helm/config/rofi/bin/passmenu
Henrik Lissner c897191831
Major design of glimpse theme
- Add rofi scripts (replace rofi-pass with homebrewed passmenu)
- Replace wallpapers
- New soft blue + blur A E S T H E T I C
- Change from Arc Dark to Nordic
- Apply GTK theme to pinentry prompt
- New rofi theme
- Switch from lightdm gtk greeter to mini greeter
- Refactor zsh aliases
2019-12-04 00:03:31 -05:00

55 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
# Prompts for a pass entry, then for a specific field. Similar to passmenu, but
# uses rofi, and can resume from a previous session.
#
# Example: passmenu [RESUME]
ROFI_CMD='rofi -dmenu -theme theme/passmenu.rasi'
set -e
shopt -s nullglob globstar
for prog in xclip notify-send pass; do
if ! command -v "$prog" >/dev/null; then
>&2 echo "$prog not installed, aborting"
exit 1
fi
done
if [[ $1 == -r ]]; then
resume=1; shift
fi
url=$@
LAST_ENTRY_FILE=/tmp/_upm
if [[ -n $resume && -f $LAST_ENTRY_FILE ]]; then
entry="$(<$LAST_ENTRY_FILE)"
else
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[@]}" | $ROFI_CMD -p "pass > " -filter "$url")
fi
if [[ -z $entry ]]; then
notify-send --urgency=critical "Failed to select $entry"
exit 1
fi
echo "$entry" >/tmp/_upm
secrets="$(pass show "$entry")"
if [[ -n $secrets ]]; then
fields=$(awk -F': ' 'NR>1 && !/^otpauth:/ {print $1}' <<<"$secrets")
field=$(printf "password\n%s\notp\n" "${fields[@]}" | $ROFI_CMD -p "pass ($entry) > ")
case $field in
password) pass -c "$entry" ;;
otp) printf "%s" "$(pass otp -c "$entry")" ;;
*) printf "%s" "$(awk -v "key=$field:" '$1 == key {print $2}' <<<"$secrets")" | xclip -selection clipboard -in ;;
esac
notify-send --urgency=low "<b>$entry -> $field</b>" "Copied to clipboard for 45s"
else
notify-send --urgency=critical "Failed to retrieve $entry"
exit 2
fi