|
@@ -17,6 +17,26 @@ checkmenu(){
|
|
|
done
|
|
|
}
|
|
|
|
|
|
+fileopener(){
|
|
|
+ editor="$(xdg-mime query default text/plain)"
|
|
|
+
|
|
|
+ [ -f "$HOME/.local/share/applications/${editor}" ] && path="$HOME/.local/share/applications/${editor}"
|
|
|
+
|
|
|
+ [ -z "$path" ] && [ -f "/usr/local/share/applications/${editor}" ] && path="/usr/local/share/applications/${editor}"
|
|
|
+
|
|
|
+ [ -z "$path" ] && [ -f "/usr/share/applications/${editor}" ] && path="/usr/share/applications/${editor}"
|
|
|
+
|
|
|
+ if [ -z "$path" ]; then
|
|
|
+ echo "Text editor cannot be found" >&2
|
|
|
+ fi
|
|
|
+
|
|
|
+ if grep -q "^Terminal=true$" "$path"; then
|
|
|
+ eval "${TERMINAL_EXEC:-xterm -e} $(grep "^Exec=" "$path" | head -n 1 | sed "{s/^Exec=//; s#%.#$1#}")"
|
|
|
+ else
|
|
|
+ eval "$(grep "^Exec=" "$path" | head -n 1 | sed "{s/^Exec=//; s#%.#$1#}")"
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
if [ -n "$WAYLAND_DISPLAY" ]; then
|
|
|
x11=false
|
|
|
if [ -z "$DMENU_COMMAND" ]; then
|
|
@@ -62,7 +82,7 @@ if [ -z "$dmenu" ]; then
|
|
|
fi
|
|
|
|
|
|
|
|
|
-usage="$(printf "USAGE:\nneopassmenu [OPTS] [Pass Entry]\n\nOptions:\n-a\t\tGenerate or modify a password\n-c\t\tCopy to clipboard instead of printing to stdout\n-t\t\tSimulate typing instead of printing to stdout\n-m\t\tSelect a specific line from a multiline file\n-o\t\tGet an otp instead of the password file (precedence over -m)\n-h\t\tPrint usage information\n\nCONFIGURATION:\nEnvironement variables:\nDMENU_COMMAND\tSpecify dmenu command (default: dmenu)")"
|
|
|
+usage="$(printf "USAGE:\nneopassmenu [OPTS] [Pass Entry]\n\nOptions:\n-a\t\tGenerate or modify a password\n-c\t\tCopy to clipboard instead of printing to stdout\n-t\t\tSimulate typing instead of printing to stdout\n-m\t\tSelect a specific line from a multiline file\n-o\t\tGet an otp instead of the password file (precedence over -m)\n-h\t\tPrint usage information\n\nCONFIGURATION:\nEnvironement variables:\nDMENU_COMMAND\tSpecify dmenu command (default: dmenu)\nTERMINAL\tSpecify the terminal command (default: xterm -e)")"
|
|
|
|
|
|
cd "${PASSWORD_STORE_DIR:-"$HOME/.password-store"}" || exit 2
|
|
|
|
|
@@ -138,15 +158,31 @@ if [ -z "$file" ]; then
|
|
|
fi
|
|
|
|
|
|
if "$add"; then
|
|
|
+ if $otp; then
|
|
|
+ if ! [ -f "${file}.gpg" ]; then
|
|
|
+ echo "Can't add otp to non-existent password"
|
|
|
+ exit 1
|
|
|
+ else
|
|
|
+ echo "Insert OTP uri" > /tmp/pass.txt
|
|
|
+ fileopener /tmp/pass.txt || notify-send "Error $?"
|
|
|
+ if [ -n "$(cat /tmp/pass.txt)" ]; then
|
|
|
+ sed p /tmp/pass.txt | pass otp add "${file}"
|
|
|
+ rm /tmp/pass.txt
|
|
|
+ exit $?
|
|
|
+ fi
|
|
|
+ rm /tmp/pass.txt
|
|
|
+ fi
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
if [ -f "${file}.gpg" ]; then
|
|
|
pass "$file" > /tmp/pass.txt
|
|
|
fi
|
|
|
printf "\n\n%s" "$(dd count=2 if=/dev/random of=/dev/stdout 2>/dev/null ibs=512 obs=512 | uuencode -m /dev/stdout | tail -n +2 | tr -d '\n')" >> /tmp/pass.txt
|
|
|
fileopener /tmp/pass.txt || notify-send "Error $?"
|
|
|
if [ -n "$(cat /tmp/pass.txt)" ]; then
|
|
|
- save="$(printf "yes\nno" | $dmenu $prompt_prefix "Save changes? ")"
|
|
|
+ save="$(printf "yes\nno" | $dmenu $prompt_prefix"Save changes? ")"
|
|
|
if [ "$save" = "yes" ]; then
|
|
|
- cat /tmp/pass.txt | pass add -m -f "$file"
|
|
|
+ pass add -m -f "$file" < /tmp/pass.txt
|
|
|
fi
|
|
|
rm /tmp/pass.txt
|
|
|
exit 0
|
|
@@ -166,8 +202,12 @@ else
|
|
|
fi
|
|
|
|
|
|
if $multi && ! $otp; then
|
|
|
- sel_password="$(echo "$password_lines" | sed 'h; s/^.\{1,2\}//; s/./*/g; x; s/^\(.\{1,2\}\).*/\1/; G; s/\n//' | $dmenu)"
|
|
|
- password_lines="$(echo "$password_lines" | grep -x "$(echo "$sel_password" | sed 'y/*/./' )")"
|
|
|
+ sel_password="$(echo "$password_lines" | sed '{h; s/^.\{1,2\}//; s/./*/g; x; s/^\(.\{1,2\}\).*/\1/; G; s/\n//}' | nl -b a -w 1 -s " " | $dmenu | cut -d " " -f 1)"
|
|
|
+ if echo "$sel_password" | grep -qE "^[0-9]+$"; then
|
|
|
+ password_lines="$(echo "$password_lines" | sed -n "$(echo "$sel_password" | cut -d " " -f 1){p;q}")"
|
|
|
+ else
|
|
|
+ password_lines=""
|
|
|
+ fi
|
|
|
|
|
|
# Sed script:
|
|
|
# Copy pattern space (line) to hold space. Pattern space: Foo Hold space: Foo
|