commit 41568376523a5ac60ba5816dc6041d5bab041c1a
parent a9c7cd5bfcb2a42636ab6f276af94c4847d533c0
Author: kar <kar@13f0.net>
Date: Thu, 29 Aug 2024 00:29:26 -0400
add totp field to be used with oathtool
Currently it's fragile like using it with invalid file path will give
a garbage code, but I'm pretty much the only user anyways. Use keepass
or pass if you want robustness.
Diffstat:
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/angou b/angou
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/sh -e
# sets the directory with all your passwords
ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"}
@@ -11,7 +11,7 @@ ANGOU_GEN_PASS=${ANGOU_GEN_PASS:-"random pass"}
ANGOU_GEN_USER=${ANGOU_GEN_USER:-"random user"}
mkdir -p "$ANGOU_DIR"
-cd "$ANGOU_DIR" || exit
+cd "$ANGOU_DIR"
# decrypt and print a password from ANGOU_DIR or print the directory structure
view() {
@@ -21,27 +21,27 @@ view() {
tree "${1:-.}"
else
usage
- exit
+ exit 1
fi
}
# view the first line
view_single() {
- [ ! -f $1 ] && usage && exit
+ [ ! -f "$1" ] && usage && exit 1
view "$1" | sed 1q | tr -d \\n
}
# copy the first line from view to clipboard
copy() {
- [ ! -f $1 ] && usage && exit
+ [ ! -f "$1" ] && usage && exit 1
view_single "$1" | $ANGOU_CLIPBOARD
}
# create new or existing password in ANGOU_DIR
edit() {
- [ -d "$1" ] && usage && exit
+ [ -d "$1" ] && usage && exit 1
tmpfile="$(mktemp)"
@@ -59,6 +59,17 @@ edit() {
$ANGOU_ENCRYPT "$tmpfile" >"$1"
}
+totp_view() {
+ [ -d "$1" ] && usage && exit 1
+
+ secret=$(view "$1" | grep TOTP | cut -d' ' -f 2)
+ oathtool -b --totp "$secret"
+}
+
+totp() {
+ totp_view "$1" | tr -d '\n' | $ANGOU_CLIPBOARD
+}
+
# print usage
usage() {
printf "Usage: %s [help|copy|edit|generate|view|view_single [file or directory]]\n" "$0"
@@ -79,5 +90,7 @@ case "$option" in
generate) edit "$2" generate ;;
view) view "$2" ;;
pass) view_single "$2" ;;
+ totp_view) totp_view "$2" ;;
+ totp) totp "$2" ;;
*) view "$1" ;;
esac
diff --git a/contrib/autocomplete.zsh b/contrib/autocomplete.zsh
@@ -6,5 +6,5 @@ passwords() {
}
_arguments \
- '1:angou commands:(copy edit generate help pass view)' \
+ '1:angou commands:(copy edit generate help pass view totp totp_view)' \
'2:passwords:passwords'