refactor(notes): clean up; wrap login in main function

This commit is contained in:
Ayo Ayco 2025-08-23 17:46:35 +02:00
parent 3f2f90b1c9
commit 5969c69bab

View file

@ -1,15 +1,9 @@
#! /usr/bin/bash #! /usr/bin/bash
## notes management
# Load config # Load config
. ${HOME}/ayo.conf . ${HOME}/ayo.conf
. ${scripts_dir}/functions.sh . ${scripts_dir}/functions.sh
# TODO: write log for echoes with >>>
command=$1
getopts "t" typora; #check if -t flag is given getopts "t" typora; #check if -t flag is given
function editFile() { function editFile() {
@ -55,18 +49,19 @@ function createNote() {
} }
} }
function main() {
## DIFF ## DIFF
if [ "$1" = "diff" ] || [ "$1" = "d" ]; then if [ "$1" = "diff" ] || [ "$1" = "d" ]; then
cd $notes_dir cd $notes_dir
git add . git add .
git diff --staged . git diff --staged .
## SYNC notes in directory ## SYNC notes in directory
elif [ "$1" = "sync" ] || [ "$1" = "s" ]; then elif [ "$1" = "sync" ] || [ "$1" = "s" ]; then
notesSync notesSync
## LIST notes in directory ## LIST notes in directory
elif [ "$1" = "list" ] || [ "$1" = "l" ]; then elif [ "$1" = "list" ] || [ "$1" = "l" ]; then
echo "ACTIVE NOTES: " echo "ACTIVE NOTES: "
notesSync notesSync
if ! [ "$2" = "" ]; then if ! [ "$2" = "" ]; then
@ -80,8 +75,8 @@ elif [ "$1" = "list" ] || [ "$1" = "l" ]; then
echo "$index) $file" echo "$index) $file"
done done
## OPEN a note from a list ## OPEN a note from a list
elif [ "$1" = "open" ] || [ "$1" = "o" ]; then elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
notesSync notesSync
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
@ -105,8 +100,8 @@ elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
done done
fi fi
## REMOVE a note from a list ## REMOVE a note from a list
elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
notesSync notesSync
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
@ -133,8 +128,8 @@ elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
done done
fi fi
## ARCHIVE a note from a list ## ARCHIVE a note from a list
elif [ "$1" = "archive" ] || [ "$1" = "a" ]; then elif [ "$1" = "archive" ] || [ "$1" = "a" ]; then
notesSync notesSync
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
@ -161,8 +156,8 @@ elif [ "$1" = "archive" ] || [ "$1" = "a" ]; then
done done
fi fi
## COPY content a note from a list ## COPY content a note from a list
elif [ "$1" = "copy" ] || [ "$1" = "c" ]; then elif [ "$1" = "copy" ] || [ "$1" = "c" ]; then
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
if ! [ "$2" = "" ]; then if ! [ "$2" = "" ]; then
@ -187,7 +182,11 @@ elif [ "$1" = "copy" ] || [ "$1" = "c" ]; then
fi fi
## CREATE a note (default) ## CREATE a note (default)
else else
createNote createNote
fi fi
}
main