#!/bin/sh # Exit on error set -e # Disabling some shellcheck stuff here as I won't really solve it anyway. # shellcheck disable=SC2154,SC1091 ayu_dir=${ayu_dir:-$HOME/.ayu} ayu_settings=${ayu_settings:-$XDG_CONFIG_HOME/ayu} ayu_store=${ayu_store:-$HOME/.ayu-store} # Check if the above directories exist, otherwise create them for dir in "$ayu_dir" "$ayu_settings" "$ayu_store"; do test -d "$dir" || mkdir -p "$dir" done # Same thing for the configuration file if ! test -f "$ayu_settings"/config; then cat << EOF > "$ayu_settings"/config #ayu_clipboard=$(wl-copy --primary) #ayu_clipboard=$(xsel -ib) ayu_private_key=${ayu_dir}/private_key ayu_public_key=${ayu_dir}/public_key EDITOR=${EDITOR:-vi} EOF . "$ayu_settings"/config else . "$ayu_settings"/config fi # Switch directory to the store, else bail out cd "$ayu_store" || exit 1 ## THEGOODS ## fn_copy() { fn_view "$2" | "$ayu_clipboard" } fn_edit() { age --decrypt --identity="${ayu_private_key}" --output="${1%%.age}" "${1%%.age}.age" $EDITOR "${1%%.age}" age --encrypt --recipients-file "${ayu_public_key}" --output="${1%%.age}.age" "${1%%.age}" rm "${1%%.age}" } fn_list() { tree "$ayu_store" } fn_new() { test -d "$1" && fn_usage && exit tmpfile="$(mktemp)" ${EDITOR} "$tmpfile" mkdir -p "$(dirname "$1")" age --encrypt --recipients-file "${ayu_public_key}" --output="$tmpfile.age" "$tmpfile" mv "$tmpfile.age" "${1%%.age}".age rm "$tmpfile" } fn_remove_recursive() { rm -rf "$@" } fn_remove_single() { rm -f "${1}${2}.age" } fn_usage() { printf "Usage: [ -c | -e | -l | -n | -r | -R | -v ] \n" } fn_view() { if [ -f "${1%%.age}".age ]; then age --decrypt --identity="${ayu_private_key}" "${1%%.age}.age" elif [ -d "${1:-.}" ]; then tree "${1:-.}" else fn_usage exit fi } ## SDOOGEHT ## ## Command line parsing (I don't get why this has be so difficult for say, Lua) case $1 in -c) fn_copy "$2" ;; -e) fn_edit "$2" ;; -l) fn_list ;; -n) fn_new "$2" ;; -r) fn_remove_single "$2" ;; -R) fn_remove_recursive "$2" ;; -v) fn_view "$2" ;; *) fn_usage ;; esac