summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/dpass
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/.local/bin/dpass')
-rwxr-xr-xscripts/.local/bin/dpass112
1 files changed, 75 insertions, 37 deletions
diff --git a/scripts/.local/bin/dpass b/scripts/.local/bin/dpass
index 8524a3e..9f187ff 100755
--- a/scripts/.local/bin/dpass
+++ b/scripts/.local/bin/dpass
@@ -2,21 +2,44 @@
shopt -s nullglob globstar
-typeit=0
+output_method=("cat")
+action_descr=""
+
+if [[ $1 == "--clipboard" ]]; then
+ if [[ -n $DISPLAY ]]; then
+ output_method=("xclip" "-selection" "clipboard")
+ action_descr="copied to clipboard"
+ else
+ echo "Only X11 is supported"
+ exit 1
+ fi
+ shift
+fi
+
if [[ $1 == "--type" ]]; then
- typeit=1
- shift
+ if [[ -n $WAYLAND_DISPLAY ]]; then
+ xdotool="ydotool type --file -"
+ elif [[ -n $DISPLAY ]]; then
+ xdotool="xdotool type --clearmodifiers --file -"
+ else
+ echo "Error: No Wayland or X11 display detected" >&2
+ exit 1
+ fi
+ #output_method=("{ IFS= read -r pass; printf %s $pass; } | $xdotool")
+ output_method=("$xdotool")
+ action_descr="typed"
+ shift
fi
+#echo ${output_method[@]}
+
if [[ -n $WAYLAND_DISPLAY ]]; then
- dmenu=dmenu-wl
- xdotool="ydotool type --file -"
+ dmenu=dmenu-wl
elif [[ -n $DISPLAY ]]; then
- dmenu=cdmenu
- xdotool="xdotool type --clearmodifiers --file -"
+ dmenu=cdmenu
else
- echo "Error: No Wayland or X11 display detected" >&2
- exit 1
+ echo "Error: No Wayland or X11 display detected" >&2
+ exit 1
fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
@@ -24,36 +47,51 @@ password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
-password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -l 30 "$@")
+password_file=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -l 30 "$@")
-[[ -n $password ]] || exit
+if [[ ! " ${password_files[*]} " =~ " ${password_file} " ]]; then
+ notify-send -u critical "No entry \"$password_file\" in the password store"
+ exit 1
+fi
-if [[ $typeit -eq 0 ]]; then
- action=$(printf "login\npass\ninfo" | "$dmenu" -l 3)
- case $action in
+action=$(printf "password\nlogin\ninfo" | "$dmenu" -l 3)
+case $action in
login)
- pass show "$password" | sed -n -e '/^login:/p' | awk '{print $2}' | xclip -selection clipboard
- notify-send "Login for $password was copied to clipboard"
- ;;
- pass)
- pass show -c "$password" 2>/dev/null
- notify-send "Password for $password was copied to clipboard"
- ;;
+ login=$(pass show $password_file | sed -n -e '/^login:/p' | awk '{print $2}')
+ if [[ -z $login ]]; then
+ notify-send -u critical "No login for \"$password_file\" was found"
+ exit 1
+ fi
+ echo "$login" | ${output_method[@]}
+ if [[ -n $action_descr ]]; then
+ notify-send "Login for \"$password_file\" was $action_descr"
+ fi
+ ;;
+ password)
+ pass show "$password_file" | head -n 1 | ${output_method[@]}
+ #pass show -c "$password" 2>/dev/null
+ if [[ -n $action_descr ]]; then
+ notify-send "Password for \"$password_file\" was $action_descr"
+ fi
+ ;;
info)
- data=$(pass show $password | "$dmenu" -l 30)
- if [[ -n "$data" ]]
- then
- do_trim=$(printf 'No\nYes' | "$dmenu" -p "Trim \"$(echo $data | awk '{print $1}')\" in front?" -l 2)
- if [[ $do_trim == "Yes" ]]; then
- data=$(echo "$data" | cut -f 2- -d ' ')
- fi
- echo $data | xclip -selection clipboard
- notify-send "Info for $password was copied to clipboard"
- else
- notify-send "No info for $password was selected, clipboard not changed"
+ data=$(pass show $password_file | tail -n +2 | sed '/login\:/d')
+ if [[ -z $data ]]; then
+ notify-send -u critical "No additional info for \"$password_file\" was found"
+ exit 1
fi
- ;;
- esac
-else
- pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
-fi
+ data=$(echo $data | "$dmenu" -l 30)
+ if [[ -z "$data" ]]; then
+ notify-send "No info for $password_file was selected"
+ exit 1
+ fi
+ do_trim=$(printf 'Yes\nNo' | "$dmenu" -p "Trim \"$(echo $data | awk '{print $1}')\" in front?" -l 2)
+ if [[ $do_trim == "Yes" ]]; then
+ data=$(echo "$data" | cut -f 2- -d ' ')
+ fi
+ echo $data | ${output_method[@]}
+ if [[ -n $action_descr ]]; then
+ notify-send "Data for $password_file was $action_descr"
+ fi
+ ;;
+esac