vns_mv now commits after renaming a note; code cleanup
This commit is contained in:
51
vns
51
vns
@@ -20,6 +20,10 @@ vns_raise (){
|
||||
|
||||
vns_report () {
|
||||
|
||||
# report (message)
|
||||
# Prints message to the console, formatted with a blue asterisk to indicate
|
||||
# some successful operation has completed
|
||||
|
||||
local -r VNS_BLUE_COLOR='\033[0;34m'
|
||||
local -r VNS_RESET_COLOR='\033[0m'
|
||||
|
||||
@@ -30,9 +34,10 @@ vns_checkDeps (){
|
||||
|
||||
# checkDeps
|
||||
# Prints a list of missing dependencies
|
||||
# Currently these dependencies are {vim, tree, git}
|
||||
|
||||
for DEP in 'vim' 'tree' 'git'; do
|
||||
if test ! -e "$(command -v "$DEP" 2>/dev/null)"; then
|
||||
if ! command -v "$DEP" >/dev/null 2>&1; then
|
||||
printf "%s " "$DEP"
|
||||
fi
|
||||
done
|
||||
@@ -51,12 +56,15 @@ vns_sanityCheck () {
|
||||
# Inform the user of missing dependencies and exit on code 20 if any were found
|
||||
if [ -n "$MISSING" ]; then
|
||||
vns_raise "Missing Dependencies: $MISSING" 20
|
||||
fi
|
||||
|
||||
# --- Store ---
|
||||
# Verify that the note store has been initialized
|
||||
if [ ! -d "$VNS_STORE" ]; then
|
||||
elif [ ! -d "$VNS_STORE" ]; then
|
||||
vns_raise "The vns store needs to be initialized (hint: -I)" 21
|
||||
|
||||
# Verify that intended GPG recipients are stored in compliance with v2.0
|
||||
elif [ ! -r "$VNS_STORE/.gpg-id" ]; then
|
||||
vns_raise "Re-initialize (-I) with gpg recipients. Existing notes will be re-encrypted" 21
|
||||
fi
|
||||
|
||||
}
|
||||
@@ -66,24 +74,30 @@ vns_init () {
|
||||
# init (GPG recipients...)
|
||||
# Prepares $VNS_STORE for use
|
||||
|
||||
# Verify that recipients were specified
|
||||
if [ "$#" -lt 1 ]; then
|
||||
vns_raise "No GPG Recipients Specified" 3
|
||||
|
||||
# Re-encrypt existing notes, if present
|
||||
elif [ -d "$VNS_STORE/.git" ]; then
|
||||
|
||||
# Reset list of GPG recipients
|
||||
echo -n '' > "${VNS_STORE}/.gpg-id"
|
||||
|
||||
vns_reencrypt "$VNS_STORE" "$@"
|
||||
vns_reencrypt "$@"
|
||||
|
||||
# No existing store found; initialize a new one
|
||||
else
|
||||
|
||||
# Create a new VNS Store
|
||||
git init "$VNS_STORE" >/dev/null
|
||||
vns_report "Initialized new VNS store"
|
||||
|
||||
fi
|
||||
|
||||
# Store GPG Recipients for later note creation
|
||||
# whether re-encrypting, or initializing a new store
|
||||
# Store GPG Recipients for later note creation whether re-encrypting, or
|
||||
# initializing a new store
|
||||
|
||||
for recipient in "$@"; do
|
||||
echo "$recipient" >> "${VNS_STORE}/.gpg-id"
|
||||
done
|
||||
@@ -93,9 +107,7 @@ vns_init () {
|
||||
|
||||
vns_reencrypt () {
|
||||
# reencrypt (GPG recipients...)
|
||||
|
||||
# Remove script name from arguments list
|
||||
shift
|
||||
# Re-encrypt all notes with provided gpg recipients.
|
||||
|
||||
# Construct list of arguments from provided recipients
|
||||
local -a GPG_RECIPS;
|
||||
@@ -116,13 +128,14 @@ vns_reencrypt () {
|
||||
vns_gpgid () {
|
||||
|
||||
# gpgid
|
||||
# Echo all recipients listed in .gpg-id
|
||||
# Print a list of all recipients listed in .gpg-id
|
||||
|
||||
# shellcheck disable=SC2002
|
||||
cat "${VNS_STORE}/.gpg-id" | while read -r recipient; do
|
||||
echo "-r"
|
||||
echo "$recipient"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
vns_printHelp (){
|
||||
@@ -153,9 +166,7 @@ vns_list () {
|
||||
|
||||
# list (notebook)
|
||||
# Prints a tree containing all notes in the notebook
|
||||
# If no notebook is specified, the entire store is used
|
||||
|
||||
#numNotes () { find "${VNS_STORE}" -name "*.gpg" \( ! -regex '.*/\..*' \) | wc -l; }
|
||||
# If no notebook is specified, all notes are shown
|
||||
|
||||
# Check for default behavior
|
||||
if [ "$#" -lt 1 ]; then
|
||||
@@ -177,9 +188,12 @@ vns_rm () {
|
||||
# rm (note)
|
||||
# removes (note) from the store
|
||||
|
||||
# Verify notes were provided
|
||||
if [ "$#" -lt 1 ]; then
|
||||
vns_raise "Insufficient arguments" 30
|
||||
fi
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
# Verify $1 is bound
|
||||
if [ "$#" -lt 1 ]; then vns_raise "Insufficient arguments" 30; fi
|
||||
|
||||
# Verify the note exists
|
||||
if [ ! -r "$VNS_STORE/$1.gpg" ]; then
|
||||
@@ -330,7 +344,12 @@ vns_mv () {
|
||||
# Refuse to overwrite existing notes
|
||||
if [ -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Note $2 already exists" 72; fi
|
||||
|
||||
# Create any necessary directories
|
||||
mkdir -p "$VNS_STORE/$(dirname "$2.gpg")"
|
||||
|
||||
# Rename the note
|
||||
vns_git mv "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg"
|
||||
vns_git commit -am "Renamed $1 -> $2"
|
||||
|
||||
}
|
||||
|
||||
@@ -410,7 +429,6 @@ vns_git () {
|
||||
}
|
||||
|
||||
vns () {
|
||||
|
||||
# Bypass sanity check if told to initialize store
|
||||
if [ "$1" != "-I" ]; then
|
||||
vns_sanityCheck;
|
||||
@@ -471,5 +489,4 @@ vns () {
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
vns "$@"
|
||||
|
||||
Reference in New Issue
Block a user