change defaults. Enter shows menu with fields to type now. Hotkeys 1-3 remain (autotype, type user, type password)

This commit is contained in:
Rasmus Steinke 2016-07-26 01:01:33 +02:00
parent 27d4b80431
commit 38e02922e1

182
rofi-pass
View File

@ -41,44 +41,38 @@ checkIfPass () {
autopass () { autopass () {
if [[ ${selected_password} == "[ Add Entry ]>" ]]; then rm -f "$HOME/.cache/rofi-pass/last_used"
insertPass; echo "${root}: $selected_password" > "$HOME/.cache/rofi-pass/last_used"
elif [[ ${selected_password} == "---" ]]; then chmod 600 "$HOME/.cache/rofi-pass/last_used"
mainMenu; 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 else
rm -f "$HOME/.cache/rofi-pass/last_used" echo "${stuff["$AUTOTYPE_field"]}"
echo "${root}: $selected_password" > "$HOME/.cache/rofi-pass/last_used" for word in ${stuff["$AUTOTYPE_field"]}; do
chmod 600 "$HOME/.cache/rofi-pass/last_used" if [[ $word == ":tab" ]]; then
if [[ -z "${stuff["$AUTOTYPE_field"]}" ]]; then xdotool key Tab;
if [[ "${stuff["${USERNAME_field}"]}" ]]; then elif [[ $word == ":space" ]]; then
echo -n "${stuff["${USERNAME_field}"]}" | xdotool type --clearmodifiers --file - xdotool key space
xdotool key Tab elif [[ $word == ":delay" ]]; then
fi sleep "${delay}";
echo -n "${password}" | xdotool type --clearmodifiers --file - elif [[ $word == ":enter" ]]; then
sleep 1 xdotool key Return;
if [[ ${auto_enter} == "true" ]]; then elif [[ $word == "pass" ]]; then
xdotool key Return echo -n "${password}" | xdotool type --clearmodifiers --file -;
fi else
else echo -n "${stuff[${word}]}" | xdotool type --clearmodifiers --file -
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
done
if [[ ${auto_enter} == "true" ]]; then
xdotool key Return
fi fi
fi fi
} }
@ -217,47 +211,49 @@ To perform default action use <span color='$help_color'>Enter</span>. For more h
rofi_exit=$? rofi_exit=$?
if [[ ${selected_password} == "[ Add Entry ]>" ]]; then # generate Array of fields
: password_temp=$(PASSWORD_STORE_DIR="${root}" pass "$selected_password")
else password=$(echo "${password_temp}" | head -1)
# generate Array of fields declare -A stuff
password_temp=$(PASSWORD_STORE_DIR="${root}" pass "$selected_password") while read -r LINE; do
password=$(echo "${password_temp}" | head -1) _id=$(echo "${LINE}" | gawk -F ':[[:space:]]*' '{print $1}')
declare -A stuff _val=$(echo "${LINE}" | gawk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}')
while read -r LINE; do stuff["${_id}"]=${_val}
_id=$(echo "${LINE}" | gawk -F ':[[:space:]]*' '{print $1}') done < <(PASSWORD_STORE_DIR="${root}" pass "${selected_password}" | tail -n+2 | grep -P '(: |:\t)' )
_val=$(echo "${LINE}" | gawk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}') stuff["pass"]=${password}
stuff["${_id}"]=${_val}
done < <(PASSWORD_STORE_DIR="${root}" pass "${selected_password}" | tail -n+2 | grep -P '(: |:\t)' )
stuff["pass"]=${password}
fi
# actions based on keypresses
if [[ "${rofi_exit}" -eq 0 ]]; then ${default_do};
elif [[ "${rofi_exit}" -eq 13 ]]; then openURL;
elif [[ "${rofi_exit}" -eq 1 ]]; then exit ${rofi_exit};
elif [[ "${rofi_exit}" -eq 10 ]]; then autopass;
elif [[ "${rofi_exit}" -eq 11 ]]; then typeUser;
elif [[ "${rofi_exit}" -eq 12 ]]; then typePass;
elif [[ "${rofi_exit}" -eq 14 ]]; then copyUser;
elif [[ "${rofi_exit}" -eq 17 ]]; then copyURL;
elif [[ "${rofi_exit}" -eq 16 ]]; then viewEntry;
elif [[ "${rofi_exit}" -eq 15 ]]; then copyPass;
elif [[ "${rofi_exit}" -eq 22 ]]; then typeMenu;
elif [[ "${rofi_exit}" -eq 23 ]]; then actionMenu;
elif [[ "${rofi_exit}" -eq 25 ]]; then unset selected_password; helpMenu;
elif [[ "${rofi_exit}" -eq 24 ]]; then copyMenu;
elif [[ "${rofi_exit}" -eq 26 ]]; then $(${basecommand} --bmarks);
elif [[ "${rofi_exit}" -eq 27 ]]; then insertPass;
fi
password=''
selected_password=''
unset stuff
unset password
unset selected_password
unset password_temp
unset stuff
fi fi
if test "${stuff['autotype']+autotype}"
then
:
else
stuff["autotype"]="user :tab pass"
fi;
# actions based on keypresses
if [[ "${rofi_exit}" -eq 0 ]]; then typeMenu;
elif [[ "${rofi_exit}" -eq 13 ]]; then openURL;
elif [[ "${rofi_exit}" -eq 1 ]]; then exit ${rofi_exit};
elif [[ "${rofi_exit}" -eq 10 ]]; then autopass;
elif [[ "${rofi_exit}" -eq 14 ]]; then copyMenu;
elif [[ "${rofi_exit}" -eq 11 ]]; then typeUser;
elif [[ "${rofi_exit}" -eq 12 ]]; then typePass;
elif [[ "${rofi_exit}" -eq 17 ]]; then copyURL;
elif [[ "${rofi_exit}" -eq 16 ]]; then viewEntry;
elif [[ "${rofi_exit}" -eq 15 ]]; then copyPass;
elif [[ "${rofi_exit}" -eq 22 ]]; then typeMenu;
elif [[ "${rofi_exit}" -eq 23 ]]; then actionMenu;
elif [[ "${rofi_exit}" -eq 25 ]]; then unset selected_password; helpMenu;
elif [[ "${rofi_exit}" -eq 24 ]]; then copyMenu;
elif [[ "${rofi_exit}" -eq 26 ]]; then $(${basecommand} --bmarks);
elif [[ "${rofi_exit}" -eq 27 ]]; then insertPass;
fi
password=''
selected_password=''
unset stuff
unset password
unset selected_password
unset password_temp
unset stuff
} }
helpMenu () { helpMenu () {
@ -283,19 +279,17 @@ else unset helptext; mainMenu; fi
typeMenu () { typeMenu () {
checkIfPass checkIfPass
typefield=$({ echo -e "< Return\n---\npassword"; \ typefield=$(printf '%s\n' "${!stuff[@]}" | sort | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Field to type > ")
pass "${selected_password}" \ val=$?
| grep -P ':[\t ]' \ if [[ $val -eq 1 ]]; then
| gawk -F ':' '{ print $1 }';} \ exit
| _rofi -kb-accept-entry '!Return' \ fi
-dmenu \
-p "Choose Field to type > ")
if [[ $typefield == "" ]]; then if [[ $typefield == "" ]]; then
exit; exit;
elif [[ $typefield == "password" ]]; then elif [[ $typefield == "password" ]]; then
typePass; typePass;
elif [[ $typefield == "< Return" ]]; then elif [[ $typefield == "${AUTOTYPE_field}" ]]; then
mainMenu; autopass
else else
typeField typeField
fi fi
@ -303,19 +297,13 @@ typeMenu () {
copyMenu () { copyMenu () {
checkIfPass checkIfPass
copyfield=$({ echo -e "< Return\n---\npassword"; \ copyfield=$(printf '%s\n' "${!stuff[@]}" | sort | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Field to type > ")
pass "${selected_password}" \ val=$?
| grep -P ':[\t ]' \ if [[ $val -eq 1 ]]; then
| gawk -F ':' '{ print $1 }';} \
| _rofi -kb-accept-entry '!Return' \
-dmenu \
-p "Choose Field to copy > ")
if [[ $copyfield == "" ]]; then
exit; exit;
elif [[ $copyfield == "password" ]]; then fi
if [[ $copyfield == "password" ]]; then
copyPass; copyPass;
elif [[ $copyfield == "< Return" ]]; then
mainMenu;
else else
copyField copyField
fi fi