2 کامیت‌ها 0de2867d13 ... ddb1c0c2c2

نویسنده SHA1 پیام تاریخ
  BezierQuadratic ddb1c0c2c2 Rewrite and OTP support 10 ماه پیش
  BezierQuadratic 04bfeedf05 Simplified sed script 10 ماه پیش
1فایلهای تغییر یافته به همراه32 افزوده شده و 40 حذف شده
  1. 32 40
      neopassmenu.sh

+ 32 - 40
neopassmenu.sh

@@ -4,6 +4,7 @@ multi=false
 clipboard=false
 type=false
 add=false
+otp=false
 file=""
 dir=""
 
@@ -89,6 +90,10 @@ while [ "$#" -gt 0 ]; do
 			echo "$usage"
 			exit 0
 			;;
+		-o)
+			otp=true
+			shift
+			;;
 		*)
 			if [ -f "$1" ] || [ -f "${1}.gpg" ]; then
 				file="$1"
@@ -154,58 +159,45 @@ if ! [ -f "$file" ] && ! [ -f "${file}.gpg" ]; then
 	exit 127
 fi
 
-if $clipboard && ! $multi; then
-	if $x11; then
-		printf "%s" "$(pass "$file")" | xclip -in -selection clipboard
-	else
-		printf "%s" "$(pass "$file")" | wl-copy -n
-	fi
-	exit 0
-elif $type && ! $multi; then
-	if $x11; then
-		printf "%s" "$(pass "$file")" | xdotool type --clearmodifiers --file -
-	else
-		printf "%s" "$(pass "$file")" | ydotool type --file -
-	fi
-	exit 0
+if ! $otp; then
+	password_lines="$(pass "$file")"
+else
+	password_lines="$(pass otp "$file")"
 fi
 
-password_lines="$(pass "$file")"
+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/*/./' )")"
+
+	# Sed script:
+	# Copy pattern space (line) to hold space. Pattern space: Foo Hold space: Foo
+	# Delete first or first two characters in pattern space. Pattern space: o Hold space: Foo
+	# Replace every character in patter space with "*", Pattern space: * Hold Space: Foo
+	# Swap pattern space with hold space. Pattern Space: Foo Hold space: *
+	# Delete all the characters in pattern space after the first two. Pattern Space: Fo Hold Space: *
+	# Append newline followed by the Hold Space to the Pattern Space. Pattern Space: Fo\n* Hold Space: *
+	# Remove the (supposedly only) newline from the pattern space. Pattern Space: Fo* Hold Space: *
+	# Sed automatically prints the pattern space at the end of a script (unless the -n option is given). Output: Fo*
+fi
 
-if ! $multi; then
-	echo "$password_lines"
-	exit 0
+if [ -z "$password_lines" ]; then
+	"No password found or selected"
 fi
 
-password="$(echo "$password_lines" | sed '{ h; s/^.$//; s/^..//; s/./*/g; x; s/^\(..\).*/\1/; G; s/\n//; }' | $dmenu)"
-# Sed script:
-# Copy pattern space (line) to hold space. Pattern space: Foo Hold space: Foo
-# If the patter space is a single character, delete the character (prevents "a" to be outputted as "aa")
-# Delete the first two characters of the patter space. Pattern Space: o; Hold space: Foo
-# Replace all the characters in the pattern space with the literal "*". Pattern Space: *; Hold space: Foo
-# Swap pattern space with hold space. Pattern Space: Foo Hold space: *
-# Match the first two characters of the pattern space, then all the rest of the characters
-# substitute with the whole match (entire line) with the first submatch (first 2 characters). Pattern Space: Fo Hold Space: *
-# Append newline followed by the Hold Space to the Pattern Space. Pattern Space: Fo\n* Hold Space: *
-# Remove the (supposedly only) newline from the pattern space. Pattern Space: Fo* Hold Space: *
-# Sed automatically prints the pattern space at the end of a script (unless the -n option is given). Output: Fo*
-
-password="$(echo "$password_lines" | grep -xE "$(echo "$password" | sed 'y/*/./' )")"
-
-if "$clipboard"; then
+if $clipboard; then
 	if $x11; then
-		printf "%s" "$password" | xclip -in -selection clipboard
+		printf "%s" "$password_lines" | xclip -in -selection clipboard
 	else
-		printf "%s" "$password" | wl-copy -n
+		printf "%s" "$password_lines" | wl-copy -n
 	fi
 	exit 0
-elif "$type"; then
+elif $type; then
 	if $x11; then
-		printf "%s" "$password" | xdotool type --clearmodifiers --file -
+		printf "%s" "$password_lines" | xdotool type --clearmodifiers --file -
 	else
-		printf "%s" "$password" | ydotool type --file -
+		printf "%s" "$password_lines" | ydotool type --file -
 	fi
 	exit 0
 fi
 
-echo "$password"
+echo "$password_lines"