aboutsummaryrefslogtreecommitdiff
path: root/base/otp
diff options
context:
space:
mode:
authorAdam Hovorka <[email protected]>2020-05-19 16:22:59 -0600
committerAdam Hovorka <[email protected]>2020-05-19 16:22:59 -0600
commitb75d3bb22bf773ccd2ca9331808f0c2018f2fab9 (patch)
tree640d0feb497820cb5e28798efd73344fe43f160a /base/otp
parent0a312771ee7a79d5682d9d7f6fdf94d6de2fb579 (diff)
Add .bin/otp (pretty pass OTP tui)
Diffstat (limited to 'base/otp')
-rwxr-xr-xbase/otp70
1 files changed, 70 insertions, 0 deletions
diff --git a/base/otp b/base/otp
new file mode 100755
index 0000000..e8c11f9
--- /dev/null
+++ b/base/otp
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+shopt -s nullglob globstar
+
+PREFIX=${PASSWORD_STORE_DIR-~/.password-store}
+PREFIX="$PREFIX/otp"
+if [[ ! -d "$PREFIX" ]]; then
+ echo "Pass OTP does not exist" >&1
+ exit 1
+fi
+
+if [[ "$1" ]]; then
+ if [[ ! -f "$PREFIX/$1.gpg" ]]; then
+ echo "otp/$1 does not exist" >&1
+ exit 1
+ fi
+ SITE="$1"
+else
+ OTPFILES=( "$PREFIX"/**/*.gpg )
+ OTPFILES=( "${OTPFILES[@]#"$PREFIX"/}" )
+ OTPFILES=( "${OTPFILES[@]%.gpg}" )
+ SITE="$(printf '%s\n' "${OTPFILES[@]}" |
+ fzf --height 8 --reverse --no-multi --prompt="Select Site: ")"
+ if [[ ! "$SITE" ]]; then exit; fi
+fi
+
+URL="$(pass "otp/$SITE" 2>/dev/null | head -n1)"
+if [[ "$?" != "0" ]]; then echo "Authentication failed" >&2; exit 1; fi
+PERIOD="$(echo "$URL" | sed 's/^.*period=\([0-9]\+\).*$/\1/')"
+#BLOCKS=(" " "▏" "▎" "▍" "▌" "▋" "▊" "▉")
+BLOCKS=(" " "▎" "▌" "▊")
+TOTAL=$(( $PERIOD / 4 ))
+echo
+
+function finish {
+ echo -ne "\r"
+ tput el
+ tput cuu1
+ tput cnorm
+ exit 0
+}
+
+trap finish SIGINT SIGTERM SIGQUIT
+tput civis
+
+while :; do
+ CODE="$(pass otp "otp/$SITE" 2>/dev/null)"
+ WAIT=$(( $PERIOD - ( $(date +%s) % $PERIOD ) ))
+ FULL=$(( $WAIT / 4 ))
+ PARTIAL=$(( $WAIT % 4 ))
+ BLANK=$(( $TOTAL - $FULL))
+
+ tput bold; tput setab 8; echo -ne "\r "
+ tput setaf 8; tput setab 18; echo -n " "
+ tput setaf 6; echo -n "$SITE"
+ tput setaf 8; echo -n "  "
+ tput sgr0
+ tput setaf 16; tput setab 18; echo -n "$CODE"
+ tput setaf 8; echo -n " "
+ for i in `seq $FULL`; do echo -n "█"; done
+ echo -n "${BLOCKS[$PARTIAL]}"
+ for i in `seq $BLANK`; do echo -n " "; done
+ tput sgr0; tput setaf 18; echo -n ""
+ tput sgr0
+
+ #sleep 0.1
+ read -rsn1 -t.1 INP
+ if [[ "$INP" = "q" || "$INP" = "Q" ||
+ "$INP" = "$(echo -ne "\e")" ]]; then finish; fi
+done