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-old/scripts/.local/bin/wpass
2020-04-21 19:36:45 -03:00

45 lines
1 KiB
Bash
Executable file

#!/bin/bash
CACHE=~/.cache/wpass-hist
set -e
shopt -s nullglob globstar
typeit=0
if [ "$1" = "--type" ]; then
typeit=1
shift
fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
[ -f $CACHE ] || touch $CACHE
for line in $(cat $CACHE); do
password_files+=( $line )
done
entry=$(printf '%s\n' "${password_files[@]}" |
sort | uniq -c | sort -r | sed 's/ *[0-9]* //'|
bmenu "$@")
[ -n "$entry" ] && echo "$entry" >> $CACHE || exit
username=$( pass show "$entry" 2>/dev/null | perl -ne 'print $1 if /^login: (.*)/' )
password=$( pass show "$entry" 2>/dev/null | head -n 1 )
# | grep 'username'&&
case $(echo -e "Autotype\nUsername -> $username\nPassword" | bmenu) in
Autotype)
ydotool type "$username"
ydotool key tab
ydotool type "$password"
;;
Username*)
printf '%s' "$username" | wl-copy;;
Password)
printf '%s' "$password" | wl-copy;;
esac