#!/bin/sh -e # 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 -i"} # sets command to use when listing directory structure ANGOU_LIST=${ANGOU_LIST:-"tree"} # custom command for generating passwords/users ANGOU_GEN_PASS=${ANGOU_GEN_PASS:-"random pass"} ANGOU_GEN_USER=${ANGOU_GEN_USER:-"random user"} mkdir -p "$ANGOU_DIR" cd "$ANGOU_DIR" # decrypt and print a password from ANGOU_DIR or print the directory structure view() { if [ -f "$1" ]; then $ANGOU_DECRYPT "$1" elif [ -d "${1:-.}" ]; then tree "${1:-.}" else usage exit 1 fi } # view the first line view_single() { [ ! -f "$1" ] && usage && exit 1 view "$1" | sed 1q | tr -d \\n } # copy the first line from view to clipboard copy() { [ ! -f "$1" ] && usage && exit 1 view_single "$1" | $ANGOU_CLIPBOARD } # create new or existing password in ANGOU_DIR edit() { [ -d "$1" ] && usage && exit 1 tmpfile="$(mktemp)" if [ "$2" = "generate" ]; then $ANGOU_GEN_PASS >"$tmpfile" echo "Username: $($ANGOU_GEN_USER)" >>"$tmpfile" fi # edit a copy of a password if it already exists [ -f "$1" ] && $ANGOU_DECRYPT "$1" > "$tmpfile" ${VISUAL:-${EDITOR:-ed}} "$tmpfile" mkdir -p "$(dirname "$1")" $ANGOU_ENCRYPT "$tmpfile" >"$1" } totp_view() { [ -d "$1" ] && usage && exit 1 secret=$(view "$1" | grep TOTP | cut -d' ' -f 2) oathtool -b --totp "$secret" } totp() { totp_view "$1" | tr -d '\n' | $ANGOU_CLIPBOARD } # print usage usage() { printf "Usage: %s [help|copy|edit|generate|view|view_single [file or directory]]\n" "$0" printf "\tThe edit and copy command expects a file as an argument,\n" printf "\twhile the view command expects a directory as an argument.\n" printf "\tThe arguments for view and edit are relative to\n" printf "\t\$ANGOU_DIR which is currently set to %s\n\n" "$ANGOU_DIR" printf "\tThe view command is the default command if only a file or\n" printf "\tdirectory is passed as an argument\n" } option="$1" case "$option" in help) usage ;; copy) copy "$2" ;; edit) edit "$2" ;; generate) edit "$2" generate ;; view) view "$2" ;; pass) view_single "$2" ;; totp_view) totp_view "$2" ;; totp) totp "$2" ;; *) view "$1" ;; esac