altpassmenu (835B) - raw


      1 #!/usr/bin/env bash
      2 
      3 shopt -s nullglob globstar
      4 
      5 typeit=0
      6 if [ "$1" = "--type" ]; then
      7 	typeit=1
      8 	shift
      9 elif [ "$1" = "--type-all" ]; then
     10 	typeit=2
     11 	shift
     12 fi
     13 
     14 prefix="${PASSWORD_STORE_DIR-~/.password-store}"
     15 password_files=( "$prefix"/**/*.gpg )
     16 password_files=( "${password_files[@]#"$prefix"/}" )
     17 password_files=( "${password_files[@]%.gpg}" )
     18 
     19 password=$(printf '%s\n' "${password_files[@]}" | dmenu -i "$@")
     20 
     21 [ -n "$password" ] || exit
     22 
     23 if [ "$typeit" = "0" ]; then
     24 	pass show -c "$password" 2>/dev/null
     25 elif [ "$typeit" = "1" ]; then
     26 	pass show "$password" | head -n 1 - | xdotool type --clearmodifiers --file -
     27 else
     28 	pass="$(pass show "$password")"
     29 	username="$(echo "$pass" | sed -n "s/^username:[ 	]*//p")"
     30 	pass="$(echo "$pass" | head -n 1 -)"
     31 	printf "%s	%s" "$username" "$pass" | xdotool type --clearmodifiers --file -
     32 fi