Minor Reworking; changed version number
This commit is contained in:
81
vns.sh
81
vns.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
XL_PRODUCT="Vim Note System"
|
XL_PRODUCT="Vim Note System"
|
||||||
XL_VER="v2b"
|
XL_VER="1.0a2"
|
||||||
|
|
||||||
# Environment Constants
|
# Environment Constants
|
||||||
readonly VNS_STORE="$HOME/.local/vns"
|
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
|
readonly VNS_ERR_NO_git=3 # Git is not installed
|
||||||
|
|
||||||
# Global Variables
|
# Global Variables
|
||||||
typeset -i VNS_SID="$RANDOM"
|
|
||||||
typeset -a VNS_ACTION=("")
|
typeset -a VNS_ACTION=("")
|
||||||
typeset -a MISSING_DEPS
|
typeset -a MISSING_DEPS
|
||||||
typeset -i VNS_EXIT=0
|
typeset -i VNS_EXIT=0
|
||||||
declare VNS_PUBKEY=
|
declare VNS_PUBKEY=
|
||||||
# Function Definitions
|
# Function Definitions
|
||||||
|
# vns_index Print the $1th index of array ${2[@]} (friendly to -euo)
|
||||||
# vns_printError Prints an error message
|
# vns_printError Prints an error message
|
||||||
# vns_NoteHeader Prints standard note header to stdout
|
# vns_NoteHeader Prints standard note header to stdout
|
||||||
# vns_checkDeps Checks the system for required dependencies
|
# vns_checkDeps Checks the system for required dependencies
|
||||||
@@ -47,6 +47,9 @@ declare VNS_PUBKEY=
|
|||||||
# vns_rm Deletes note from store ( -d)
|
# vns_rm Deletes note from store ( -d)
|
||||||
# vns_gitPassthrough Passes through all instructions to git (git)
|
# vns_gitPassthrough Passes through all instructions to git (git)
|
||||||
|
|
||||||
|
function vns_index(){
|
||||||
|
echo "$@" | awk -v index="$(($1+1))" '{print $index}'
|
||||||
|
}
|
||||||
function vns_printError(){
|
function vns_printError(){
|
||||||
printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\n" "$@"
|
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
|
if [ -d "$VNS_STORE" ]; then true; else false; fi
|
||||||
}
|
}
|
||||||
function vns_sanityCheck {
|
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
|
if ! vns_checkDeps; then
|
||||||
VNS_EXIT="$VNS_ERR_DEPS"
|
VNS_EXIT="$VNS_ERR_DEPS"
|
||||||
for DEP in "${MISSING_DEPS[@]}"; do
|
for DEP in "${MISSING_DEPS[@]}"; do
|
||||||
@@ -87,7 +82,7 @@ function vns_sanityCheck {
|
|||||||
if [ -r "$VNS_STORE/.pubkey" ]; then
|
if [ -r "$VNS_STORE/.pubkey" ]; then
|
||||||
VNS_PUBKEY="$(cat "$VNS_STORE/.pubkey")"
|
VNS_PUBKEY="$(cat "$VNS_STORE/.pubkey")"
|
||||||
elif ! vns_checkStore; then
|
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."
|
vns_printError "The vns store does not exist."
|
||||||
printf " - %s\n" "Please run \`vns -i [gpg-key]\` to initialize vns."
|
printf " - %s\n" "Please run \`vns -i [gpg-key]\` to initialize vns."
|
||||||
VNS_EXIT="$VNS_ERR_NO_STORE"
|
VNS_EXIT="$VNS_ERR_NO_STORE"
|
||||||
@@ -101,11 +96,11 @@ function vns_initStore {
|
|||||||
}
|
}
|
||||||
function vns_printHelp(){
|
function vns_printHelp(){
|
||||||
printf "%s" "usage: vns [-cedlp] <notebook/section/name>"
|
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%s%s" "usage: vns " "git" " ..."
|
||||||
printf "\n%s" " vns [-hi]"
|
|
||||||
|
|
||||||
printf "\n%s" " -c | --create : Create note"
|
printf "\n%s" " -c | --create : Create note"
|
||||||
printf "\n%s" " -C | --config : Edit Config"
|
|
||||||
printf "\n%s" " -d | --delete : Delete note"
|
printf "\n%s" " -d | --delete : Delete note"
|
||||||
printf "\n%s" " -e | --edit : Open note for editing"
|
printf "\n%s" " -e | --edit : Open note for editing"
|
||||||
printf "\n%s" " -h | --help : Display this message"
|
printf "\n%s" " -h | --help : Display this message"
|
||||||
@@ -115,17 +110,38 @@ function vns_printHelp(){
|
|||||||
printf "\n\n"
|
printf "\n\n"
|
||||||
}
|
}
|
||||||
function vns_list(){
|
function vns_list(){
|
||||||
# Change directories to fix tree header
|
|
||||||
cd "$VNS_STORE" || exit; cd .. || exit;
|
|
||||||
# Print the tree
|
# 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(){
|
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"
|
echo "Deleting $VNS_NOTE"
|
||||||
rm -f "$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(){
|
function vns_gitPassthrough(){
|
||||||
cd "$VNS_STORE" || exit;
|
cd "$VNS_STORE" || exit;
|
||||||
git "$@";
|
git "$@";
|
||||||
@@ -164,13 +180,13 @@ function vns_argParse(){
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ "${#VNS_ACTION[@]}" -eq 0 ]; then
|
if [ "${#VNS_ACTION[@]}" -eq 0 ]; then
|
||||||
if [ "$(echo "$@" | awk '{print $1}')" == "git" ]; then
|
if [ "$(vns_index "1" "$@")" == "git" ]; then
|
||||||
VNS_ACTION=($@)
|
VNS_ACTION=($@)
|
||||||
else
|
else
|
||||||
if [ -d "$VNS_STORE/$*" ]; then
|
if [ -d "$VNS_STORE/$*" ]; then
|
||||||
VNS_ACTION=("vns_list" "vns/$@")
|
VNS_ACTION=("vns_list" "$@")
|
||||||
else
|
else
|
||||||
VNS_ACTION=("vns_list" "vns")
|
VNS_ACTION=("vns_list" "")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -179,33 +195,12 @@ function vns_argParse(){
|
|||||||
# Entry Point
|
# Entry Point
|
||||||
printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER"
|
printf "%s\n%s\n" "$XL_PRODUCT" "$XL_VER"
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
cd "$VNS_STORE" || exit;
|
||||||
|
|
||||||
readonly VNS_EDITOR="vim"
|
readonly VNS_EDITOR="vim"
|
||||||
readonly VNS_DEPS=("vim" "gpg2" "tree" "git")
|
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}')"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user