From f2ed316ed00b4cd19c63f5c8af1130810eac18f0 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 31 May 2020 12:17:41 +0200 Subject: Add support for pass-otp in passmenu --- contrib/dmenu/passmenu | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'contrib/dmenu/passmenu') diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu index 83268bc..0bb9d2b 100755 --- a/contrib/dmenu/passmenu +++ b/contrib/dmenu/passmenu @@ -3,23 +3,49 @@ shopt -s nullglob globstar typeit=0 -if [[ $1 == "--type" ]]; then - typeit=1 - shift -fi +otp=0 +infer_otp=0 +otp_pattern="" +while [[ $# -gt 0 ]]; do + argument="$1" + shift + case $argument in + --type) typeit=1 ;; + --otp) otp=1 ;; + --infer-otp) infer_otp=1 ;; + --otp-pattern) otp_pattern="$1"; shift ;; + esac +done prefix=${PASSWORD_STORE_DIR-~/.password-store} password_files=( "$prefix"/**/*.gpg ) password_files=( "${password_files[@]#"$prefix"/}" ) password_files=( "${password_files[@]%.gpg}" ) +if [[ $otp -eq 1 ]]; then + filtered_files=() + for file in "${password_files[@]}"; do + [[ "$file" =~ $otp_pattern ]] && filtered_files+=("$file") + done + password_files=(${filtered_files[@]}) +fi + password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@") [[ -n $password ]] || exit +if [[ $infer_otp -eq 1 ]]; then + [[ "$password" =~ $otp_pattern ]] && otp=1 +fi + +otp_arg='' +if [[ $otp -eq 1 ]]; then + otp_arg='otp' +fi + if [[ $typeit -eq 0 ]]; then - pass show -c "$password" 2>/dev/null + pass $otp_arg show -c "$password" 2>/dev/null else - pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | + pass $otp_arg show "$password" | { IFS= read -r pass; printf %s "$pass"; } | xdotool type --clearmodifiers --file - fi -- cgit v1.2.3