-
Notifications
You must be signed in to change notification settings - Fork 3
/
zsh-fzf-pass.zsh
71 lines (63 loc) · 1.82 KB
/
zsh-fzf-pass.zsh
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
function fuzzy-pass() {
PASS_STR_VALID_DIR="${PASSWORD_STORE_DIR:-${HOME}/.password-store}"
PASSFILE=$(find -L $PASS_STR_VALID_DIR | sed "s|$PASS_STR_VALID_DIR||" | grep '.gpg' | sed 's/.gpg$//g' | fzf)
[ -z "$PASSFILE" ] && return 0
PASSDATA="$(pass ${PASSFILE})"
PASS="$(echo "${PASSDATA}" | head -n 1)"
LOGIN="$(echo "${PASSDATA}" | egrep -i "login:|username:|user:" | head -n 1 | cut -d' ' -f2-)"
if [ -z "${LOGIN}" ] && [ -n "${PASS}" ]; then
LOGIN=${PASSFILE##*/}
fi
EMAIL="$(echo "${PASSDATA}" | egrep -i "email:" | head -n 1 | cut -d' ' -f2-)"
URL="$(echo "${PASSDATA}" | egrep -i "url:" | cut -d' ' -f2-)"
if [ -z "${URL}" ]; then
URL="$(basename $(dirname "${PASSFILE}"))"
URL="$(echo "${URL}" | grep "\.")"
fi
ACTIONS="Edit\nFile"
if [ -n "${URL}" ]; then
ACTIONS="Url\n${ACTIONS}"
fi
if [ -n "${EMAIL}" ]; then
ACTIONS="Email\n${ACTIONS}"
fi
if [ -n "${PASS}" ]; then
ACTIONS="Password\n${ACTIONS}"
fi
if [ -n "${LOGIN}" ]; then
ACTIONS="Login\n${ACTIONS}"
fi
CONTINUE=true
while ${CONTINUE}; do
ACTION=$(echo "${ACTIONS}" \
| fzf --height 10 --border --header "Pass file ${PASSFILE}")
case ${ACTION} in
Login)
echo "${LOGIN}" | clipcopy
echo "Copied Login '${LOGIN}' to clipboard"
;;
Password)
pass --clip "${PASSFILE}" 1>/dev/null
echo "Copied Password to clipboard (clear in 45 seconds)"
;;
Url)
echo "${URL}" | clipcopy
echo "Copied Url '${URL}' to clipboard"
;;
File)
pass "${PASSFILE}"
;;
Email)
echo "${EMAIL}" | clipcopy
echo "Copied Email '${EMAIL}' to clipboard"
;;
Edit)
pass edit "${PASSFILE}"
;;
*)
CONTINUE=false
;;
esac
done
}
alias fzp=fuzzy-pass