stockholm/tv/5pkgs/simple/fzmenu/bin/passmenu

46 lines
1.0 KiB
Plaintext
Raw Normal View History

2018-11-28 08:20:25 +00:00
#! /bin/sh
set -efu
#PATH=
case ${FZMENU_PHASE-0} in
0)
export FZMENU_PHASE=1
2023-01-11 16:21:51 +00:00
exec setsid -f terminal dash "$0"
2018-11-28 08:20:25 +00:00
;;
1)
if result=$(
2023-03-22 17:04:21 +00:00
PASSWORD_STORE_DIR=${PASSWORD_STORE_DIR-$HOME/.password-store}
2018-11-28 08:20:25 +00:00
FZF_DEFAULT_OPTS=${FZMENU_FZF_DEFAULT_OPTS-}
if test -n "$FZF_DEFAULT_OPTS"; then
export FZF_DEFAULT_OPTS
fi
2023-03-22 17:04:21 +00:00
find -L "$PASSWORD_STORE_DIR" -type f -name '*.gpg' |
awk -F / -v PASSWORD_STORE_DIR="$PASSWORD_STORE_DIR" '
{ n = length(PASSWORD_STORE_DIR "/") }
$NF == "otp.gpg" { next }
/.*\.gpg$/ {
print substr($0, 1 + n, length($0)-length(".gpg")-n)
}
2018-11-28 08:20:25 +00:00
' |
exec fzf \
--history=/dev/null \
--no-sort \
--prompt='pass: ' \
)
then
export FZMENU_PHASE=2
export FZMENU_RESULT="$result"
setsid -f "$0"
fi
;;
2)
pass=$(pass show "$FZMENU_RESULT")
printf %s "$pass" |
xdotool type -f -
;;
*)
echo "$0: error: bad phase: $FZMENU_PHASE" >&2
exit -1
esac