#!/usr/bin/env bash # # Code originally inspired by https://github.com/carnager/rofi-pass/ # DEFAULT OPTIONS # typing tool used, choice of: # xdotool | BACKEND=xdotool # the complete typing chain autoentry uses # possible fields: # :tab | :space | :enter | username | password # # Note that spaces have to be passed explicitly with :space, # putting a literal ' ' in the chain will not work # # 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" # wait time before entering each input # in milliseconds AUTOENTRY_DELAY=20 # default key bindings # Automatically enter username and password KEY_AUTOENTRY="Return" # rofi wrapper. Add custom settings here. _rofi() { # TODO add check for dmenu exist rofi critical "rofi-pass" || exit 0 rofi -dmenu -no-auto-select -i "$@" -theme /themes/dmenu } # exit on escape pressed # rofi returns exit code 1 on esc exit_check() { [ "$1" -eq 1 ] && exit } # simply return a list of all passwords in gopass store # TODO choose password store # TODO only show website names (+ folder names), and account names for multiple accounts on one site _gp_list_passwords() { gopass list --flat } # return password for argument passed _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" } # invoke the dotool to type inputs _type() { local tool local toolmode local key tool="${BACKEND}" toolmode="$1" key="$2" "$tool" "$toolmode" --delay "$AUTOENTRY_DELAY" "$key" } # automatically enter entry chain, set via AUTOENTRY_CHAIN # transform special chain entries into valid dotool commands autoentry() { local selected local autoentry_chain selected="${1}" autoentry_chain="${AUTOENTRY_CHAIN}" for part in $autoentry_chain; do case "$part" in ":tab") _type key Tab ;; ":return") _type key Return ;; ":space") _type key space ;; "username") _type type "$(_gp_show_username "$selected")" ;; "password") _type type "$(_gp_show_password "$selected")" ;; *) printf '%s' "$part" ;; esac done } 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}")" exit_value=$? exit_check "${exit_value}" case "${exit_value}" in # autoentry selected "10") autoentry "${entry}" exit ;; "11") printf '%s' "$(gopass show "${entry}" username)" | _dotool type exit ;; "12") printf '%s' "$(gopass show --password "${entry}")" | _dotool type exit ;; esac do_menu "${entry}" } main