diff --git a/gopass/.local/bin/rofi-gopass b/gopass/.local/bin/rofi-gopass index e39dc1d..bc5865f 100755 --- a/gopass/.local/bin/rofi-gopass +++ b/gopass/.local/bin/rofi-gopass @@ -6,7 +6,7 @@ # typing tool used, choice of: # xdotool | -BACKEND=xdotool +# BACKEND=xdotool # the complete typing chain autoentry uses # possible fields: @@ -18,15 +18,20 @@ BACKEND=xdotool # By default it enters the username, tabs down, and enters the password # It does not press return at the end for safety, though you can add # :return to make it do so. -AUTOENTRY_CHAIN="username :tab password" +# AUTOENTRY_CHAIN="username :tab password" # wait time before entering each input # in milliseconds -AUTOENTRY_DELAY=20 +# AUTOENTRY_DELAY=20 # default key bindings # Automatically enter username and password -KEY_AUTOENTRY="Return" +# KEY_AUTOENTRY="Return" + +# The field name containing your gopass username +# can take multiple names, separated by space +# Will go through names in descending precedence +# GOPASS_USERNAME_FIELD="username user login" # rofi wrapper. Add custom settings here. _rofi() { @@ -53,31 +58,48 @@ _gp_show_password() { gopass show -f --password "$1" } -GOPASS_USERNAME_ATTEMPTS="username user login" - -# return username for argument passed -_gp_show_username() { - for key in $GOPASS_USERNAME_ATTEMPTS; do - - done - gopass show -f "$1" username || gopass -f show "$1" user || gopass -f show "$1" login -} - # send password to clipboard _gp_clip_password() { gopass show -c "$1" } +# attempt to return the field specified +# attempts all (space separated) fields until the +# first one successfully returned +_gp_get_field() { + local gp_entry="$1" + local gp_field="$2" + local gp_opt="$3" + + for key in $gp_field; do + # return on first successfully returned key + if [ -n "$gp_opt" ]; then + gopass show "$gp_opt" -f "$gp_entry" "$key" && break + else + gopass show -f "$gp_entry" "$key" && break + fi + done +} + +# return username for argument passed +_gp_show_username() { + _gp_get_field "$1" "${GOPASS_USERNAME_FIELD:-"username user login"}" +} + +_gp_clip_username() { + _gp_get_field "$1" "${GOPASS_USERNAME_FIELD:-"username user login"}" "-c" +} + # invoke the dotool to type inputs _type() { local tool local toolmode local key - tool="${BACKEND}" + tool="${BACKEND:-xdotool}" toolmode="$1" key="$2" - "$tool" "$toolmode" --delay "$AUTOENTRY_DELAY" "$key" + "$tool" "$toolmode" --delay "${AUTOENTRY_DELAY:-20}" "$key" } # automatically enter entry chain, set via AUTOENTRY_CHAIN @@ -86,7 +108,7 @@ autoentry() { local selected local autoentry_chain selected="${1}" - autoentry_chain="${AUTOENTRY_CHAIN}" + autoentry_chain="${AUTOENTRY_CHAIN:-username :tab password}" for part in $autoentry_chain; do case "$part" in @@ -103,7 +125,7 @@ autoentry() { main() { # entry="$(list_passwords | _rofi -kb-accept-entry "" -kb-custom-1 "${key_autotype}" -kb-custom-2 "${key_usertype}" -kb-custom-3 "${key_passtype}" -kb-custom-4 "${key_actions}" -mesg "${key_autotype}: Autotype | ${key_usertype}: Type User | ${key_passtype}: Type Pass | ${key_actions}: More Actions")" - entry="$(_gp_list_passwords | _rofi -kb-accept-entry "" -kb-custom-1 "${KEY_AUTOENTRY}")" + entry="$(_gp_list_passwords | _rofi -kb-accept-entry "" -kb-custom-1 "${KEY_AUTOENTRY:-Return}")" exit_value=$? exit_check "${exit_value}"