diff --git a/sns.sh b/sns.sh new file mode 100755 index 0000000..1bbdf8c --- /dev/null +++ b/sns.sh @@ -0,0 +1,63 @@ +#!/bin/bash +XL_PRODUCT="Simple Note System" +XL_VER="v2.1" + +#Environment +SNS_STORE="$HOME/.local/sns" +SNS_KEYFILE="$SNS_STORE/.pubkey" +SNS_DEPS=("gpg" "tree" "git") + +declare -f sns_checkDeps # Checks the system for dependencies +declare -f sns_initStore # Initializes the SNS Store ( -i) +declare -f sns_printHelp # Prints help page ( -h) +declare -f sns_list # Lists all notes in `tree` format ( *) +declare -f sns_create # Creates note; calls sns_edit() ( -c) +declare -f sns_edit # Decrypts note to /tmp, calls editor, re-encrypts note ( -e) +declare -f sns_print # Prints note to stdout ( -p) +declare -f sns_rm # Deletes note from store ( -d) +declare -f sns_gitPassthrough # Passes through all instructions to git (git) + +function sns_checkDeps(){ + for DEP in "${SNS_DEPS[@]}"; do + if test ! -e "$(which gpg 2>/dev/null)"; then + echo "Dependency missing: $DEP" + fi + done +} +function sns_initStore(){ + mkdir -p "$SNS_STORE" + mkdir -p "$SNS_STORE/notes" + echo "$1" > "$SNS_KEYFILE" +} +function sns_printHelp(){ + printf "%s" "Import helpfile from sns v2" +} +function sns_list(){ + tree -C --noreport "$1" +} +function sns_create(){ + gpg -r "$SNS_PUBKEY" -o "$1" < /dev/null + sns_edit "$1" +} +function sns_print(){ + gpg -d "$1" +} +function sns_rm(){ + rm -f "$1" +} +function sns_gitPassthrough(){ + git "$@" +} +# Entry Point +printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER" +while getopts ":ihc:e:p:d:git:" OPT; do + case "$OPT" in + *) + if [ -d "$SNS_STORE/notes/$OPTARG" ]; then + sns_list "$SNS_STORE/notes/$OPTARG" + else + sns_list "$SNS_STORE/notes/*" + fi + ;; + esac +done