use external editor for creating new entries

This commit is contained in:
Rasmus Steinke 2016-05-24 23:10:13 +02:00
parent 0d6f2882ed
commit 160e5d11df
2 changed files with 20 additions and 86 deletions

View File

@ -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"

101
rofi-pass
View File

@ -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 "<span color='$help_color'>For faster adding use the addpass command</span>" -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="<span color='$help_color'>Enter Domain Name</span>"
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="<span color='$help_color'>Enter Username</span>"
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="<span color='$help_color'>Choose one password or type your own</span>"
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 ""