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