From 38e02922e1181f9f867585e8945b72134c256b93 Mon Sep 17 00:00:00 2001 From: Rasmus Steinke Date: Tue, 26 Jul 2016 01:01:33 +0200 Subject: change defaults. Enter shows menu with fields to type now. Hotkeys 1-3 remain (autotype, type user, type password) --- rofi-pass | 184 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 86 insertions(+), 98 deletions(-) diff --git a/rofi-pass b/rofi-pass index 282674f..a3a4bf2 100755 --- a/rofi-pass +++ b/rofi-pass @@ -41,44 +41,38 @@ checkIfPass () { autopass () { - if [[ ${selected_password} == "[ Add Entry ]>" ]]; then - insertPass; - elif [[ ${selected_password} == "---" ]]; then - mainMenu; + rm -f "$HOME/.cache/rofi-pass/last_used" + echo "${root}: $selected_password" > "$HOME/.cache/rofi-pass/last_used" + chmod 600 "$HOME/.cache/rofi-pass/last_used" + if [[ -z "${stuff["$AUTOTYPE_field"]}" ]]; then + if [[ "${stuff["${USERNAME_field}"]}" ]]; then + echo -n "${stuff["${USERNAME_field}"]}" | xdotool type --clearmodifiers --file - + xdotool key Tab + fi + echo -n "${password}" | xdotool type --clearmodifiers --file - + sleep 1 + if [[ ${auto_enter} == "true" ]]; then + xdotool key Return + fi else - rm -f "$HOME/.cache/rofi-pass/last_used" - echo "${root}: $selected_password" > "$HOME/.cache/rofi-pass/last_used" - chmod 600 "$HOME/.cache/rofi-pass/last_used" - if [[ -z "${stuff["$AUTOTYPE_field"]}" ]]; then - if [[ "${stuff["${USERNAME_field}"]}" ]]; then - echo -n "${stuff["${USERNAME_field}"]}" | xdotool type --clearmodifiers --file - - xdotool key Tab - fi - echo -n "${password}" | xdotool type --clearmodifiers --file - - sleep 1 - if [[ ${auto_enter} == "true" ]]; then - xdotool key Return - fi - else - echo "${stuff["$AUTOTYPE_field"]}" - for word in ${stuff["$AUTOTYPE_field"]}; do - if [[ $word == ":tab" ]]; then - xdotool key Tab; - elif [[ $word == ":space" ]]; then - xdotool key space - elif [[ $word == ":delay" ]]; then - sleep "${delay}"; - elif [[ $word == ":enter" ]]; then - xdotool key Return; - elif [[ $word == "pass" ]]; then - echo -n "${password}" | xdotool type --clearmodifiers --file -; - else - echo -n "${stuff[${word}]}" | xdotool type --clearmodifiers --file - - fi - done - if [[ ${auto_enter} == "true" ]]; then - xdotool key Return + echo "${stuff["$AUTOTYPE_field"]}" + for word in ${stuff["$AUTOTYPE_field"]}; do + if [[ $word == ":tab" ]]; then + xdotool key Tab; + elif [[ $word == ":space" ]]; then + xdotool key space + elif [[ $word == ":delay" ]]; then + sleep "${delay}"; + elif [[ $word == ":enter" ]]; then + xdotool key Return; + elif [[ $word == "pass" ]]; then + echo -n "${password}" | xdotool type --clearmodifiers --file -; + else + echo -n "${stuff[${word}]}" | xdotool type --clearmodifiers --file - fi + done + if [[ ${auto_enter} == "true" ]]; then + xdotool key Return fi fi } @@ -217,47 +211,49 @@ To perform default action use Enter. For more h rofi_exit=$? - if [[ ${selected_password} == "[ Add Entry ]>" ]]; then - : + # generate Array of fields + password_temp=$(PASSWORD_STORE_DIR="${root}" pass "$selected_password") + password=$(echo "${password_temp}" | head -1) + declare -A stuff + while read -r LINE; do + _id=$(echo "${LINE}" | gawk -F ':[[:space:]]*' '{print $1}') + _val=$(echo "${LINE}" | gawk '{sub(/:/,"")}{for (i=2; i ") + typefield=$(printf '%s\n' "${!stuff[@]}" | sort | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Field to type > ") + val=$? + if [[ $val -eq 1 ]]; then + exit + fi if [[ $typefield == "" ]]; then exit; elif [[ $typefield == "password" ]]; then - typePass; - elif [[ $typefield == "< Return" ]]; then - mainMenu; + typePass; + elif [[ $typefield == "${AUTOTYPE_field}" ]]; then + autopass else typeField fi @@ -303,23 +297,17 @@ typeMenu () { copyMenu () { checkIfPass - copyfield=$({ echo -e "< Return\n---\npassword"; \ - pass "${selected_password}" \ - | grep -P ':[\t ]' \ - | gawk -F ':' '{ print $1 }';} \ - | _rofi -kb-accept-entry '!Return' \ - -dmenu \ - -p "Choose Field to copy > ") - if [[ $copyfield == "" ]]; then + copyfield=$(printf '%s\n' "${!stuff[@]}" | sort | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Field to type > ") + val=$? + if [[ $val -eq 1 ]]; then exit; - elif [[ $copyfield == "password" ]]; then + fi + if [[ $copyfield == "password" ]]; then copyPass; - elif [[ $copyfield == "< Return" ]]; then - mainMenu; else copyField - fi -} + fi +} actionMenu () { checkIfPass -- cgit