nixos-config/scripts/wpass.nix

51 lines
1.2 KiB
Nix
Raw Normal View History

2022-08-08 20:05:06 -03:00
{ config, pkgs, lib, ... }:
pkgs.writeShellScriptBin "wpass" ''
2022-09-26 22:12:56 -03:00
_gpg-unlock
2022-08-08 22:50:12 -03:00
set -xe
2022-08-08 20:05:06 -03:00
wtype=${pkgs.wtype}/bin/wtype
2022-08-12 23:35:42 -03:00
# dmenu=${pkgs.bmenu}/bin/bmenu
2022-08-19 20:40:39 -03:00
dmenu="wdmenu -i"
2022-08-08 20:05:06 -03:00
find_file() {
${pkgs.fd}/bin/fd --strip-cwd-prefix '\.gpg$' |
${pkgs.sd}/bin/sd ".gpg$" "" |
2022-08-16 09:44:14 -03:00
$dmenu -p "Password" $@
2022-08-08 20:05:06 -03:00
}
main() {
test -n "$PASSWORD_STORE_DIR" &&
cd "$PASSWORD_STORE_DIR" ||
cd "$HOME/.password-store"
entry=`find_file "$@"`
test -n "$entry" || exit 0
2022-08-08 22:50:12 -03:00
username=`${pkgs.pass}/bin/pass show "$entry" 2>/dev/null | perl -ne 'print $2 if /^(login|user|email): (.*)/'`
2022-08-08 20:05:06 -03:00
password=`${pkgs.pass}/bin/pass show "$entry" 2>/dev/null | head -n 1`
2022-08-16 09:44:14 -03:00
action=`printf "Autotype\nUsername -> $username\nPassword" | $dmenu -p Action`
2022-08-08 20:05:06 -03:00
case $action in
Autotype)
autotype
;;
Username*)
printf '%s' "$username" | ${pkgs.wl-clipboard}/bin/wl-copy;;
Password)
printf '%s' "$password" | ${pkgs.wl-clipboard}/bin/wl-copy;;
esac
}
autotype(){
env $wtype -s 100 "$username"
env $wtype -s 100 -k tab
env $wtype -s 100 "$password"
}
main
''