Files
vns/sns.sh
2016-12-27 14:54:06 -06:00

67 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
XL_PRODUCT="Simple Note System"
XL_VER="v2a"
#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"
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"
if [ -d "$SNS_STORE" ] && [ "$1" != "-i" ]; then
printf "%s\n" "Please run \`sns -i\` to initialize sns."
exit
fi
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