#!/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 -ib"} mkdir -p "$ANGOU_DIR" cd "$ANGOU_DIR" || exit # print the directory structure of ANGOU_DIR list() { tree "$@" } # decrypt and print a password from ANGOU_DIR view() { gpg -qd "${1%%.gpg}".gpg } # copy the first line from view to clipboard copy() { view "$1" | "$ANGOU_CLIPBOARD" } # create new or existing password in ANGOU_DIR edit() { tmpfile="$(mktemp)" # edit a copy of a password if it already exists test [ -f "${1**.gpg}".gpg] && cp "$1" "$tmpfile" "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" mkdir -p "$(dirname "$1")" mv "$tmpfile" "${1%%.gpg}".gpg } # print usage usage() { printf "Usage: %s [help|view|copy|edit|list [file or directory]]\n" "$1" printf "\tThe view and edit commands expect a file as an argument,\n" printf "\twhile the list commands expect a directory as an argument.\n" printf "\tThe arguments for view, edit, and list are relative to\n" printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" printf "\tThe list command is the default option if only a file or\n" printf "\tdirectory is passed as an argument\n" } option="$1" case "$option" in help) usage "$0" ;; view) view "$2" ;; copy) copy "$2" ;; edit) edit "$2" ;; list) shift && list "$@" ;; # fallthrough isn't in posix sh? *) list "$@" ;; esac