split manu menu from manage menu

This commit is contained in:
Rasmus Steinke 2015-07-17 18:16:25 +02:00
parent 6637fca949
commit 5f8deed989

View File

@ -2,13 +2,14 @@
# rofi-pass
# (c) 2015 Rasmus Steinke <rasi@xssn.at>
# (c) 2015 Thore Bödecker <me@foxxx0.de>
# enable extended globbing
shopt -s nullglob globstar
# read global config file
source /etc/rofi-pass.conf
# import parsers to local config directory
if [[ ! -d $HOME/.config/rofi-pass/parsers ]]; then
mkdir $HOME/.config/rofi-pass/parsers
cp /usr/share/doc/rofi-pass/parsers/* $HOME/.config/rofi-pass/parsers
@ -24,12 +25,14 @@ if [[ -z $BROWSER ]]; then
export BROWSER=xdg-open
fi
# check if alternative root directory was given on commandline
if [[ -n "$2" && "$1" == "--root" ]]; then
root="${2}"
else
:
fi
# get all password files and create an array
list_passwords() {
if [[ -n "$root" ]]; then
passwords=( "${basedir}/${root}"/**/*.gpg )
@ -44,48 +47,31 @@ list_passwords() {
done
}
# make xdotool type letter by letter
xdotool_type() {
for (( i=0; i<${#1}; i++ )); do
xdotool type "${1:$i:1}"
done
}
# main Menu
mainMenu () {
if [[ $1 == "manage" ]]; then
HELP="<span color='$help_color'>${edit}: Edit Entry | ${move}: Move Entry | ${delete}: Delete Entry | ${show}: Show Entry</span>"
selected_password="$(echo -e "0 Return to Main Menu\n---\n$(list_passwords 2>/dev/null)" | rofi -custom-kb-1 "${edit}" -custom-kb-2 "${move}" -custom-kb-3 "${delete}" -custom-kb-4 "${show}" -mesg "${HELP}" -dmenu -select "$entry" -p "rofi-pass > ")"
rofi_exit=$?
if [[ "${rofi_exit}" -eq 0 ]]; then true;
elif [[ "${rofi_exit}" -eq 10 ]]; then manageEntry edit;
elif [[ "${rofi_exit}" -eq 11 ]]; then manageEntry move;
elif [[ "${rofi_exit}" -eq 1 ]]; then exit;
elif [[ "${rofi_exit}" -eq 12 ]]; then manageEntry delete;
elif [[ "${rofi_exit}" -eq 13 ]]; then showEntry;
fi
if [[ "$selected_password" == "0 Return to Main Menu" ]]; then
mainMenu
else
mainMenu manage
fi
else
HELP="<span color='$help_color'>${autotype}: Autotype | ${type_user}: Type User | ${type_pass}: Type Password
${open_url}: Open URL | ${copy_name}: Copy Username | ${copy_pass}: Copy Password</span>"
selected_password="$(echo -e "[ Add Entry ]>\n[ Manage Database ]>\n---\n$(list_passwords 2>/dev/null)" | rofi -mesg "${HELP}" -dmenu -kb-custom-1 "${autotype}" -kb-custom-2 "${type_user}" -kb-custom-3 "${type_pass}" -kb-custom-4 "${open_url}" -kb-custom-5 "${copy_name}" -kb-custom-6 "${copy_pass}" -dmenu -select "$entry" -kb-custom-8 "Alt+c" -kb-custom-9 "Alt+Shift+c" -p "rofi-pass > ")"
HELP="<span color='$help_color'>${autotype}: Autotype | ${type_user}: Type User | ${type_pass}: Type Password
${open_url}: Open URL | ${copy_name}: Copy Username | ${copy_pass}: Copy Password | ${show}: Show Entry</span>"
selected_password="$(echo -e "[ Add Entry ]>\n[ Manage Database ]>\n---\n$(list_passwords 2>/dev/null)" | rofi -mesg "${HELP}" -dmenu -kb-custom-1 "${autotype}" -kb-custom-2 "${type_user}" -kb-custom-3 "${type_pass}" -kb-custom-4 "${open_url}" -kb-custom-5 "${copy_name}" -kb-custom-6 "${copy_pass}" -kb-custom-7 "${show}" -dmenu -select "$entry" -p "rofi-pass > ")"
rofi_exit=$?
if [[ "${rofi_exit}" -eq 0 ]]; then true;
elif [[ "${rofi_exit}" -eq 10 ]]; then true;
elif [[ "${rofi_exit}" -eq 13 ]]; then $BROWSER $(pass "$selected_password" | grep "URL: " | awk -F 'URL: ' '{ print $2 }'); exit;
if [[ "${rofi_exit}" -eq 13 ]]; then $BROWSER $(pass "$selected_password" | grep "URL: " | awk -F 'URL: ' '{ print $2 }'); exit;
elif [[ "${rofi_exit}" -eq 1 ]]; then exit ${rofi_exit};
elif [[ "${rofi_exit}" -eq 10 || "${rofi-exit}" -eq 0 ]]; then true
fi
if [[ "$selected_password" == "[ Add Entry ]>" ]]; then
insertPass
elif [[ "$selected_password" == "[ Manage Database ]>" ]]; then
mainMenu manage
manageEntry
elif [[ "$selected_password" == "" ]]; then
exit
fi
fi
password_temp=$(pass "$selected_password")
password=$(echo "${password_temp}" | head -1)
@ -107,6 +93,8 @@ ${open_url}: Open URL | ${copy_name}: Copy Username | ${copy_pass}: Copy Passwor
elif [[ $rofi_exit -eq 14 ]]; then
echo -n "${stuff[${USERNAME_field}]}" | xclip
exit
elif [[ $rofi_exit -eq 16 ]]; then
showEntry
elif [[ $rofi_exit -eq 15 ]]; then
echo -n "$password" | xclip
xclip -o | xclip -selection clipboard
@ -146,9 +134,26 @@ ${open_url}: Open URL | ${copy_name}: Copy Username | ${copy_pass}: Copy Passwor
unset stuff
}
manageMenu() {
HELP="<span color='$help_color'>${edit}: Edit Entry | ${move}: Move Entry | ${delete}: Delete Entry</span>"
selected_password="$(echo -e "0 Return to Main Menu\n---\n$(list_passwords 2>/dev/null)" | rofi -custom-kb-1 "${edit}" -custom-kb-2 "${move}" -custom-kb-3 "${delete}" -mesg "${HELP}" -dmenu -select "$entry" -p "rofi-pass > ")"
rofi_exit=$?
if [[ "${rofi_exit}" -eq 0 && "${selected_password}" != "0 Return to Main Menu" ]]; then showEntry;
elif [[ "${rofi_exit}" -eq 10 ]]; then manageEntry edit;
elif [[ "${rofi_exit}" -eq 11 ]]; then manageEntry move;
elif [[ "${rofi_exit}" -eq 1 ]]; then exit;
elif [[ "${rofi_exit}" -eq 12 ]]; then manageEntry delete;
fi
if [[ "$selected_password" == "0 Return to Main Menu" ]]; then
mainMenu
else
manageMenu
fi
}
showEntry () {
menu=$(echo -e "0 Return to Manage Menu\n---\n$(pass "$selected_password")" | rofi -dmenu -p "> ")
if [[ $menu == "0 Return to Manage Menu" ]]; then mainMenu manage
if [[ $menu == "0 Return to Manage Menu" ]]; then manageMenu
elif [[ $menu == "" ]]; then exit
else
showEntry
@ -158,22 +163,22 @@ showEntry () {
manageEntry () {
if [[ "$1" == "edit" ]]; then
EDITOR=$EDITOR pass edit "${selected_password}"
mainMenu manage
manageMenu
elif [[ $1 == "move" ]]; then
cd "$HOME"/.password-store/"${root}"
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 > ")
pass mv "$selected_password" "${root}"/"${group}"/"${selected_password2}"
mainMenu manage
manageMenu
elif [[ "$1" == "delete" ]]; then
ask=$(echo -e "Yes\nNo" | rofi -dmenu -p "Are You Sure? >")
if [[ "$ask" == "Yes" ]]; then
pass rm --force "${selected_password}"
elif [[ "$ask" == "no" ]]; then
mainMenu manage
manageMenu
fi
else
mainMenu manage
manageMenu
fi
}
@ -284,7 +289,7 @@ case $1 in
insertPass
;;
--root)
mainMenu $2
mainMenu
;;
--manage)
manageEntry