Skip to content

Instantly share code, notes, and snippets.

@silveiralexf
Last active October 6, 2019 15:32
Show Gist options
  • Save silveiralexf/0d7059ad84dec588edba3ac636514375 to your computer and use it in GitHub Desktop.
Save silveiralexf/0d7059ad84dec588edba3ac636514375 to your computer and use it in GitHub Desktop.
Use this simple script to choose a password from pass/gpg
#!/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"/keys/**/*.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
pass show -c "$password" 2>/dev/null
pass show "$password" 2>/dev/null | head -n 1 | tr -d "\n" | xclip
sleep 10 && pkill xclip
else
xdotool - <<<"type --clearmodifiers -- $(pass show "$password" | head -n 1)"
fi
#!/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"/keys/**/*.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
pass show -c "$password" 2>/dev/null
pass show "$password" 2>/dev/null | head -n 1 | tr -d "\n" | xclip
sleep 10 && pkill xclip
else
xdotool - <<<"type --clearmodifiers -- $(pass show "$password" | head -n 1)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment