about summary refs log tree commit diff stats
path: root/ayu
diff options
context:
space:
mode:
authorNova li Gensokyo <novaburst@kalli.st>2021-12-05 14:46:17 +0000
committerNova li Gensokyo <novaburst@kalli.st>2021-12-05 14:46:17 +0000
commit5079a58c5b348aa26af06951d0b31cc25de9f843 (patch)
tree5ed4a34dbce3800f9f0d753f1d4ea7e8c56740c3 /ayu
downloadayu-5079a58c5b348aa26af06951d0b31cc25de9f843.tar.gz
# * NOTE: Comments in this file WILL DEGRADE PERFORMANCE. *
Diffstat (limited to 'ayu')
-rwxr-xr-xayu72
1 files changed, 72 insertions, 0 deletions
diff --git a/ayu b/ayu
new file mode 100755
index 0000000..4848531
--- /dev/null
+++ b/ayu
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+# Path to the program's directory
+ayu_dir="$HOME/.config/ayu"
+
+# Path to the age(1) keys
+ayu_key="$ayu_dir/age.key"
+ayu_pub="$ayu_dir/age.pub"
+
+# Path to the password store
+ayu_store="$HOME/.ayu"
+
+test -d $ayu_dir || mkdir -p $ayu_dir
+test -d $ayu_store || mkdir -p $ayu_store
+
+
+if ! [ -f $ayu_key ];then
+	printf "First generate your own age(1) key with age-keygen(1) and place it as $ayu_key. \n"
+	exit 1
+fi
+
+cd $ayu_store
+
+list() {
+	tree $ayu_store
+}
+
+edit() {
+	test -d "$1" && usage && exit
+
+	tmpfile="$(mktemp)"
+
+	# if the password already exists, decrypt and edit it instead
+	test -f "${1%%.age}".age && age --decrypt --identity=$age_pub "${1%%.age}".age > $tmpfile
+
+	vi "$tmpfile"
+
+	mkdir -p "$(dirname "$1")"
+	age --encrypt -R $ayu_pub -o $tmpfile.age $tmpfile
+
+	mv $tmpfile.age "${1%%.age}".age
+	rm $tmpfile
+}
+
+usage() {
+	printf "$0 [ edit | list | new | view ] \n"
+}
+
+view() {
+	if [ -f "${1%%.age}".age ];then
+		age --decrypt --identity=$ayu_key .age
+	elif [ -d "${1:-.}" ];then
+		tree "${1:-.}"
+	else
+		usage
+		exit
+	fi
+}
+case $1 in
+	list)
+		list
+		;;
+	edit | new)
+		edit $2
+		;;
+	view)
+		view $2
+		;;
+	*)
+		list
+		;;
+esac