From 46924111a8fb9e7a51bb3cb50f306b2334f46f24 Mon Sep 17 00:00:00 2001 From: Shokara Kou Date: Wed, 7 Sep 2022 18:16:32 -0400 Subject: 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. --- angou-age | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 angou-age diff --git a/angou-age b/angou-age new file mode 100755 index 0000000..845670b --- /dev/null +++ b/angou-age @@ -0,0 +1,66 @@ +#!/bin/sh + +# sets the directory with all your passwords +ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"} +# sets the command to copy into your clipboard (must accept stdin) +ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"} +# sets command to use when listing directory structure +ANGOU_LIST=${ANGOU_LIST:-"tree"} + +mkdir -p "$ANGOU_DIR" +cd "$ANGOU_DIR" || exit + +# decrypt and print a password from ANGOU_DIR or print the directory structure +view() { + if [ -f "$1" ]; then + $ANGOU_DECRYPT "$1" + elif [ -d "${1:-.}" ]; then + tree "${1:-.}" + else + usage + exit + fi +} + +# copy the first line from view to clipboard +copy() { + [ ! -f $1 ] && usage && exit + + view "$1" | sed 1q | $ANGOU_CLIPBOARD +} + +# create new or existing password in ANGOU_DIR +edit() { + [ -d "$1" ] && usage && exit + + tmpfile="$(mktemp)" + + # edit a copy of a password if it already exists + [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" + + "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" + + mkdir -p "$(dirname "$1")" + $ANGOU_ENCRYPT "$tmpfile" >"$1" +} + +# print usage +usage() { + printf "Usage: %s [help|copy|edit|view [file or directory]]\n" "$0" + printf "\tThe edit and copy command expects a file as an argument,\n" + printf "\twhile the view command expects a directory as an argument.\n" + printf "\tThe arguments for view and edit are relative to\n" + printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" + + printf "\tThe view command is the default command if only a file or\n" + printf "\tdirectory is passed as an argument\n" +} + +option="$1" +case "$option" in + help) usage ;; + copy) copy "$2" ;; + edit) edit "$2" ;; + view) view "$2" ;; + *) view "$1" ;; +esac -- cgit v1.2.3