-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass-menu.sh
executable file
·61 lines (52 loc) · 1.34 KB
/
pass-menu.sh
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
#!/usr/bin/env bash
escape() {
local s=${1//\&/&}
s=${s//\'/'}
s=${s//_/__}
echo "$s"
}
gen_xml() {
local PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
local PS_PATH=$(base64 -d <<< "$1")
local MENU_ID LABEL OPT
echo '<?xml version="1.0" encoding="UTF-8"?><openbox_pipe_menu>'
if [[ -d $PREFIX/$PS_PATH ]] ; then
cd -- "$PREFIX/$PS_PATH"
[[ $PS_PATH ]] && PS_PATH="$PS_PATH/"
for item in * ; do
LABEL=${item%.gpg}
OPT=$(echo -n "${PS_PATH}${LABEL}" | base64 -w 0)
LABEL=$(escape "$LABEL")
echo "<menu id='$OPT' label='$LABEL' execute='$0 $OPT' />"
done
else
printf "<item label='%s'><action name='Execute'><command>$0 %s $1</command></action></item>\n" \
'Type _password' type \
'Type _login and password' type_ex \
'Copy password to _clipboard' clip
fi
echo '</openbox_pipe_menu>'
}
type_pass() {
if type xvkbd >/dev/null ; then
echo -n "$1" | xvkbd -file - 2>/dev/null
while [[ $2 ]] ; do
shift
xvkbd -text '\t' 2>/dev/null
echo -n "$1" | xvkbd -file - 2>/dev/null
done
else
IFS=' '
xdotool type --clearmodifiers "$*"
fi
}
if [[ $2 ]] ; then
PS_PATH=$(base64 -d <<< "$2")
case "$1" in
type) type_pass "$(pass show -- "$PS_PATH")" ;;
type_ex) type_pass "${PS_PATH##*/}" "$(pass show -- "$PS_PATH")" ;;
clip) pass show -c -- "$PS_PATH" ;;
esac
else
gen_xml "$1"
fi