Minor Reworking; changed version number

This commit is contained in:
Jon-William Lewis
2017-08-24 20:49:36 -05:00
parent 25655916c5
commit 3c49352b60

81
vns.sh
View File

@@ -1,6 +1,6 @@
#!/bin/bash
XL_PRODUCT="Vim Note System"
XL_VER="v2b"
XL_VER="1.0a2"
# Environment Constants
readonly VNS_STORE="$HOME/.local/vns"
@@ -26,12 +26,12 @@ readonly VNS_RESET_COLOR='\033[0m'
readonly VNS_ERR_NO_git=3 # Git is not installed
# Global Variables
typeset -i VNS_SID="$RANDOM"
typeset -a VNS_ACTION=("")
typeset -a MISSING_DEPS
typeset -i VNS_EXIT=0
declare VNS_PUBKEY=
# Function Definitions
# vns_index Print the $1th index of array ${2[@]} (friendly to -euo)
# vns_printError Prints an error message
# vns_NoteHeader Prints standard note header to stdout
# vns_checkDeps Checks the system for required dependencies
@@ -47,6 +47,9 @@ declare VNS_PUBKEY=
# vns_rm Deletes note from store ( -d)
# vns_gitPassthrough Passes through all instructions to git (git)
function vns_index(){
echo "$@" | awk -v index="$(($1+1))" '{print $index}'
}
function vns_printError(){
printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\n" "$@"
}
@@ -67,14 +70,6 @@ function vns_checkStore(){
if [ -d "$VNS_STORE" ]; then true; else false; fi
}
function vns_sanityCheck {
set +u
if [ "$VNS_EDITOR" != "vim" ] && [ -z "$EDITOR" ]; then
echo "$VNS_EDITOR"
vns_printError "No editor specified in environment."
VNS_EXIT="$VNS_ERR_NO_EDTR"
return
fi
set -u
if ! vns_checkDeps; then
VNS_EXIT="$VNS_ERR_DEPS"
for DEP in "${MISSING_DEPS[@]}"; do
@@ -87,7 +82,7 @@ function vns_sanityCheck {
if [ -r "$VNS_STORE/.pubkey" ]; then
VNS_PUBKEY="$(cat "$VNS_STORE/.pubkey")"
elif ! vns_checkStore; then
if [ "$(echo "${VNS_ACTION[@]}" | awk '{print $1;}')" != "vns_initStore" ]; then
if [ "$(vns_index "1" "${VNS_ACTION[@]}")" != "vns_initStore" ]; then
vns_printError "The vns store does not exist."
printf " - %s\n" "Please run \`vns -i [gpg-key]\` to initialize vns."
VNS_EXIT="$VNS_ERR_NO_STORE"
@@ -101,11 +96,11 @@ function vns_initStore {
}
function vns_printHelp(){
printf "%s" "usage: vns [-cedlp] <notebook/section/name>"
printf "\n%s" " vns -i <gnupg recipient>"
printf "\n%s" " vns -h"
printf "\n%s%s%s" "usage: vns " "git" " ..."
printf "\n%s" " vns [-hi]"
printf "\n%s" " -c | --create : Create note"
printf "\n%s" " -C | --config : Edit Config"
printf "\n%s" " -d | --delete : Delete note"
printf "\n%s" " -e | --edit : Open note for editing"
printf "\n%s" " -h | --help : Display this message"
@@ -115,17 +110,38 @@ function vns_printHelp(){
printf "\n\n"
}
function vns_list(){
# Change directories to fix tree header
cd "$VNS_STORE" || exit; cd .. || exit;
# Print the tree
tree -C --noreport --prune "$(echo "$@" | awk '{print $1}')"
tree -C --noreport --prune "$VNS_STORE/$(vns_index "1" "$@")" | tail -n +2 | sed s/\.gpg//g
}
function vns_rm(){
local readonly VNS_NOTE="$VNS_STORE/$(echo "$@" | awk '{print $1}').gpg"
local readonly VNS_NOTE; VNS_NOTE="$VNS_STORE/$(vns_index "1" "$@").gpg"
echo "Deleting $VNS_NOTE"
rm -f "$VNS_NOTE"
}
function vns_create(){
local readonly VNS_NOTE; VNS_NOTE="$VNS_STORE/$(vns_index "1" "$@").gpg"
# Make sure the note doesn't already exist
if [ -r "$VNS_NOTE" ]; then
vns_printError "Note already exists."
else
if [ ! -d "$(dirname "$VNS_NOTE")" ]; then
mkdir -p "$(dirname "$VNS_NOTE")"
fi
vns_NoteHeader | gpg2 -e -r "$VNS_PUBKEY" -o "$VNS_NOTE"
vns_edit "$@"
fi
}
function vns_edit(){
# Make the function more readable
local readonly VNS_NOTE; VNS_NOTE="$VNS_STORE/$(vns_index "1" "$@").gpg"
# Edit the note
vim "$VNS_NOTE"
}
function vns_print(){
gpg2 -d "$VNS_STORE/$(vns_index "1" "$@").gpg"
}
function vns_gitPassthrough(){
cd "$VNS_STORE" || exit;
git "$@";
@@ -164,13 +180,13 @@ function vns_argParse(){
done
if [ "${#VNS_ACTION[@]}" -eq 0 ]; then
if [ "$(echo "$@" | awk '{print $1}')" == "git" ]; then
if [ "$(vns_index "1" "$@")" == "git" ]; then
VNS_ACTION=($@)
else
if [ -d "$VNS_STORE/$*" ]; then
VNS_ACTION=("vns_list" "vns/$@")
VNS_ACTION=("vns_list" "$@")
else
VNS_ACTION=("vns_list" "vns")
VNS_ACTION=("vns_list" "")
fi
fi
fi
@@ -179,33 +195,12 @@ function vns_argParse(){
# Entry Point
printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER"
printf "\n"
cd "$VNS_STORE" || exit;
readonly VNS_EDITOR="vim"
readonly VNS_DEPS=("vim" "gpg2" "tree" "git")
function vns_create(){
VNS_NOTE="$VNS_STORE/$(echo "$@" | awk '{print $1}').gpg"
# Make sure the note doesn't already exist
if [ -r "$VNS_NOTE" ]; then
vns_printError "Note already exists."
else
if [ ! -d "$(dirname $VNS_NOTE)" ]; then
mkdir -p "$(dirname $VNS_NOTE)"
fi
vns_NoteHeader | gpg2 -e -r "$VNS_PUBKEY" -o "$VNS_NOTE"
vns_edit "$@"
fi
}
function vns_edit(){
# Make the function more readable
local readonly VNS_NOTE="$VNS_STORE/$(echo "$@" | awk '{print $1}').gpg"
# Edit the note
vim "$VNS_NOTE"
}
function vns_print(){
gpg2 -d "$VNS_STORE/$(echo "$@" | awk '{print $1}')"
}