| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu) |
| 4 | |
| 5 | shopt -s nullglob globstar |
| 6 | |
| 7 | typeit=0 |
| 8 | username=1 |
| 9 | editit=0 |
| 10 | |
| 11 | while [[ -n "$1" ]]; do |
| 12 | if [[ $1 == "--type" ]]; then |
| 13 | typeit=1 |
| 14 | elif [[ $1 == "--no-username" ]]; then |
| 15 | username=0 |
| 16 | elif [[ $1 == "--edit" ]]; then |
| 17 | editit=1 |
| 18 | elif [[ $1 == "--" ]]; then |
| 19 | break; |
| 20 | fi |
| 21 | shift |
| 22 | done |
| 23 | |
| 24 | |
| 25 | prefix=${PASSWORD_STORE_DIR-~/.password-store} |
| 26 | password_files=( "$prefix"/**/*.gpg ) |
| 27 | password_files=( "${password_files[@]#"$prefix"/}" ) |
| 28 | password_files=( "${password_files[@]%.gpg}" ) |
| 29 | |
| 30 | password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@") |
| 31 | |
| 32 | if [[ $editit -eq 1 ]]; then |
| 33 | # Insert the edit command for your preferred terminal here: |
| 34 | #termite -e "pass edit '$password' > /dev/null" |
| 35 | #xterm "pass edit '$password' > /dev/null" |
| 36 | #urxvt -e "pass edit '$password' > /dev/null" |
| 37 | #gnome-terminal -- pass edit "$password" > /dev/null |
| 38 | # ..etc |
| 39 | exit |
| 40 | fi |
| 41 | |
| 42 | [[ -n $password ]] || exit |
| 43 | |
| 44 | if [[ $typeit -eq 0 ]]; then |
| 45 | pass show -c "$password" | xclip |
| 46 | |
| 47 | else |
| 48 | pwfile=$(pass show "$password") |
| 49 | password=$(printf "%s" "$pwfile" | sed -n 1p) |
| 50 | username=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)") |
| 51 | printf '%s' "$password" | xclip -selection clipboard |
| 52 | print '%s' "$password" | xclip |
| 53 | if [ -z "$username" ] || [[ $username -eq 0 ]]; then |
| 54 | printf '%s' "$password" | xdotool type --clearmodifiers --file - |
| 55 | else |
| 56 | pstr=$(printf '%s\t%s' "$username" "$password") |
| 57 | xdotool type "$pstr" |
| 58 | fi |
| 59 | fi |
| 60 |
willpower232 / passmenu.sh
Last active 1 month ago
dmenu script for pass
Revision b11e4b8a810f17c1db6f7f7f45c432755922c37b