#!/usr/bin/env bash 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 "$@") 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