blob: a3f4e72ae411029d3e9ef7c66369377bc84e99ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/usr/bin/env bash
shopt -s nullglob globstar
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
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"
elif [[ -n $DISPLAY ]]; then
dmenu="$HOME/.local/bin/cdmenu"
else
echo "Error: No Wayland or X11 display detected" >&2
exit 1
fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
password_file=$(printf '%s\n' "${password_files[@]}" | "$dmenu" -l 30 "$@")
if [[ -z "$password_file" ]]; then
exit 1
fi
if [[ ! ${password_files[*]} =~ "${password_file}" ]]; then
notify-send -u critical "No entry \"$password_file\" in the password store"
exit 1
fi
action=$(printf "password\nlogin\nOTP\ninfo" | "$dmenu" -l 4)
case $action in
login)
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
printf "%s" "$login" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "Login for \"$password_file\" was $action_descr"
fi
;;
password)
password=$(pass show "$password_file" | head -n 1)
if [[ -z $password ]]; then
notify-send -u critical "No password for \"$password_file\" was found"
exit 1
fi
printf "%s" "$password" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "Password for \"$password_file\" was $action_descr"
fi
;;
OTP)
otp=$(pass otp "$password_file")
if [[ -z $otp ]]; then
notify-send -u critical "No OTP for \"$password_file\" was found"
exit 1
fi
printf "%s" "$otp" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "OTP for \"$password_file\" was $action_descr"
fi
;;
info)
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
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
printf "%s" "$data" | "${output_method[@]}"
if [[ -n $action_descr ]]; then
notify-send "Data for $password_file was $action_descr"
fi
;;
esac
|