reimplemented title dialog when adding note if nothing is passed on the command line.
[bash-notes.git] / SOURCE / CORE / core-add.sh
index ed6256c..3404f71 100644 (file)
@@ -1,11 +1,27 @@
-function addnote() {
+addnote() {
+       # attempt syncing before adding a note
+       gitsync -f
        # remove eventually existing temp DB file
        if [[ -f $TMPDB ]]; then
                rm $TMPDB
        fi
 
+       # RANDOM TITLE
        RTITLE=$(random_title)
-       [[ -z "$1" ]] && NOTETITLE="$RTITLE" || NOTETITLE="$1"
+
+       if [[ -z $1 ]]; then
+               read -r -p "Title: " TITLE
+               case "$TITLE" in
+                       '' )
+                               NOTETITLE="$RTITLE"
+                               ;;
+                       * )
+                               NOTETITLE=$TITLE
+                               ;;
+               esac
+       fi
+
+       # [[ -z "$1" ]] && NOTETITLE="$RTITLE" || NOTETITLE="$1"
        echo "adding new note - \"$NOTETITLE\""
        # shellcheck disable=SC2086
        LASTID=$($JQ '.notes[-1].id // 0 | tonumber' $DB)
@@ -21,4 +37,6 @@ function addnote() {
        # alacritty --class notes --title notes -e /usr/bin/vim ...
        # shellcheck disable=SC2086,SC2091
        $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${NOW})
+       # add note to git and push to remote
+       gitadd
 }