started refactoring
This commit is contained in:
parent
4c43d92c32
commit
908bcd4586
319
rofi-pass
319
rofi-pass
@ -17,34 +17,128 @@ list_passwords() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doClip () {
|
doClip () {
|
||||||
if [[ $clip == "primary" ]]; then
|
if [[ $clip == "primary" ]]; then xclip;
|
||||||
xclip
|
elif [[ $clip == "clipboard" ]]; then xclip -selection clipboard;
|
||||||
elif [[ $clip == "clipboard" ]]; then
|
elif [[ $clip == "both" ]]; then xclip; xclip -o | xclip -selection clipboard;
|
||||||
xclip -selection clipboard
|
|
||||||
elif [[ $clip == "both" ]]; then
|
|
||||||
xclip
|
|
||||||
xclip -o | xclip -selection clipboard
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIfPass () {
|
checkIfPass () {
|
||||||
if [[ $selected_password == "[ Add Entry ]>" ]]; then
|
if [[ $selected_password == "[ Add Entry ]>" ]]; then mainMenu;
|
||||||
mainMenu
|
elif [[ $selected_password == "---" ]]; then mainMenu;
|
||||||
elif [[ $selected_password == "[ Manage Database ]>" ]]; then
|
else
|
||||||
mainMenu
|
rm -f "$HOME/.config/rofi-pass/last_used"
|
||||||
elif [[ $selected_password == "---" ]]; then
|
echo "${root}: $selected_password" > "$HOME/.config/rofi-pass/last_used"
|
||||||
mainMenu
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
autopass () {
|
||||||
|
checkIfPass
|
||||||
|
if [[ ${selected_password} == "[ Add Entry ]>" ]]; then insertPass;
|
||||||
|
elif [[ ${selected_password} == "---" ]]; then mainMenu;
|
||||||
|
else
|
||||||
|
if [[ -z "${stuff["$AUTOTYPE_field"]}" ]]; then
|
||||||
|
echo -n "${stuff["${USERNAME_field}"]}" | xdotool type --clearmodifiers --file -
|
||||||
|
xdotool key Tab
|
||||||
|
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; fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
openURL () {
|
||||||
|
checkIfPass
|
||||||
|
$BROWSER "$(pass "$selected_password" | grep "${URL_field}: " | awk '{sub(/:/,"")}{print $2}1' | head -1)"; exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
typeUser () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${stuff[${USERNAME_field}]}" | xdotool type --clearmodifiers --file -
|
||||||
|
}
|
||||||
|
|
||||||
|
typePass () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${password}" | xdotool type --clearmodifiers --file -
|
||||||
|
if [[ $notify == "true" ]]; then
|
||||||
|
if [[ "${stuff[notify]}" == "false" ]]; then
|
||||||
|
:
|
||||||
|
else notify-send "rofi-pass" "finished typing password";
|
||||||
|
fi
|
||||||
|
elif [[ $notify == "false" ]]; then
|
||||||
|
if [[ "${stuff[notify]}" == "true" ]]; then notify-send "rofi-pass" "finished typing password";
|
||||||
|
else
|
||||||
|
:
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
typeField () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${stuff[${typefield}]}" | xdotool type --clearmodifiers --file -
|
||||||
|
}
|
||||||
|
|
||||||
|
copyUser () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${stuff[${USERNAME_field}]}" | doClip
|
||||||
|
}
|
||||||
|
|
||||||
|
copyField () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${stuff[${copyfield}]}" | doClip
|
||||||
|
}
|
||||||
|
|
||||||
|
copyURL () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "${stuff[${URL_field}]}" | doClip
|
||||||
|
}
|
||||||
|
|
||||||
|
copyPass () {
|
||||||
|
checkIfPass
|
||||||
|
echo -n "$password" | doClip
|
||||||
|
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") &
|
||||||
|
}
|
||||||
|
|
||||||
|
viewEntry () {
|
||||||
|
checkIfPass
|
||||||
|
showEntry "${selected_password}"
|
||||||
|
}
|
||||||
|
|
||||||
|
generatePass () {
|
||||||
|
checkIfPass
|
||||||
|
symbols=$(echo -e "0 Cancel\n---\n1 Yes\n2 No" | rofi -dmenu -p "Use Symbols? > ")
|
||||||
|
if [[ $symbols == "0 Cancel" ]]; then mainMenu;
|
||||||
|
elif [[ $symbols == "1 Yes" ]]; then symbols="";
|
||||||
|
elif [[ $symbols == "2 No" ]]; then symbols="-n";
|
||||||
|
fi
|
||||||
|
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}) > ")
|
||||||
|
if [[ $length == "" ]]; then pass generate ${symbols} -i "$selected_password" "${passlength}" > /dev/null;
|
||||||
|
else pass generate ${symbols} -i "$selected_password" "${length}" > /dev/null;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# main Menu
|
# main Menu
|
||||||
mainMenu () {
|
mainMenu () {
|
||||||
help_text=$(echo -e "${autotype}: Autotype - ${copy_name}: Copy User - ${edit}: Edit - ${show}: Show Entry\n${type_user}: Type User - ${copy_pass}: Copy Pass - ${move}: Move - ${generate}: Generate Pass\n${type_pass}: Type Pass - ${copy_url}: Copy URL - ${delete}: Delete" | column -s '-' -t)
|
help_text=$(echo -e "${autotype}: Autotype - ${copy_menu}: Copy Field - ${show}: View\n${type_menu}: Type Field - ${action_menu}: Actions - ${help}: Help" | column -s '-' -t)
|
||||||
line1=$(echo "${help_text}" | head -1)
|
line1=$(echo "${help_text}" | head -1)
|
||||||
line2=$(echo "${help_text}" | tail -2 | head -1)
|
line2=$(echo "${help_text}" | head -2 | tail -1)
|
||||||
line3=$(echo "${help_text}" | tail -1)
|
line3=$(echo "${help_text}" | tail -1)
|
||||||
HELP="<span color='$help_color'>${line1}
|
HELP="<span color='$help_color'>${line1}
|
||||||
${line2}
|
|
||||||
${line3}</span>"
|
${line3}</span>"
|
||||||
selected_password="$(echo -e "[ Add Entry ]>\n---\n$(list_passwords 2>/dev/null)" \
|
selected_password="$(echo -e "[ Add Entry ]>\n---\n$(list_passwords 2>/dev/null)" \
|
||||||
| _rofi -mesg "${HELP}" \
|
| _rofi -mesg "${HELP}" \
|
||||||
@ -57,49 +151,20 @@ ${line3}</span>"
|
|||||||
-kb-custom-7 "${show}" \
|
-kb-custom-7 "${show}" \
|
||||||
-kb-custom-8 "${copy_url}" \
|
-kb-custom-8 "${copy_url}" \
|
||||||
-kb-custom-9 "${edit}" \
|
-kb-custom-9 "${edit}" \
|
||||||
-kb-custom-10 "${move}" \
|
-kb-custom-13 "${type_menu}" \
|
||||||
-kb-custom-11 "${delete}" \
|
-kb-custom-14 "${action_menu}" \
|
||||||
-kb-custom-12 "${generate}" \
|
-kb-custom-15 "${copy_menu}" \
|
||||||
|
-kb-custom-16 "${help}" \
|
||||||
-dmenu \
|
-dmenu \
|
||||||
-select "$entry" \
|
-select "$entry" \
|
||||||
-p "rofi-pass > ")"
|
-p "rofi-pass > ")"
|
||||||
|
|
||||||
rofi_exit=$?
|
rofi_exit=$?
|
||||||
|
|
||||||
if [[ -n $selected_password ]]; then
|
# generate Array of fields
|
||||||
if [[ $selected_password == "[ Add Entry ]>" ]]; then
|
|
||||||
:
|
|
||||||
elif [[ $selected_password == "[ Manage Database ]>" ]]; then
|
|
||||||
:
|
|
||||||
elif [[ $selected_password == "---" ]]; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
rm -f "$HOME/.config/rofi-pass/last_used"
|
|
||||||
echo "${root}: $selected_password" > "$HOME/.config/rofi-pass/last_used"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${rofi_exit}" -eq 0 ]]; then
|
|
||||||
if [[ ${selected_password} == "[ Add Entry ]>" ]]; then
|
|
||||||
insertPass
|
|
||||||
elif [[ ${selected_password} == "---" ]]; then
|
|
||||||
mainMenu
|
|
||||||
else
|
|
||||||
true
|
|
||||||
fi
|
|
||||||
elif [[ "${rofi_exit}" -eq 13 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
$BROWSER "$(pass "$selected_password" | grep "${URL_field}: " | awk '{sub(/:/,"")}{print $2}1' | head -1)"; exit;
|
|
||||||
elif [[ "${rofi_exit}" -eq 1 ]]; then exit ${rofi_exit};
|
|
||||||
elif [[ "${rofi_exit}" -eq 10 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
declare -A stuff
|
declare -A stuff
|
||||||
|
|
||||||
while read LINE; do
|
while read LINE; do
|
||||||
_id=$(echo -e "${LINE}" | awk -F ':[[:space:]]*' '{print $1}')
|
_id=$(echo -e "${LINE}" | awk -F ':[[:space:]]*' '{print $1}')
|
||||||
_val=$(echo -e "${LINE}" | awk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}')
|
_val=$(echo -e "${LINE}" | awk '{sub(/:/,"")}{for (i=2; i<NF; i++) printf $i " "; print $NF}')
|
||||||
@ -107,112 +172,22 @@ ${line3}</span>"
|
|||||||
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}
|
||||||
|
|
||||||
if [[ $rofi_exit -eq 11 ]]; then
|
# actions based on keypresses
|
||||||
checkIfPass
|
if [[ "${rofi_exit}" -eq 0 ]]; then autopass;
|
||||||
echo -n "${stuff[${USERNAME_field}]}" | xdotool type --clearmodifiers --file -
|
elif [[ "${rofi_exit}" -eq 13 ]]; then openURL;
|
||||||
exit
|
elif [[ "${rofi_exit}" -eq 1 ]]; then exit ${rofi_exit};
|
||||||
|
elif [[ "${rofi_exit}" -eq 10 ]]; then autopass;
|
||||||
elif [[ "${rofi_exit}" -eq 18 ]]; then
|
elif [[ "${rofi_exit}" -eq 11 ]]; then typeUser;
|
||||||
manageEntry edit;
|
elif [[ "${rofi_exit}" -eq 12 ]]; then typePass;
|
||||||
|
elif [[ "${rofi_exit}" -eq 14 ]]; then copyUser;
|
||||||
elif [[ "${rofi_exit}" -eq 19 ]]; then
|
elif [[ "${rofi_exit}" -eq 17 ]]; then copyURL;
|
||||||
manageEntry move;
|
elif [[ "${rofi_exit}" -eq 16 ]]; then viewEntry;
|
||||||
|
elif [[ "${rofi_exit}" -eq 15 ]]; then copyPass;
|
||||||
elif [[ "${rofi_exit}" -eq 20 ]]; then
|
elif [[ "${rofi_exit}" -eq 22 ]]; then typeMenu;
|
||||||
manageEntry delete;
|
elif [[ "${rofi_exit}" -eq 23 ]]; then actionMenu;
|
||||||
|
elif [[ "${rofi_exit}" -eq 25 ]]; then helpMenu;
|
||||||
elif [[ "${rofi_exit}" -eq 21 ]]; then
|
elif [[ "${rofi_exit}" -eq 24 ]]; then copyMenu;
|
||||||
checkIfPass
|
|
||||||
symbols=$(echo -e "0 Cancel\n---\n1 Yes\n2 No" | rofi -dmenu -p "Use Symbols? > ")
|
|
||||||
if [[ $symbols == "0 Cancel" ]]; then
|
|
||||||
mainMenu
|
|
||||||
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>"
|
|
||||||
length=$(echo -e "" | rofi -dmenu -mesg "${HELP}" -p "Password length? (Default: ${passlength}) > ")
|
|
||||||
if [[ $length == "" ]]; then
|
|
||||||
pass generate ${symbols} -i "$selected_password" "${passlength}" > /dev/null
|
|
||||||
else
|
|
||||||
pass generate ${symbols} -i "$selected_password" "${length}" > /dev/null
|
|
||||||
fi
|
|
||||||
exit
|
|
||||||
|
|
||||||
elif [[ $rofi_exit -eq 12 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
echo -n "${password}" | xdotool type --clearmodifiers --file -
|
|
||||||
if [[ $notify == "true" ]]; then
|
|
||||||
if [[ "${stuff[notify]}" == "false" ]]; then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
notify-send "rofi-pass" "finished typing password"
|
|
||||||
fi
|
|
||||||
elif [[ $notify == "false" ]]; then
|
|
||||||
if [[ "${stuff[notify]}" == "true" ]]; then
|
|
||||||
notify-send "rofi-pass" "finished typing password"
|
|
||||||
else
|
|
||||||
:
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
exit
|
|
||||||
|
|
||||||
elif [[ $rofi_exit -eq 14 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
echo -n "${stuff[${USERNAME_field}]}" | doClip
|
|
||||||
exit
|
|
||||||
|
|
||||||
elif [[ $rofi_exit -eq 17 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
echo -n "${stuff[${URL_field}]}" | doClip
|
|
||||||
exit
|
|
||||||
|
|
||||||
elif [[ $rofi_exit -eq 16 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
showEntry "${selected_password}"
|
|
||||||
|
|
||||||
elif [[ $rofi_exit -eq 15 ]]; then
|
|
||||||
checkIfPass
|
|
||||||
echo -n "$password" | doClip
|
|
||||||
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") &
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z "${stuff["$AUTOTYPE_field"]}" ]]; then
|
|
||||||
echo -n "${stuff[${USERNAME_field}]}" | xdotool type --clearmodifiers --file -
|
|
||||||
|
|
||||||
xdotool key Tab
|
|
||||||
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
|
|
||||||
#xdotool key Tab
|
|
||||||
done
|
|
||||||
if [[ ${auto_enter} == "true" ]]; then
|
|
||||||
xdotool key Return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
password=''
|
password=''
|
||||||
selected_password=''
|
selected_password=''
|
||||||
unset stuff
|
unset stuff
|
||||||
@ -222,6 +197,39 @@ ${line3}</span>"
|
|||||||
unset stuff
|
unset stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helpMenu () {
|
||||||
|
help=$(echo -e "${type_user}: Type User
|
||||||
|
${type_pass}: Type Password
|
||||||
|
${type_menu}: Type Custom Field
|
||||||
|
${autotype}: Autotype
|
||||||
|
---
|
||||||
|
${copy_name}: Copy Username
|
||||||
|
${copy_pass}: Copy Password
|
||||||
|
${copy_url}: Copy URL
|
||||||
|
${copy_menu}: Copy Custom Field
|
||||||
|
---
|
||||||
|
${action_menu}: Edit, Move, Delete, Re-generate Submenu
|
||||||
|
${show}: Show Password File" | rofi -dmenu -p "Help > ")
|
||||||
|
}
|
||||||
|
|
||||||
|
typeMenu () {
|
||||||
|
typefield=$(pass "${selected_password}" | awk -F ':' '{ print $1 }' | grep -Ev '\-\-\-' | tail -n +2 | rofi -dmenu -p "Choose Field to type > ")
|
||||||
|
typeField
|
||||||
|
}
|
||||||
|
|
||||||
|
copyMenu () {
|
||||||
|
copyfield=$(pass "${selected_password}" | awk -F ':' '{ print $1 }' | grep -Ev '\-\-\-' | tail -n +2 | rofi -dmenu -p "Choose Field to type > ")
|
||||||
|
copyField
|
||||||
|
}
|
||||||
|
|
||||||
|
actionMenu () {
|
||||||
|
action=$(echo -e "1 Move Password File\n2 Delete Password File\n3 Generate New Password" | rofi -dmenu -p "Choose Action > ")
|
||||||
|
if [[ ${action} == "1 Move Password File" ]]; then manageEntry move;
|
||||||
|
elif [[ ${action} == "2 Delete Password File" ]]; then manageEntry delete;
|
||||||
|
elif [[ ${action} == "3 Generate New Password" ]]; then generatePass;
|
||||||
|
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---\n$(PASSWORD_STORE_DIR="${root}" pass "$selected_password")" | _rofi -dmenu -mesg "${HELP}" -p "> ")
|
bla=$(echo -e "0 Return\n---\n$(PASSWORD_STORE_DIR="${root}" pass "$selected_password")" | _rofi -dmenu -mesg "${HELP}" -p "> ")
|
||||||
@ -298,6 +306,7 @@ manageEntry () {
|
|||||||
cd "${root}"
|
cd "${root}"
|
||||||
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
|
||||||
PASSWORD_STORE_DIR="${root}" pass mv "$selected_password" "${group}"
|
PASSWORD_STORE_DIR="${root}" pass mv "$selected_password" "${group}"
|
||||||
mainMenu
|
mainMenu
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user