Browse Source

merge view and list commands into one like pass(1) does

Also added some checks for arguments into view, copy, and edit
commands, and usage is printed if the checks fail.
master
Shokara 6 months ago
parent
commit
44278549ad
Signed by: shokara GPG Key ID: 7F5702DEF8E6DC82
  1. 41
      angou

41
angou

@ -4,31 +4,39 @@
ANGOU_DIR=${ANGOU_DIR:-"$HOME/.angou/"}
# sets the command to copy into your clipboard (must accept stdin)
ANGOU_CLIPBOARD=${ANGOU_CLIPBOARD:-"xsel -ib"}
# sets command to use when listing directory structure
ANGOU_LIST=${ANGOU_LIST:-"tree"}
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
# decrypt and print a password from ANGOU_DIR or print the directory structure
view() {
gpg -qd "${1%%.gpg}".gpg
if [ -f "${1%%.gpg}" ]; then
gpg -qd "${1%%.gpg}".gpg
elif [ -d "${1:-.}" ]; then
tree "${1:-.}"
else
usage
exit
fi
}
# copy the first line from view to clipboard
copy() {
[ ! -f "$1" ] && usage && exit
view "$1" | sed 1q | $ANGOU_CLIPBOARD
}
# create new or existing password in ANGOU_DIR
edit() {
[ -d "$1" ] && usage && exit
tmpfile="$(mktemp)"
# edit a copy of a password if it already exists
test [ -f "${1**.gpg}".gpg] && cp "$1" "$tmpfile"
[ -f "${1%%.gpg}".gpg ] && cp "$1" "$tmpfile"
"${VISUAL:-${EDITOR:-ed}}" "$tmpfile"
@ -38,22 +46,21 @@ edit() {
# 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 "Usage: %s [help|copy|edit|view [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 list command is the default option if only a file or\n"
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 "$0" ;;
view) view "$2" ;;
help) usage ;;
copy) copy "$2" ;;
edit) edit "$2" ;;
list) shift && list "$@" ;; # fallthrough isn't in posix sh?
*) list "$@" ;;
view) view "$2" ;;
*) view "$1" ;;
esac
Loading…
Cancel
Save