bins

handy scripts
git clone git://popovic.xyz/bins.git
Log | Files | Refs | LICENSE

passmenu-otp (671B)


      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 fi
     10 
     11 prefix=${PASSWORD_STORE_DIR-~/.password-store}
     12 password_files=( "$prefix"/**/*.gpg )
     13 password_files=( "${password_files[@]#"$prefix"/}" )
     14 password_files=( "${password_files[@]%.gpg}" )
     15 
     16 password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
     17 
     18 [[ -n $password ]] || exit
     19 
     20 pass_cmd=show
     21 if pass show "$password" | grep -q '^otpauth://'; then
     22     pass_cmd=otp
     23 fi
     24 
     25 if [[ $typeit -eq 0 ]]; then
     26 	pass $pass_cmd -c "$password" 2>/dev/null
     27 else
     28 	pass $pass_cmd "$password" | { IFS= read -r pass; printf %s "$pass"; } |
     29 		xdotool type --clearmodifiers --file -
     30 fi