Separated script into multiple files for easier management. Added Makefile
[bash-notes.git] / SOURCE / main.sh
diff --git a/SOURCE/main.sh b/SOURCE/main.sh
new file mode 100644 (file)
index 0000000..da3130a
--- /dev/null
@@ -0,0 +1,96 @@
+# shellcheck disable=SC2006
+GOPT=$(getopt -o hvpla::e::d::s:: --long help,version,list,plain,userconf,backup::,add::,edit::,delete::,show:: -n 'bash-notes' -- "$@")
+
+# shellcheck disable=SC2181
+if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
+
+# Note the quotes around `$GOPT': they are essential!
+eval set -- "$GOPT"
+unset GOPT
+
+while true; do
+       case "$1" in
+               -h | --help )
+                       helptext
+               exit
+               ;;
+               -v | --version )
+                       echo $BASENAME v${VERSION}
+                       exit
+                       ;;
+           -p | --plain )
+                       PLAIN=true
+                       shift
+               ;;
+           -l | --list )
+                       listnotes
+                       exit
+               ;;
+           -a | --add )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Title: " TITLE
+                                       ;;
+                               * )
+                                       TITLE=$2
+                                       ;;
+                       esac
+                       shift 2
+                       addnote "$TITLE"
+               ;;
+               -e | --edit )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Note ID: " NOTE
+                                       ;;
+                               * )
+                                       NOTE=$2
+                                       ;;
+                       esac
+                       shift 2
+                       editnote "$NOTE"
+                       ;;
+               -d | --delete )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Note ID: " NOTE
+                                       ;;
+                               * )
+                                       NOTE=$2
+                                       ;;
+                       esac
+                       shift 2
+                       rmnote "$NOTE"
+                       ;;
+               -s | --show )
+                       case "$2" in
+                               '' )
+                                       read -r -p "Note ID: " NOTE
+                                       ;;
+                               * )
+                                       NOTE=$2
+                                       ;;
+                       esac
+                       shift 2
+                       shownote "$NOTE"
+                       ;;
+               --userconf )
+                       export_config
+                       # shellcheck disable=SC2317
+                       echo "config exported to \"$RCFILE\""
+                       # shellcheck disable=SC2317
+                       exit
+                       ;;
+               -- )
+                       shift
+                       break
+                       ;;
+               * )
+                       break
+                       ;;
+       esac
+done
+
+if [ -z $1 ]; then
+       helptext
+fi