summary refs log tree commit diff stats
path: root/examples/rifle_different_file_opener.conf
Commit message (Expand)AuthorAgeFilesLines
* Should I dual ranger/cleric or wait for the THAC0 bonus? v1.7.0hut2015-04-141-1/+1
* moved "doc/examples" to "examples" for more visibilityhut2015-04-131-0/+9
* move examples to doc/exampleshut2013-03-091-9/+0
* Added version info to exampleshut2013-03-011-0/+2
* added examples/rifle_different_file_opener.confhut2012-12-041-0/+7
ref='#n93'>93 94 95 96 97 98 99
#!/bin/sh

# ayu(1) - an actually boring password manager, which uses age(1) as backend.

# Path to the program's directory
ayu_dir="${ayu_dir:-$HOME/.ayu}"

# Path to the password store
ayu_store="${ayu_store:-$HOME/.ayu-store}"

# Command to copy an entry's text into the clipboard (must accept standard input)
clipboard="xsel -ib"

# Path to the age(1) keys
private_key="${private_key:-${ayu_dir}/private_key}"
public_key="${public_key:-${ayu_dir}/public_key}"

# Default editor to be used
EDITOR=${EDITOR:-vi}

# Run some tests
test -d $ayu_dir || mkdir -p $ayu_dir
test -d $ayu_store || mkdir -p $ayu_store

test -f $private_key || printf "$0: Generate your own age(1) key with age-keygen(1) and place it as a $private_key. \n"
test -f $public_key || printf "$0: Public key needs to be placed on $public_key (Hint: it's the visible output of age-keygen(1)) \n"

# Switch directory to the password store, otherwise bail out.
cd $ayu_store || exit 1

# Copy an entry to the clipboard
copy() {
	view "$2" | sed 1q | $clipboard
}

# Edit an entry if it exists
edit() {
	age --decrypt --identity=$private_key --output=${1%%.age} ${1%%.age}.age
	${EDITOR} ${1%%.age}
	age --encrypt -R $public_key --output=${1%%.age}.age ${1%%.age}
	rm ${1%%.age}
}

# List contents of the store
list() {
	tree $ayu_store
}

# Create a new entry
new() {
	test -d "$1" && usage && exit

	tmpfile="$(mktemp)"
	${EDITOR} "$tmpfile"

	mkdir -p "$(dirname "$1")"
	age --encrypt -R $public_key -o $tmpfile.age $tmpfile

	mv $tmpfile.age "${1%%.age}".age
	rm $tmpfile
}

# Remove
remove() {
	rm -f ${1}${2}.age
}

# Remove recursively
remove_recursive() {
	rm -rf "$@"
}
# Print usage
usage() {
	printf "$0 [ -c | -e | -l | -n | -r | -R | -v ] <entry> \n"
}

# View an entry, otherwise list the contents of the directory specified.
view() {
	if [ -f "${1%%.age}".age ];then
		age --decrypt --identity=$private_key "${1%%.age}".age
	elif [ -d "${1:-.}" ];then
		tree "${1:-.}"
	else
		usage
		exit
	fi
}

case $1 in
	-c) copy $2 ;;
	-e) edit $2 ;;
	-l) list ;;
	-n) new $2 ;;
	-r) remove $2 $3 ;;
	-R) remove_recursive $2 ;;
	-h) usage ;;
	-v) view $2 ;;
	*) usage ;;
esac