diff options
| author | kar <kar@13f0.net> | 2024-08-29 00:29:26 -0400 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2024-08-30 14:01:27 -0400 |
| commit | 41568376523a5ac60ba5816dc6041d5bab041c1a (patch) | |
| tree | a2f2790b0c278c1ec54718bdb14dca30d6866615 | |
| parent | a9c7cd5bfcb2a42636ab6f276af94c4847d533c0 (diff) | |
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.
| -rwxr-xr-x | angou | 25 | ||||
| -rw-r--r-- | contrib/autocomplete.zsh | 2 |
2 files changed, 20 insertions, 7 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh -e |
| 2 | 2 | ||
| 3 | # sets the directory with all your passwords | 3 | # sets the directory with all your passwords |
| 4 | ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} | 4 | ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} |
| @@ -11,7 +11,7 @@ ANGOU_GEN_PASS=${ANGOU_GEN_PASS:-"random pass"} | |||
| 11 | ANGOU_GEN_USER=${ANGOU_GEN_USER:-"random user"} | 11 | ANGOU_GEN_USER=${ANGOU_GEN_USER:-"random user"} |
| 12 | 12 | ||
| 13 | mkdir -p "$ANGOU_DIR" | 13 | mkdir -p "$ANGOU_DIR" |
| 14 | cd "$ANGOU_DIR" || exit | 14 | cd "$ANGOU_DIR" |
| 15 | 15 | ||
| 16 | # decrypt and print a password from ANGOU_DIR or print the directory structure | 16 | # decrypt and print a password from ANGOU_DIR or print the directory structure |
| 17 | view() { | 17 | view() { |
| @@ -21,27 +21,27 @@ view() { | |||
| 21 | tree "${1:-.}" | 21 | tree "${1:-.}" |
| 22 | else | 22 | else |
| 23 | usage | 23 | usage |
| 24 | exit | 24 | exit 1 |
| 25 | fi | 25 | fi |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | # view the first line | 28 | # view the first line |
| 29 | view_single() { | 29 | view_single() { |
| 30 | [ ! -f $1 ] && usage && exit | 30 | [ ! -f "$1" ] && usage && exit 1 |
| 31 | 31 | ||
| 32 | view "$1" | sed 1q | tr -d \\n | 32 | view "$1" | sed 1q | tr -d \\n |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | # copy the first line from view to clipboard | 35 | # copy the first line from view to clipboard |
| 36 | copy() { | 36 | copy() { |
| 37 | [ ! -f $1 ] && usage && exit | 37 | [ ! -f "$1" ] && usage && exit 1 |
| 38 | 38 | ||
| 39 | view_single "$1" | $ANGOU_CLIPBOARD | 39 | view_single "$1" | $ANGOU_CLIPBOARD |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | # create new or existing password in ANGOU_DIR | 42 | # create new or existing password in ANGOU_DIR |
| 43 | edit() { | 43 | edit() { |
| 44 | [ -d "$1" ] && usage && exit | 44 | [ -d "$1" ] && usage && exit 1 |
| 45 | 45 | ||
| 46 | tmpfile="$(mktemp)" | 46 | tmpfile="$(mktemp)" |
| 47 | 47 | ||
| @@ -59,6 +59,17 @@ edit() { | |||
| 59 | $ANGOU_ENCRYPT "$tmpfile" >"$1" | 59 | $ANGOU_ENCRYPT "$tmpfile" >"$1" |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | totp_view() { | ||
| 63 | [ -d "$1" ] && usage && exit 1 | ||
| 64 | |||
| 65 | secret=$(view "$1" | grep TOTP | cut -d' ' -f 2) | ||
| 66 | oathtool -b --totp "$secret" | ||
| 67 | } | ||
| 68 | |||
| 69 | totp() { | ||
| 70 | totp_view "$1" | tr -d '\n' | $ANGOU_CLIPBOARD | ||
| 71 | } | ||
| 72 | |||
| 62 | # print usage | 73 | # print usage |
| 63 | usage() { | 74 | usage() { |
| 64 | printf "Usage: %s [help|copy|edit|generate|view|view_single [file or directory]]\n" "$0" | 75 | printf "Usage: %s [help|copy|edit|generate|view|view_single [file or directory]]\n" "$0" |
| @@ -79,5 +90,7 @@ case "$option" in | |||
| 79 | generate) edit "$2" generate ;; | 90 | generate) edit "$2" generate ;; |
| 80 | view) view "$2" ;; | 91 | view) view "$2" ;; |
| 81 | pass) view_single "$2" ;; | 92 | pass) view_single "$2" ;; |
| 93 | totp_view) totp_view "$2" ;; | ||
| 94 | totp) totp "$2" ;; | ||
| 82 | *) view "$1" ;; | 95 | *) view "$1" ;; |
| 83 | esac | 96 | esac |
diff --git a/contrib/autocomplete.zsh b/contrib/autocomplete.zsh index 776a9c7..eaafb8c 100644 --- a/contrib/autocomplete.zsh +++ b/contrib/autocomplete.zsh | |||
| @@ -6,5 +6,5 @@ passwords() { | |||
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | _arguments \ | 8 | _arguments \ |
| 9 | '1:angou commands:(copy edit generate help pass view)' \ | 9 | '1:angou commands:(copy edit generate help pass view totp totp_view)' \ |
| 10 | '2:passwords:passwords' | 10 | '2:passwords:passwords' |
