nixos-config/scripts/wpass

63 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2022-10-18 20:04:46 -03:00
_gpg-unlock
set -xe
find_file() {
fd --strip-cwd-prefix '\.gpg$' |
sd ".gpg$" "" |
2022-10-21 20:21:51 -03:00
wdmenu -p "Password" $@
2022-10-18 20:04:46 -03:00
}
2023-08-07 19:58:05 -03:00
print_actions_for_entry() {
echo "Autotype"
if test -n "$username"; then
echo "Username -> $username"
fi
echo "Password"
if test -n "$otp"; then
echo "OTP"
fi
}
2022-10-18 20:04:46 -03:00
main() {
test -n "$PASSWORD_STORE_DIR" &&
cd "$PASSWORD_STORE_DIR" ||
cd "$HOME/.password-store"
2022-10-18 20:04:46 -03:00
entry=`find_file "$@"`
test -n "$entry" || exit 0
username=`pass show "$entry" 2>/dev/null | perl -ne 'print $2 if /^(login|user|email): (.*)/'`
password=`pass show "$entry" 2>/dev/null | head -n 1`
2023-08-08 16:45:02 -03:00
otp=`pass otp "$entry" 2>/dev/null` || true
2022-10-18 20:04:46 -03:00
2023-08-07 19:58:05 -03:00
action="$(print_actions_for_entry | wdmenu -p Action)"
2022-10-18 20:04:46 -03:00
case $action in
Autotype)
autotype
;;
Username*)
printf '%s' "$username" | wl-copy;;
Password)
printf '%s' "$password" | wl-copy;;
2023-08-07 19:58:05 -03:00
OTP)
pass otp "$entry" | wl-copy;;
2022-10-18 20:04:46 -03:00
esac
}
autotype(){
if pgrep qutebrowser >/dev/null; then
qutebrowser ":mode-enter insert"
fi
2022-10-18 20:04:46 -03:00
env wtype -s 100 "$username"
env wtype -s 100 -k tab
env wtype -s 100 "$password"
}
main