From 7008ba72bf9b64130fc716464c517908d89012df Mon Sep 17 00:00:00 2001 From: mxmehl Date: Fri, 16 Dec 2016 11:49:50 +0100 Subject: [PATCH] exit program when pressing cancel; adding pronouncable password generation --- gpassgen.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gpassgen.sh b/gpassgen.sh index 1c99198..623dc12 100755 --- a/gpassgen.sh +++ b/gpassgen.sh @@ -23,29 +23,49 @@ # ######################################################################## +function checkexit { + if [ $1 = 1 ]; then exit 1; fi +} cd "$(dirname "$(readlink -f "$0")")" if [ $(zenity --question --cancel-label "More options" --ok-label "Close" --text "$(apg -m 16 -M NCL -a 1)" --title "Generated Passwords"; echo $?) == 1 ]; then # More options requested - echo $POPT PLEN=$(zenity --entry --text "Desired length of password(s)" --title "Enter password length") + checkexit $? + + PALG=$(zenity --list \ + --text="Choose between random character or pronouncable passwords" \ + --title="Choose password algorithm" \ + --column="Option" --column="Description" \ + 1 "Random character passwords" \ + 0 "Pronouncable password algorithm" \ + ) + checkexit $? + PALG=$(echo $PALG | sed 's/|//g') + POPT=$(zenity --list --multiple \ - --text="Choose one or multiple generator options" \ - --title="Choose password options" \ - --column="Option" --column="Description" \ + --text="Choose one or multiple generator options" \ + --title="Choose password options" \ + --column="Option" --column="Description" \ N "Numerical" \ C "Capital letters" \ L "Lower case letters" \ ) + checkexit $? POPT=$(echo $POPT | sed 's/|//g') + PAMT=$(zenity --entry --text "Desired amount of generated passwords" --title "Enter password amount") + checkexit $? # Set defaults if no entry was given if [ "$PLEN" == "" ]; then PLEN="12" fi + if [ "$PALG" == "" ]; then + PLEN="1" + fi if [ "$POPT" == "" ]; then POPT="NCL" fi @@ -54,5 +74,5 @@ if [ $(zenity --question --cancel-label "More options" --ok-label "Close" --text fi # Output desired passwords - $(zenity --info --text "$(apg -a 1 -m $PLEN -M $POPT -n $PAMT)" --title "Generated Passwords") + $(zenity --info --text "$(apg -a $PALG -m $PLEN -M $POPT -n $PAMT)" --title "Generated Passwords") fi