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