From b75d3bb22bf773ccd2ca9331808f0c2018f2fab9 Mon Sep 17 00:00:00 2001 From: Adam Hovorka Date: Tue, 19 May 2020 16:22:59 -0600 Subject: Add .bin/otp (pretty pass OTP tui) --- base/otp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 base/otp (limited to 'base') 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 -- cgit v1.2.3-70-g09d2