| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | # 3 - correct include_username variable | |
| 6 | 6 | # 4 - only pick out usernames if they are the start of the sentence, i.e. ignore non-primary usernames listed in the file (mostly for bitbucket) | |
| 7 | 7 | # 5 - dependency test and install | |
| 8 | + | # 6 - error output on bad argument | |
| 8 | 9 | ||
| 9 | 10 | shopt -s nullglob globstar | |
| 10 | 11 | ||
| @@ -24,6 +25,9 @@ while [[ -n "$1" ]]; do | |||
| 24 | 25 | deps=1 | |
| 25 | 26 | elif [[ $1 == "--" ]]; then | |
| 26 | 27 | break; | |
| 28 | + | else | |
| 29 | + | echo "Error: unhandled argument $1." >&2 | |
| 30 | + | exit 1 | |
| 27 | 31 | fi | |
| 28 | 32 | shift | |
| 29 | 33 | done | |
willpower232 / passmenu.sh
Last active 1 month ago
dmenu script for pass
Will Power revised this gist 4 years ago · 6309b94
1 file changed, 4 insertions
Will Power revised this gist 6 years ago · 1020eda
1 file changed, 23 insertions
| @@ -4,12 +4,14 @@ | |||
| 4 | 4 | # 2 - make dmenu case insensitive | |
| 5 | 5 | # 3 - correct include_username variable | |
| 6 | 6 | # 4 - only pick out usernames if they are the start of the sentence, i.e. ignore non-primary usernames listed in the file (mostly for bitbucket) | |
| 7 | + | # 5 - dependency test and install | |
| 7 | 8 | ||
| 8 | 9 | shopt -s nullglob globstar | |
| 9 | 10 | ||
| 10 | 11 | typeit=0 | |
| 11 | 12 | include_username=1 | |
| 12 | 13 | editit=0 | |
| 14 | + | deps=0 | |
| 13 | 15 | ||
| 14 | 16 | while [[ -n "$1" ]]; do | |
| 15 | 17 | if [[ $1 == "--type" ]]; then | |
| @@ -18,12 +20,23 @@ while [[ -n "$1" ]]; do | |||
| 18 | 20 | include_username=0 | |
| 19 | 21 | elif [[ $1 == "--edit" ]]; then | |
| 20 | 22 | editit=1 | |
| 23 | + | elif [[ $1 == "--install-dependencies" ]]; then | |
| 24 | + | deps=1 | |
| 21 | 25 | elif [[ $1 == "--" ]]; then | |
| 22 | 26 | break; | |
| 23 | 27 | fi | |
| 24 | 28 | shift | |
| 25 | 29 | done | |
| 26 | 30 | ||
| 31 | + | if [[ $deps -eq 1 ]]; then | |
| 32 | + | sudo apt install dmenu xclip xdotool -y | |
| 33 | + | exit | |
| 34 | + | fi | |
| 35 | + | ||
| 36 | + | if ! [ -x "$(command -v dmenu)" ]; then | |
| 37 | + | echo 'Error: dmenu is not installed.' >&2 | |
| 38 | + | exit 1 | |
| 39 | + | fi | |
| 27 | 40 | ||
| 28 | 41 | prefix=${PASSWORD_STORE_DIR-~/.password-store} | |
| 29 | 42 | password_files=( "$prefix"/**/*.gpg ) | |
| @@ -44,10 +57,20 @@ fi | |||
| 44 | 57 | ||
| 45 | 58 | [[ -n $password ]] || exit | |
| 46 | 59 | ||
| 60 | + | if ! [ -x "$(command -v xclip)" ]; then | |
| 61 | + | echo 'Error: xclip is not installed.' >&2 | |
| 62 | + | exit 1 | |
| 63 | + | fi | |
| 64 | + | ||
| 47 | 65 | if [[ $typeit -eq 0 ]]; then | |
| 48 | 66 | pass show -c "$password" | xclip | |
| 49 | 67 | ||
| 50 | 68 | else | |
| 69 | + | if ! [ -x "$(command -v xdotool)" ]; then | |
| 70 | + | echo 'Error: xdotool is not installed.' >&2 | |
| 71 | + | exit 1 | |
| 72 | + | fi | |
| 73 | + | ||
| 51 | 74 | pwfile=$(pass show "$password") | |
| 52 | 75 | password=$(printf "%s" "$pwfile" | sed -n 1p) | |
| 53 | 76 | username=$(printf "%s" "$pwfile" | grep -Po "^[Uu]ser(name)?: \K(.*)") | |
William Hall revised this gist 7 years ago · 5811443
1 file changed, 2 insertions, 1 deletion
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | # 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu) | |
| 4 | 4 | # 2 - make dmenu case insensitive | |
| 5 | 5 | # 3 - correct include_username variable | |
| 6 | + | # 4 - only pick out usernames if they are the start of the sentence, i.e. ignore non-primary usernames listed in the file (mostly for bitbucket) | |
| 6 | 7 | ||
| 7 | 8 | shopt -s nullglob globstar | |
| 8 | 9 | ||
| @@ -49,7 +50,7 @@ if [[ $typeit -eq 0 ]]; then | |||
| 49 | 50 | else | |
| 50 | 51 | pwfile=$(pass show "$password") | |
| 51 | 52 | password=$(printf "%s" "$pwfile" | sed -n 1p) | |
| 52 | - | username=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)") | |
| 53 | + | username=$(printf "%s" "$pwfile" | grep -Po "^[Uu]ser(name)?: \K(.*)") | |
| 53 | 54 | printf '%s' "$password" | xclip -selection clipboard | |
| 54 | 55 | print '%s' "$password" | xclip | |
| 55 | 56 | if [ -z "$username" ] || [[ $include_username -eq 0 ]]; then | |
Will Power revised this gist 7 years ago · 2cb34a4
1 file changed, 4 insertions, 3 deletions
| @@ -2,18 +2,19 @@ | |||
| 2 | 2 | ||
| 3 | 3 | # 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu) | |
| 4 | 4 | # 2 - make dmenu case insensitive | |
| 5 | + | # 3 - correct include_username variable | |
| 5 | 6 | ||
| 6 | 7 | shopt -s nullglob globstar | |
| 7 | 8 | ||
| 8 | 9 | typeit=0 | |
| 9 | - | username=1 | |
| 10 | + | include_username=1 | |
| 10 | 11 | editit=0 | |
| 11 | 12 | ||
| 12 | 13 | while [[ -n "$1" ]]; do | |
| 13 | 14 | if [[ $1 == "--type" ]]; then | |
| 14 | 15 | typeit=1 | |
| 15 | 16 | elif [[ $1 == "--no-username" ]]; then | |
| 16 | - | username=0 | |
| 17 | + | include_username=0 | |
| 17 | 18 | elif [[ $1 == "--edit" ]]; then | |
| 18 | 19 | editit=1 | |
| 19 | 20 | elif [[ $1 == "--" ]]; then | |
| @@ -51,7 +52,7 @@ else | |||
| 51 | 52 | username=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)") | |
| 52 | 53 | printf '%s' "$password" | xclip -selection clipboard | |
| 53 | 54 | print '%s' "$password" | xclip | |
| 54 | - | if [ -z "$username" ] || [[ $username -eq 0 ]]; then | |
| 55 | + | if [ -z "$username" ] || [[ $include_username -eq 0 ]]; then | |
| 55 | 56 | printf '%s' "$password" | xdotool type --clearmodifiers --file - | |
| 56 | 57 | else | |
| 57 | 58 | pstr=$(printf '%s\t%s' "$username" "$password") | |
Will Power revised this gist 7 years ago · e075b99
1 file changed, 2 insertions, 1 deletion
| @@ -1,6 +1,7 @@ | |||
| 1 | 1 | #!/usr/bin/env bash | |
| 2 | 2 | ||
| 3 | 3 | # 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu) | |
| 4 | + | # 2 - make dmenu case insensitive | |
| 4 | 5 | ||
| 5 | 6 | shopt -s nullglob globstar | |
| 6 | 7 | ||
| @@ -27,7 +28,7 @@ password_files=( "$prefix"/**/*.gpg ) | |||
| 27 | 28 | password_files=( "${password_files[@]#"$prefix"/}" ) | |
| 28 | 29 | password_files=( "${password_files[@]%.gpg}" ) | |
| 29 | 30 | ||
| 30 | - | password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@") | |
| 31 | + | password=$(printf '%s\n' "${password_files[@]}" | dmenu -i "$@") | |
| 31 | 32 | ||
| 32 | 33 | if [[ $editit -eq 1 ]]; then | |
| 33 | 34 | # Insert the edit command for your preferred terminal here: | |
Will Power revised this gist 7 years ago · b11e4b8
1 file changed, 59 insertions
| @@ -0,0 +1,59 @@ | |||
| 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 | |