summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xangou-age66
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
4ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"}
5# sets the command to copy into your clipboard (must accept stdin)
6ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -i"}
7# sets command to use when listing directory structure
8ANGOU_LIST=${ANGOU_LIST:-"tree"}
9
10mkdir -p "$ANGOU_DIR"
11cd "$ANGOU_DIR" || exit
12
13# decrypt and print a password from ANGOU_DIR or print the directory structure
14view() {
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
26copy() {
27 [ ! -f $1 ] && usage && exit
28
29 view "$1" | sed 1q | $ANGOU_CLIPBOARD
30}
31
32# create new or existing password in ANGOU_DIR
33edit() {
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
48usage() {
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
59option="$1"
60case "$option" in
61 help) usage ;;
62 copy) copy "$2" ;;
63 edit) edit "$2" ;;
64 view) view "$2" ;;
65 *) view "$1" ;;
66esac