This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/dotfiles/scripts/wpass

65 lines
1.4 KiB
Text
Raw Normal View History

2020-04-14 19:51:53 +02:00
#!/bin/bash
2020-10-27 05:41:06 +01:00
# passmenu, for wayland
# depends: ydotool, wtype, pass
2020-04-14 19:51:53 +02:00
shopt -s nullglob globstar
2020-10-20 18:54:12 +02:00
INSERTKEY="{{@@ key.insertMode @@}}"
#{%@@ if False @@%}#
INSERTKEY="i"
#{%@@ endif @@%}#
2020-10-27 05:41:06 +01:00
for m in "dmenu" "bmenu" "wofi" "wdmenu"; do
command -v "$m" > /dev/null && dmenu="$m"
done
test -z "$dmenu" && exit 1
test "$dmenu" = "wofi" &&
dmenu="wofi -d"
main() {
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
2020-11-16 14:17:10 +01:00
entry=`printf '%s\n' "${password_files[@]}" | "$dmenu" -p "Password" $@`
2020-10-27 05:41:06 +01:00
[ -n "$entry" ] || exit
2020-04-14 19:51:53 +02:00
2020-10-27 05:41:06 +01:00
username=`pass show "$entry" 2>/dev/null | perl -ne 'print $1 if /^login: (.*)/'`
password=`pass show "$entry" 2>/dev/null | head -n 1`
2020-04-14 19:51:53 +02:00
2020-10-27 05:41:06 +01:00
action=`printf "Autotype\nUsername -> $username\nPassword" | "$dmenu" -p Action`
2020-04-14 19:51:53 +02:00
2020-10-27 05:41:06 +01:00
case $action in
Autotype)
autotype
;;
Username*)
printf '%s' "$username" | wl-copy;;
Password)
printf '%s' "$password" | wl-copy;;
esac
2020-04-14 19:51:53 +02:00
2020-10-27 05:41:06 +01:00
}
2020-05-22 02:34:08 +02:00
2020-10-03 01:24:04 +02:00
autotype(){
2020-10-27 05:41:06 +01:00
curWindow=`swaymsg -t get_tree | jq -r '.. | select(.focused? == true).app_id'`
if test "$curWindow" = "org.qutebrowser.qutebrowser"
2020-10-03 01:24:04 +02:00
then
2020-10-27 05:41:06 +01:00
ydotool key esc
wtype "$INSERTKEY"
2020-10-03 01:24:04 +02:00
fi
2020-10-27 05:41:06 +01:00
wtype "$username"
2020-10-03 01:24:04 +02:00
ydotool key tab
2020-10-27 05:41:06 +01:00
wtype "$password"
2020-10-03 01:24:04 +02:00
}
2020-05-22 02:34:08 +02:00
2020-10-27 05:41:06 +01:00
main