Skip to content

Instantly share code, notes, and snippets.

@willpower232 willpower232/passmenu.sh
Last active Jun 10, 2019

Embed
What would you like to do?
dmenu script for pass
#!/usr/bin/env bash
# 1 - source copy from https://geluk.io/p/passmenu.sh (https://github.com/Baggykiin/pass-winmenu)
# 2 - make dmenu case insensitive
# 3 - correct include_username variable
shopt -s nullglob globstar
typeit=0
include_username=1
editit=0
while [[ -n "$1" ]]; do
if [[ $1 == "--type" ]]; then
typeit=1
elif [[ $1 == "--no-username" ]]; then
include_username=0
elif [[ $1 == "--edit" ]]; then
editit=1
elif [[ $1 == "--" ]]; then
break;
fi
shift
done
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 -i "$@")
if [[ $editit -eq 1 ]]; then
# Insert the edit command for your preferred terminal here:
#termite -e "pass edit '$password' > /dev/null"
#xterm "pass edit '$password' > /dev/null"
#urxvt -e "pass edit '$password' > /dev/null"
#gnome-terminal -- pass edit "$password" > /dev/null
# ..etc
exit
fi
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
pass show -c "$password" | xclip
else
pwfile=$(pass show "$password")
password=$(printf "%s" "$pwfile" | sed -n 1p)
username=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)")
printf '%s' "$password" | xclip -selection clipboard
print '%s' "$password" | xclip
if [ -z "$username" ] || [[ $include_username -eq 0 ]]; then
printf '%s' "$password" | xdotool type --clearmodifiers --file -
else
pstr=$(printf '%s\t%s' "$username" "$password")
xdotool type "$pstr"
fi
fi
@willpower232

This comment has been minimized.

Copy link
Owner Author

commented Jun 3, 2019

Best to leave in /usr/local/bin/passmenu so it can be run easily by keyboard shortcuts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.