From 160e5d11df28ccb3fad4178a5f73a735ac52963f Mon Sep 17 00:00:00 2001 From: Rasmus Steinke Date: Tue, 24 May 2016 23:10:13 +0200 Subject: [PATCH] use external editor for creating new entries --- config.example | 5 +++ rofi-pass | 101 ++++++++----------------------------------------- 2 files changed, 20 insertions(+), 86 deletions(-) diff --git a/config.example b/config.example index 80a067a..fb03d83 100644 --- a/config.example +++ b/config.example @@ -41,6 +41,11 @@ help_color="" # Possible options: primary, clipboard, both clip=primary +# Options for generating new password entries +default_user=john_doe +default_user2=mary_ann +password_length=12 + # Custom Keybindings autotype="Alt+1" type_user="Alt+2" diff --git a/rofi-pass b/rofi-pass index 6fd9d9a..8cd440b 100755 --- a/rofi-pass +++ b/rofi-pass @@ -385,97 +385,26 @@ manageEntry () { } insertPass () { - if [[ -z "$pass" ]]; then - if [[ -n "$1" ]]; then - pass="$1" - pass2="***" - else - pass2="Empty" - fi - fi - if [[ -z "$user" ]]; then user="Empty"; fi - if [[ -z "$domain" ]]; then domain="Empty"; fi - if [[ -z "$name" ]]; then name="Empty"; fi + cd "${root}" + name="$(echo -e "$(list_passwords 2>/dev/null)" | rofi -dmenu -mesg "Type name, make sure it is unique" -p "> ")" + val=$? + 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 "> ") + val=$? + 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 > ") + val=$? + if [[ $val -eq 1 ]]; then exit; fi - insertmenu=$(echo -e "0 Return to Main Menu\n* Accept Values and Add Password Entry\n---\n1 Name ($name)\n2 URL ($domain)\n3 User ($user)\n4 Password ($pass2)" | _rofi -dmenu -mesg "For faster adding use the addpass command" -p "Add Entry > ") - insert_val=$? - if [[ $insert_val -eq 1 ]]; then exit + if [[ "$group" == "No Group" ]]; then + echo $EDITOR + echo -e "PASS\n---\nuser: $user" | pass insert -m "${name}" > /dev/null && pass generate -ni "${name}" "${password_length}" >/dev/null && pass edit "${name}" else - if [[ $insertmenu == "0 Return to Main Menu" ]]; then mainMenu - elif [[ $insertmenu == "" ]]; then exit - elif [[ $insertmenu == "* Accept Values and Add Password Entry" ]]; then - cd "${root}" || exit - 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 > ") - if [[ "$group" == "No Group" ]]; then - PASSWORD_STORE_DIR="${root}" pass insert -m -f "${name}" < <(echo -e "${pass}\n${USERNAME_field}: ${user}\n---\n${URL_field}: ${domain}") - elif [[ "$group" == "" ]]; then - exit - else - PASSWORD_STORE_DIR="${root}" pass insert -m -f "${group}/${name}" < <(echo -e "${pass}\nU${USERNAME_field}: ${user}\n---\n${URL_field}: ${domain}") - fi - exit - elif [[ $insertmenu == "1 Name"* ]]; then - name=$(echo "" | _rofi -dmenu -p "Enter Name > ") - insertPass - - elif [[ $insertmenu == "2 URL"* ]]; then - HELP="Enter Domain Name" - domain=$(echo -e "< Return" | _rofi -dmenu -mesg "${HELP}" -p "URL > ") - if [[ $domain == "< Return" ]]; then - insertPass - elif [[ $domain == "" ]]; then - exit - else - insertPass - fi - elif [[ $insertmenu == "3 User"* ]]; then - HELP="Enter Username" - user=$(echo -e "" | _rofi -dmenu -mesg "${HELP}" -p "Username > ") - insertPass - elif [[ $insertmenu == "4 Password"* ]]; then - password_length=12 - symbols="False" - numerals="True" - capitals="True" - password_gen - else - insertPass - fi + echo $EDITOR + echo -e "PASS\n---\nuser: $user" | pass insert -m "${group}/${name}" > /dev/null && pass generate -ni "${group}/${name}" "${password_length}" >/dev/null && pass edit "${group}/${name}" fi } -password_gen () { - if [[ $capitals == "True" ]]; then cap="-c"; else cap="-A"; fi - if [[ $symbols == "True" ]]; then sym="-y"; else sym=""; fi - if [[ $numerals == "True" ]]; then num="-n"; else num="-0"; fi - HELP="Choose one password or type your own" - menu=$(echo -e "0 Return to Insert Menu\n* Generate new Password\n---\n1 Password Length\n2 Include Capitals ($capitals)\n3 Include Numerals ($numerals)\n4 Include Symbols ($symbols)\n---\n$(pwgen $num $cap $sym -B -1 $password_length 5)" | _rofi -dmenu -mesg "${HELP}" -p "Password > ") - - if [[ $menu == "1 Password Length" ]]; then - password_length=$(echo -e "5\n7\n10\n12\n15\n20" | _rofi -dmenu -p "Choose Length > ") - password_gen - elif [[ $menu == "0 Return to Insert Menu" ]]; then - insertPass - elif [[ $menu == "* Generate new Password" ]]; then - password_gen - elif [[ $menu == "2 Include Capitals"* ]]; then - capitals=$(echo -e "True\nFalse" | _rofi -dmenu -p "Capitals? > ") - password_gen - elif [[ $menu == "3 Include Numerals"* ]]; then - numerals=$(echo -e "True\nFalse" | _rofi -dmenu -p "Numerals? > ") - password_gen - elif [[ $menu == "4 Include Symbols"* ]]; then - symbols=$(echo -e "True\nFalse" | _rofi -dmenu -p "Symbols? > ") - password_gen - else - insertPass "$menu" - fi -} - -#function _rofi () { -# rofi -dmenu -z ${rofiopts} "$@" -#} - help_msg () { echo "rofi-pass (Version: 1.2)" echo ""