From: danix Date: Tue, 18 Apr 2023 06:47:37 +0000 (+0200) Subject: added git functionality to edit and remove options. X-Git-Tag: v0.4~2 X-Git-Url: https://git.danix.xyz/?p=bash-notes.git;a=commitdiff_plain;h=d1f115c1bcef830147519b1c3e950828b5626cdc added git functionality to edit and remove options. --- diff --git a/SOURCE/CORE/core-edit.sh b/SOURCE/CORE/core-edit.sh index 20765f1..1fc4222 100644 --- a/SOURCE/CORE/core-edit.sh +++ b/SOURCE/CORE/core-edit.sh @@ -16,6 +16,7 @@ editnote() { echo "editing note $TITLE" # shellcheck disable=SC2086,SC2091 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${FILE}) + gitedit else echo "note not found" exit 1 diff --git a/SOURCE/CORE/core-remove.sh b/SOURCE/CORE/core-remove.sh index 7bbf8c4..24c7290 100644 --- a/SOURCE/CORE/core-remove.sh +++ b/SOURCE/CORE/core-remove.sh @@ -16,6 +16,7 @@ rmnote() { mv $TMPDB $DB # shellcheck disable=SC2086 rm $NOTESDIR/* + gitremove "all" echo "Deleted all notes" ;; * ) @@ -43,6 +44,7 @@ rmnote() { # shellcheck disable=SC2086 mv $TMPDB $DB rm $NOTESDIR/$FILE + gitremove $OK $FILE echo "Deleted note $TITLE" sleep 1 exit diff --git a/SOURCE/CORE/git.sh b/SOURCE/CORE/git.sh index bb51dc7..ff674df 100644 --- a/SOURCE/CORE/git.sh +++ b/SOURCE/CORE/git.sh @@ -62,6 +62,47 @@ gitadd() { fi } +# edited note added to git and pushed it to remote +gitedit() { + if [[ $USEGIT && -n $GITREMOTE ]]; then + [ $PLAIN == false ] && echo "Editing note on remote \"$GITREMOTE\"" + cd $BASEDIR + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} note edited." + $GIT push origin master + else + # no git, so we just keep going + true + fi +} + +# add note to git and push it to remote +gitremove() { + NOTE=$1 + FILE=$2 + if [[ $USEGIT && -n $GITREMOTE ]]; then + [ $PLAIN == false ] && echo "Deleting notes from remote \"$GITREMOTE\"" + if [ "all" == $NOTE ];then + echo "Deleting all notes" + cd $BASEDIR + $GIT rm notes/* + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing all notes." + $GIT push origin master + else + echo "Deleting note ID ${NOTE}" + local OK=$(check_noteID "$NOTE") + cd $BASEDIR + $GIT rm notes/${FILE} + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing note ID ${NOTE}." + $GIT push origin master + fi + else + # no git, so we just keep going + true + fi +} + # check for USEGIT and subsequent variables if [[ $USEGIT && -n $GITREMOTE ]]; then # GIT is a go. diff --git a/notes.sh b/notes.sh index adc3de7..687fefe 100755 --- a/notes.sh +++ b/notes.sh @@ -304,6 +304,47 @@ gitadd() { fi } +# edited note added to git and pushed it to remote +gitedit() { + if [[ $USEGIT && -n $GITREMOTE ]]; then + [ $PLAIN == false ] && echo "Editing note on remote \"$GITREMOTE\"" + cd $BASEDIR + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} note edited." + $GIT push origin master + else + # no git, so we just keep going + true + fi +} + +# add note to git and push it to remote +gitremove() { + NOTE=$1 + FILE=$2 + if [[ $USEGIT && -n $GITREMOTE ]]; then + [ $PLAIN == false ] && echo "Deleting notes from remote \"$GITREMOTE\"" + if [ "all" == $NOTE ];then + echo "Deleting all notes" + cd $BASEDIR + $GIT rm notes/* + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing all notes." + $GIT push origin master + else + echo "Deleting note ID ${NOTE}" + local OK=$(check_noteID "$NOTE") + cd $BASEDIR + $GIT rm notes/${FILE} + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing note ID ${NOTE}." + $GIT push origin master + fi + else + # no git, so we just keep going + true + fi +} + # check for USEGIT and subsequent variables if [[ $USEGIT && -n $GITREMOTE ]]; then # GIT is a go. @@ -456,6 +497,7 @@ editnote() { echo "editing note $TITLE" # shellcheck disable=SC2086,SC2091 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${FILE}) + gitedit else echo "note not found" exit 1 @@ -503,6 +545,7 @@ rmnote() { mv $TMPDB $DB # shellcheck disable=SC2086 rm $NOTESDIR/* + gitremove "all" echo "Deleted all notes" ;; * ) @@ -530,6 +573,7 @@ rmnote() { # shellcheck disable=SC2086 mv $TMPDB $DB rm $NOTESDIR/$FILE + gitremove $OK $FILE echo "Deleted note $TITLE" sleep 1 exit