diff options
| author | Shokara Kou <kou@13f0.net> | 2022-09-07 18:16:32 -0400 |
|---|---|---|
| committer | Shokara Kou <kou@13f0.net> | 2022-09-07 18:16:32 -0400 |
| commit | 46924111a8fb9e7a51bb3cb50f306b2334f46f24 (patch) | |
| tree | 72f3a27afcdd75043c8b5a4be8c11ba550d79c7b | |
| parent | 07c0204d9a9e1cabca3b5a7140e976e5c0ee810f (diff) | |
add angou-age after 5 months of not being committed
I have no idea how I forgot to commit this after writing it
at the end of April.
| -rwxr-xr-x | angou-age | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/angou-age b/angou-age new file mode 100755 index 0000000..845670b --- /dev/null +++ b/angou-age | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # sets the directory with all your passwords | ||
| 4 | ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} | ||
| 5 | # sets the command to copy into your clipboard (must accept stdin) | ||
| 6 | ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"} | ||
| 7 | # sets command to use when listing directory structure | ||
| 8 | ANGOU_LIST=${ANGOU_LIST:-"tree"} | ||
| 9 | |||
| 10 | mkdir -p "$ANGOU_DIR" | ||
| 11 | cd "$ANGOU_DIR" || exit | ||
| 12 | |||
| 13 | # decrypt and print a password from ANGOU_DIR or print the directory structure | ||
| 14 | view() { | ||
| 15 | if [ -f "$1" ]; then | ||
| 16 | $ANGOU_DECRYPT "$1" | ||
| 17 | elif [ -d "${1:-.}" ]; then | ||
| 18 | tree "${1:-.}" | ||
| 19 | else | ||
| 20 | usage | ||
| 21 | exit | ||
| 22 | fi | ||
| 23 | } | ||
| 24 | |||
| 25 | # copy the first line from view to clipboard | ||
| 26 | copy() { | ||
| 27 | [ ! -f $1 ] && usage && exit | ||
| 28 | |||
| 29 | view "$1" | sed 1q | $ANGOU_CLIPBOARD | ||
| 30 | } | ||
| 31 | |||
| 32 | # create new or existing password in ANGOU_DIR | ||
| 33 | edit() { | ||
| 34 | [ -d "$1" ] && usage && exit | ||
| 35 | |||
| 36 | tmpfile="$(mktemp)" | ||
| 37 | |||
| 38 | # edit a copy of a password if it already exists | ||
| 39 | [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" | ||
| 40 | |||
| 41 | "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" | ||
| 42 | |||
| 43 | mkdir -p "$(dirname "$1")" | ||
| 44 | $ANGOU_ENCRYPT "$tmpfile" >"$1" | ||
| 45 | } | ||
| 46 | |||
| 47 | # print usage | ||
| 48 | usage() { | ||
| 49 | printf "Usage: %s [help|copy|edit|view [file or directory]]\n" "$0" | ||
| 50 | printf "\tThe edit and copy command expects a file as an argument,\n" | ||
| 51 | printf "\twhile the view command expects a directory as an argument.\n" | ||
| 52 | printf "\tThe arguments for view and edit are relative to\n" | ||
| 53 | printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" | ||
| 54 | |||
| 55 | printf "\tThe view command is the default command if only a file or\n" | ||
| 56 | printf "\tdirectory is passed as an argument\n" | ||
| 57 | } | ||
| 58 | |||
| 59 | option="$1" | ||
| 60 | case "$option" in | ||
| 61 | help) usage ;; | ||
| 62 | copy) copy "$2" ;; | ||
| 63 | edit) edit "$2" ;; | ||
| 64 | view) view "$2" ;; | ||
| 65 | *) view "$1" ;; | ||
| 66 | esac | ||
