#!/usr/bin/env bash shopt -s nullglob globstar typeit=1 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}" ) # Show urls open in firefox on top open_urls="$($HOME/.local/bin/exfirefoxtabs.py | awk -F/ '{print $3}' | sort | uniq | sed 's/$//g' | sed ':a;N;$!ba;s/\n/|/g')" pfiles="$(printf "%s\n" ${password_files[@]})" list="$(echo "$pfiles" | grep -E "$open_urls")\n$(echo "$pfiles" | grep -Ev "$open_urls")" entry=$(echo -e "$list" | dmenu -l 7 -p "Pass" -i "$@") [[ -n $entry ]] || exit action=$(echo -e "Login\nUsername\nPassword\nTOTP" | dmenu -p "Entry" -i ) case "$action" in Login) username=$(echo "$entry" | rev | cut -d"/" -f 1 | rev) password=$(pass show "$entry") printf %s "$username" | xargs | xdotool type --clearmodifiers --file - xdotool key Tab printf %s "$password" | { IFS= read -r pass; printf %s "$pass"; } | xargs | xdotool type --clearmodifiers --file - xdotool key Return ;; Username) username=$(echo "$entry" | rev | cut -d"/" -f 1 | rev) printf %s "$username" | xclip -selection clipboard printf %s "$username" | xargs | xdotool type --clearmodifiers --file - notify-send -a " Password Manager" "Username copied to clipboard";; Password) password=$(pass show "$entry") printf %s "$password" | xclip -selection clipboard printf %s "$password" | { IFS= read -r pass; printf %s "$pass"; } | xargs | xdotool type --clearmodifiers --file - notify-send -a " Password Manager" "Password copied to clipboard";; TOTP) otp=$(pass otp "$entry") printf %s "$otp" | xclip -selection clipboard printf %s "$otp" | { IFS= read -r pass; printf %s "$pass"; } | xdotool type --clearmodifiers --file - notify-send -a " Password Manager" "TOTP copied to clipboard" xdotool key Return ;; esac