modernize UI

This commit is contained in:
Rasmus Steinke 2016-06-15 07:08:40 +02:00
parent f71c27746f
commit 6f8c3d803e

129
rofi-pass
View File

@ -18,15 +18,20 @@ list_passwords() {
} }
doClip () { doClip () {
if [[ $clip == "primary" ]]; then xclip; if [[ $clip == "primary" ]]; then
elif [[ $clip == "clipboard" ]]; then xclip -selection clipboard; xclip
elif [[ $clip == "both" ]]; then xclip; xclip -o | xclip -selection clipboard; elif [[ $clip == "clipboard" ]]; then
xclip -selection clipboard;
elif [[ $clip == "both" ]]; then
xclip; xclip -o | xclip -selection clipboard;
fi fi
} }
checkIfPass () { checkIfPass () {
if [[ $selected_password == "[ Add Entry ]>" ]]; then mainMenu; if [[ $selected_password == "[ Add Entry ]>" ]]; then
elif [[ $selected_password == "---" ]]; then mainMenu; mainMenu;
elif [[ $selected_password == "---" ]]; then
mainMenu;
else else
rm -f "/tmp/$USER-rofi-pass/last_used" rm -f "/tmp/$USER-rofi-pass/last_used"
echo "${root}: $selected_password" > "/tmp/$USER-rofi-pass/last_used" echo "${root}: $selected_password" > "/tmp/$USER-rofi-pass/last_used"
@ -35,8 +40,10 @@ checkIfPass () {
autopass () { autopass () {
if [[ ${selected_password} == "[ Add Entry ]>" ]]; then insertPass; if [[ ${selected_password} == "[ Add Entry ]>" ]]; then
elif [[ ${selected_password} == "---" ]]; then mainMenu; insertPass;
elif [[ ${selected_password} == "---" ]]; then
mainMenu;
else else
rm -f "/tmp/$USER-rofi-pass/last_used" rm -f "/tmp/$USER-rofi-pass/last_used"
echo "${root}: $selected_password" > "/tmp/$USER-rofi-pass/last_used" echo "${root}: $selected_password" > "/tmp/$USER-rofi-pass/last_used"
@ -47,19 +54,29 @@ autopass () {
fi fi
echo -n "${password}" | xdotool type --clearmodifiers --file - echo -n "${password}" | xdotool type --clearmodifiers --file -
sleep 1 sleep 1
if [[ ${auto_enter} == "true" ]]; then xdotool key Return; fi if [[ ${auto_enter} == "true" ]]; then
xdotool key Return
fi
else else
echo "${stuff["$AUTOTYPE_field"]}" echo "${stuff["$AUTOTYPE_field"]}"
for word in ${stuff["$AUTOTYPE_field"]}; do for word in ${stuff["$AUTOTYPE_field"]}; do
if [[ $word == ":tab" ]]; then xdotool key Tab; if [[ $word == ":tab" ]]; then
elif [[ $word == ":space" ]]; then xdotool key space; xdotool key Tab;
elif [[ $word == ":delay" ]]; then sleep "${delay}"; elif [[ $word == ":space" ]]; then
elif [[ $word == ":enter" ]]; then xdotool key Return; xdotool key space
elif [[ $word == "pass" ]]; then echo -n "${password}" | xdotool type --clearmodifiers --file -; elif [[ $word == ":delay" ]]; then
else echo -n "${stuff[${word}]}" | xdotool type --clearmodifiers --file - 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 fi
done done
if [[ ${auto_enter} == "true" ]]; then xdotool key Return; fi if [[ ${auto_enter} == "true" ]]; then
xdotool key Return
fi
fi fi
fi fi
} }
@ -80,10 +97,12 @@ typePass () {
if [[ $notify == "true" ]]; then if [[ $notify == "true" ]]; then
if [[ "${stuff[notify]}" == "false" ]]; then if [[ "${stuff[notify]}" == "false" ]]; then
: :
else notify-send "rofi-pass" "finished typing password"; else
notify-send "rofi-pass" "finished typing password";
fi fi
elif [[ $notify == "false" ]]; then elif [[ $notify == "false" ]]; then
if [[ "${stuff[notify]}" == "true" ]]; then notify-send "rofi-pass" "finished typing password"; if [[ "${stuff[notify]}" == "true" ]]; then
notify-send "rofi-pass" "finished typing password";
else else
: :
fi fi
@ -134,15 +153,20 @@ generatePass () {
checkIfPass checkIfPass
symbols=$(echo -e "0 Cancel\n---\n1 Yes\n2 No" | rofi -dmenu -p "Use Symbols? > ") symbols=$(echo -e "0 Cancel\n---\n1 Yes\n2 No" | rofi -dmenu -p "Use Symbols? > ")
if [[ $symbols == "0 Cancel" ]]; then mainMenu; if [[ $symbols == "0 Cancel" ]]; then
elif [[ $symbols == "1 Yes" ]]; then symbols=""; mainMenu;
elif [[ $symbols == "2 No" ]]; then symbols="-n"; elif [[ $symbols == "1 Yes" ]]; then
symbols="";
elif [[ $symbols == "2 No" ]]; then
symbols="-n";
fi fi
HELP="<span color='$help_color'>Enter Number or hit Enter to use default length</span>" HELP="<span color='$help_color'>Enter Number or hit Enter to use default length</span>"
length=$(echo -e "" | _rofi -dmenu -mesg "${HELP}" -p "Password length? (Default: ${passlength}) > ") length=$(echo -e "" | _rofi -dmenu -mesg "${HELP}" -p "Password length? (Default: ${passlength}) > ")
askGen askGen
if [[ $length == "" ]]; then pass generate ${symbols} -i "$selected_password" "${passlength}" > /dev/null; if [[ $length == "" ]]; then
else pass generate ${symbols} -i "$selected_password" "${length}" > /dev/null; pass generate ${symbols} -i "$selected_password" "${passlength}" > /dev/null;
else
pass generate ${symbols} -i "$selected_password" "${length}" > /dev/null;
fi fi
} }
@ -167,12 +191,9 @@ mainMenu () {
fi fi
else else
unset selected_password unset selected_password
help_text=$({ echo -e "Enter: Autotype - ${action_menu}: Actions - ${show}: View"; echo "${type_menu}: Type Field - ${copy_menu}: Copy Field - ${help}: Help";} | column -s '-' -t) HELP="Welcome to rofi-pass. Use <span color='$help_color'>${insert_pass}</span> to create a new pass entry.
line1=$(echo "${help_text}" | head -1) To type User/Pass use <span color='$help_color'>Enter</span>. For more help hit <span color='$help_color'>${help}</span>."
line3=$(echo "${help_text}" | tail -1) selected_password="$(list_passwords 2>/dev/null \
HELP="<span color='$help_color'>${line1}
${line3}</span>"
selected_password="$({ echo -e "[ Add Entry ]>\n---"; list_passwords 2>/dev/null;} \
| _rofi -mesg "${HELP}" \ | _rofi -mesg "${HELP}" \
-dmenu -kb-accept-entry '!Return' -kb-custom-1 "${autotype}" \ -dmenu -kb-accept-entry '!Return' -kb-custom-1 "${autotype}" \
-kb-custom-2 "${type_user}" \ -kb-custom-2 "${type_user}" \
@ -246,12 +267,13 @@ ${type_menu}: Type Custom Field
${copy_name}: Copy Username ${copy_name}: Copy Username
${copy_pass}: Copy Password ${copy_pass}: Copy Password
${copy_url}: Copy URL ${copy_url}: Copy URL
${open_url}: Open URL
${copy_menu}: Copy Custom Field ${copy_menu}: Copy Custom Field
--- ---
${action_menu}: Edit, Move, Delete, Re-generate Submenu ${action_menu}: Edit, Move, Delete, Re-generate Submenu
${show}: Show Password File ${show}: Show Password File
${insert_pass}: Insert new Pass Entry ${insert_pass}: Insert new Pass Entry
${switch}: Switch Pass/Bookmark Mode" | _rofi -dmenu -p "Help > ") ${switch}: Switch Pass/Bookmark Mode" | _rofi -dmenu -mesg "Hint: All hotkeys are configurable in config file" -p "Help > ")
help_val=$? help_val=$?
if [[ $help_val -eq 1 ]]; then exit; if [[ $help_val -eq 1 ]]; then exit;
else unset helptext; mainMenu; fi else unset helptext; mainMenu; fi
@ -300,18 +322,24 @@ copyMenu () {
actionMenu () { actionMenu () {
checkIfPass checkIfPass
action=$(echo -e "< Return\n---\n1 Move Password File\n2 Delete Password File\\n3 Edit Password File\n4 Generate New Password" | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Action > ") action=$(echo -e "< Return\n---\n1 Move Password File\n2 Delete Password File\\n3 Edit Password File\n4 Generate New Password" | _rofi -kb-accept-entry '!Return' -dmenu -p "Choose Action > ")
if [[ ${action} == "1 Move Password File" ]]; then manageEntry move; if [[ ${action} == "1 Move Password File" ]]; then
elif [[ ${action} == "2 Delete Password File" ]]; then manageEntry delete; manageEntry move;
elif [[ ${action} == "3 Edit Password File" ]]; then manageEntry edit; elif [[ ${action} == "2 Delete Password File" ]]; then
elif [[ ${action} == "4 Generate New Password" ]]; then generatePass; manageEntry delete;
elif [[ ${action} == "< Return" ]]; then mainMenu; elif [[ ${action} == "3 Edit Password File" ]]; then
elif [[ ${action} == "" ]]; then exit manageEntry edit;
elif [[ ${action} == "4 Generate New Password" ]]; then
generatePass;
elif [[ ${action} == "< Return" ]]; then
mainMenu;
elif [[ ${action} == "" ]]; then
exit
fi fi
} }
showEntry () { showEntry () {
HELP="<span color='$help_color'>${type_entry}: Type Entry | ${copy_entry}: Copy Entry</span>" HELP="<span color='$help_color'>${type_entry}: Type Entry | ${copy_entry}: Copy Entry</span>"
bla=$({ echo -e "0 Return\n---"; PASSWORD_STORE_DIR="${root}" pass "$selected_password";} | _rofi -kb-accept-entry '!Return' -dmenu -mesg "${HELP}" -p "> ") bla=$({ echo -e "< Return\n---"; PASSWORD_STORE_DIR="${root}" pass "$selected_password";} | _rofi -kb-accept-entry '!Return' -dmenu -mesg "${HELP}" -p "> ")
rofi_exit=$? rofi_exit=$?
password_temp=$(PASSWORD_STORE_DIR="${root}" pass "$selected_password") password_temp=$(PASSWORD_STORE_DIR="${root}" pass "$selected_password")
password=$(echo "${password_temp}" | head -1) password=$(echo "${password_temp}" | head -1)
@ -321,21 +349,21 @@ showEntry () {
_id=$(echo "${LINE}" | gawk -F ':[[:space:]]*' '{print $1}') _id=$(echo "${LINE}" | gawk -F ':[[:space:]]*' '{print $1}')
_val=$(echo "${LINE}" | gawk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}') _val=$(echo "${LINE}" | gawk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}')
stuff["${_id}"]=${_val} stuff["${_id}"]=${_val}
done < <(PASSWORD_STORE_DIR="${root}" pass "${selected_password}" | tail -n+2 | grep -P '(: |:\t)' ) done < <(PASSWORD_STORE_DIR="${root}" pass "${selected_password}" | tail -n+2 | grep -P '(: |:\t)' )
stuff["pass"]=${password} stuff["pass"]=${password}
word=$(echo "$bla" | gawk -F': ' '{print $1}') word=$(echo "$bla" | gawk -F': ' '{print $1}')
if [[ ${rofi_exit} -eq 0 ]]; then if [[ ${rofi_exit} -eq 0 ]]; then
if [[ $bla == "" ]]; then exit if [[ $bla == "" ]]; then
elif [[ $bla == "0 Return" ]]; then exit
elif [[ $bla == "< Return" ]]; then
selected_password="" selected_password=""
mainMenu mainMenu
fi fi
elif [[ ${rofi_exit} -eq 1 ]]; then elif [[ ${rofi_exit} -eq 1 ]]; then
exit exit
elif [[ ${rofi_exit} -eq 11 ]]; then elif [[ ${rofi_exit} -eq 11 ]]; then
if [[ ${bla} == "0 Return" ]]; then if [[ ${bla} == "< Return" ]]; then
echo "not doing anything" echo "not doing anything"
else else
if [[ -z $(echo -n "${stuff[${word}]}") ]]; then if [[ -z $(echo -n "${stuff[${word}]}") ]]; then
@ -346,10 +374,9 @@ showEntry () {
notify-send "rofi-pass" "Copied Password\nClearing in 45 seconds" notify-send "rofi-pass" "Copied Password\nClearing in 45 seconds"
$(sleep 45; echo -n "" | xclip; echo "" | xclip -selection clipboard | notify-send "rofi-pass" "Clipboard cleared") & $(sleep 45; echo -n "" | xclip; echo "" | xclip -selection clipboard | notify-send "rofi-pass" "Clipboard cleared") &
exit exit
fi fi
elif [[ ${rofi_exit} -eq 10 ]]; then elif [[ ${rofi_exit} -eq 10 ]]; then
if [[ ${bla} == "0 Return" ]]; then if [[ ${bla} == "< Return" ]]; then
echo "not doing anything" echo "not doing anything"
else else
if [[ -z $(echo -n "${stuff[${word}]}") ]]; then if [[ -z $(echo -n "${stuff[${word}]}") ]]; then
@ -380,15 +407,15 @@ manageEntry () {
if [[ "$1" == "edit" ]]; then if [[ "$1" == "edit" ]]; then
EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${selected_password}" EDITOR=$EDITOR PASSWORD_STORE_DIR="${root}" pass edit "${selected_password}"
mainMenu mainMenu
elif [[ $1 == "move" ]]; then elif [[ $1 == "move" ]]; then
cd "${root}" || exit cd "${root}" || exit
selected_password2=$(basename "$selected_password" .gpg) selected_password2=$(basename "$selected_password" .gpg)
group=$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2- | _rofi -dmenu -p "Choose Group > ") group=$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2- | _rofi -dmenu -p "Choose Group > ")
if [[ $group == "" ]]; then exit; fi if [[ $group == "" ]]; then
exit
fi
PASSWORD_STORE_DIR="${root}" pass mv "$selected_password" "${group}" PASSWORD_STORE_DIR="${root}" pass mv "$selected_password" "${group}"
mainMenu mainMenu
elif [[ "$1" == "delete" ]]; then elif [[ "$1" == "delete" ]]; then
HELP="<span color='$help_color'>Selected entry: ${selected_password}</span>" HELP="<span color='$help_color'>Selected entry: ${selected_password}</span>"
ask=$(echo -e "Yes\nNo" | _rofi -mesg "${HELP}" -dmenu -p "Are You Sure? > ") ask=$(echo -e "Yes\nNo" | _rofi -mesg "${HELP}" -dmenu -p "Are You Sure? > ")
@ -414,13 +441,19 @@ insertPass () {
name="$(listgpg | rofi -dmenu -format 'f' -mesg "Type name, make sure it is unique" -p "> ")" name="$(listgpg | rofi -dmenu -format 'f' -mesg "Type name, make sure it is unique" -p "> ")"
# name="$(echo -e "$(list_passwords 2>/dev/null)" | rofi -dmenu -mesg "Type name, make sure it is unique" -p "> ")" # name="$(echo -e "$(list_passwords 2>/dev/null)" | rofi -dmenu -mesg "Type name, make sure it is unique" -p "> ")"
val=$? val=$?
if [[ $val -eq 1 ]]; then exit; fi if [[ $val -eq 1 ]]; then
exit
fi
user=$(echo -e "${default_user2}\n$USER\n${default_user}" | rofi -dmenu -mesg "Chose Username or type" -p "> ") user=$(echo -e "${default_user2}\n$USER\n${default_user}" | rofi -dmenu -mesg "Chose Username or type" -p "> ")
val=$? val=$?
if [[ $val -eq 1 ]]; then exit; fi if [[ $val -eq 1 ]]; then
exit
fi
group=$(echo -e "No Group\n---\n$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2-)" | rofi -dmenu -p "Choose Group > ") group=$(echo -e "No Group\n---\n$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2-)" | rofi -dmenu -p "Choose Group > ")
val=$? val=$?
if [[ $val -eq 1 ]]; then exit; fi if [[ $val -eq 1 ]]; then
exit
fi
if [[ "$group" == "No Group" ]]; then if [[ "$group" == "No Group" ]]; then
if [[ $url == http* ]]; then if [[ $url == http* ]]; then