blob: 606998f19de238f2c85ffa6ab0ff127749e0df1b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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 "${1%%.age}".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
|