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

48 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
shopt -s nullglob globstar
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
entry=$(printf '%s\n' "${password_files[@]}" | wdmenu -p Password $@)
[ -n "$entry" ] || exit
username=$( pass show "$entry" 2>/dev/null | perl -ne 'print $1 if /^login: (.*)/' )
password=$( pass show "$entry" 2>/dev/null | head -n 1 )
action=$(echo -e "Autotype\nUsername -> $username\nPassword" | wdmenu -p Action)
autotype(){
if swaymsg -t get_inputs | grep -i colemak > /dev/null
then
swaymsg input \* xkb_layout 'us'
restoreKeyLayout='us(colemak)'
fi
if [ $(swaymsg -t get_tree | jq -r '.. | select(.focused? == true).app_id') = "org.qutebrowser.qutebrowser" ]
then
ydotool --delay 1 key esc
ydotool --delay 1 key {{@@ key.insertMode @@}}
fi
ydotool type "$username"
ydotool key tab
ydotool type "$password"
[ -n "$restoreKeyLayout" ] &&
swaymsg input \* xkb_layout "$restoreKeyLayout"
}
case $action in
Autotype)
autotype
;;
Username*)
printf '%s' "$username" | wl-copy;;
Password)
printf '%s' "$password" | wl-copy;;
esac