Skip to content

Instantly share code, notes, and snippets.

@pandada8
Created November 18, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandada8/dae82fdc8ca0796d589d5bf93476aef0 to your computer and use it in GitHub Desktop.
Save pandada8/dae82fdc8ca0796d589d5bf93476aef0 to your computer and use it in GitHub Desktop.
passmenu with pass-otp support
#!/usr/bin/env bash
shopt -s nullglob globstar
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
if [[ "$password" == otp/* ]]; then
pass otp -c "$password" 2>/dev/null
else
pass show -c "$password" 2>/dev/null
fi
else
result=""
if [[ "$password" == otp/* ]]; then
result=$(pass otp "$password")
else
result=$(pass show "$password")
fi
echo "$result" | { read -r pass; printf %s "$pass"; } |
xdotool type --clearmodifiers --file -
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment