geluk / pass-winmenu

An easy-to-use password manager for Windows, compatible with pass.
MIT License
385 stars 25 forks source link

added EDIT option to your script, corrected variable overwrite and logic on --no-username #43

Closed thewaywest closed 5 years ago

thewaywest commented 5 years ago
#!/usr/bin/env bash

shopt -s nullglob globstar

typeit=0
username=1
editit=0

while [[ -n "$1" ]]; do
        if [[ $1 == "--type" ]]; then
                typeit=1
        elif [[ $1 == "--no-username" ]]; then
                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
        gnome-terminal -- pass edit "$password" > /dev/null
        exit
fi

[[ -n $password ]] || exit

if [[ $typeit -eq 0 ]]; then
        pass show -c "$password" | xclip
else
        pwfile=$(pass show "$password")
        pwd=$(printf "%s" "$pwfile" | sed -n 1p)
        uid=$(printf "%s" "$pwfile" | grep -Po "[Uu]ser(name)?: \K(.*)")
        printf '%s' "$pwd" | xclip -selection clipboard
        print '%s' "$pwd" | xclip
        if [ -z "$uid" ] || [[ $username -eq 0 ]]; then
                printf '%s' "$pwd" | xdotool type --clearmodifiers --file -
        else
                pstr=$(printf '%s\t%s' "$uid" "$pwd")
                xdotool type "$pstr"
        fi
fi
geluk commented 5 years ago

Thanks for your modifications! I have integrated them into the script.