From: danix Date: Sat, 22 Apr 2023 07:53:42 +0000 (+0200) Subject: cleanup of the output of the program. Updated README. X-Git-Tag: v0.4^0 X-Git-Url: https://git.danix.xyz/?a=commitdiff_plain;h=refs%2Fheads%2Fgitsupport;p=bash-notes.git cleanup of the output of the program. Updated README. --- diff --git a/README.md b/README.md index 0901435..df2996b 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ notes parameters are: -v | --version : Print version --userconf : Export User config file --backup [] : Backup your data in your destination folder + --showconf : Display running options + --sync : Sync notes to git repository if a non option is passed and is a valid note ID, the note will be displayed. ``` @@ -49,26 +51,39 @@ You can change all these settings by editing the file: ```bash # Binaries to use -JQ=${JQ:-/usr/bin/jq} -EDITOR=${EDITOR:-/usr/bin/vim} -TERMINAL=${TERMINAL:-/usr/bin/alacritty} +JQ=/usr/bin/jq +EDITOR=/usr/bin/vim +TERMINAL=/usr/bin/alacritty +# Git binary only used if $USEGIT is true - See below +GIT=/usr/bin/git # add options for your terminal. Remember to add the last option to execute # your editor program, otherwise the script will fail. # see example in the addnote function TERM_OPTS="--class notes --title notes -e " # Setting PAGER here overrides whatever is set in your default shell # comment this option to use your default pager if set in your shell. -PAGER=${PAGER:-/usr/bin/more} +PAGER=/usr/bin/more # set this to true to have output in plain text # or use the -p option on the command line before every other option PLAIN=false # base directory for program files -BASEDIR=${BASEDIR:-~/.local/share/bash-notes} +BASEDIR=~/.local/share/bash-notes # notes database in json format DB=${BASEDIR}/db.json # directory containing the actual notes NOTESDIR=${BASEDIR}/notes + +### GIT SUPPORT + +# If you want to store your notes in a git repository set this to true +USEGIT=true +# Address of your remote repository. Without this GIT will refuse to work +GITREMOTE="" +# How long should we wait (in seconds) between sync on the git remote. Default 3600 (1 hour) +GITSYNCDELAY="3600" +# The name of this client. If left empty, defaults to the output of hostname +GITCLIENT="" ``` Most are pretty self explanatory, the only one that might need clarification is `TERM_OPTS` which is used to set the terminal window that will run the editor while writing the note. @@ -77,13 +92,17 @@ Special attention is needed when specifying the options, in my case, using [alac ### Functionalities -bash-notes can: +This script can: * write a new note `--add="Your note title"` or in short `-a"Your note title"` + - EG. `notes.sh --add="this is a nice note"` + If the title is left empty, two random words will be assigned as title. * modify an existing note `--edit=[note ID]`, short version `-e[note ID]` + - EG. `notes.sh --edit=7` will let you modify note n. 7 * delete a note `--delete=[note ID]`, or `-d[note ID]` + - EG. `notes.sh --delete=7` will delete note n. 7 * delete all notes `--delete=all`, or `-dall` @@ -91,13 +110,13 @@ bash-notes can: * display a note `--show=[note ID]`, or `-s[note ID]`. - It's also possible to simply pass [note ID] as an argument to the script and the corresponding note will be displayed. + It's also possible to simply pass `[note ID]` as an argument to the script and the corresponding note will be displayed. ```bash notes.sh 1 ``` -The *note id* is assigned when the note is created, and that's how you refer to the note in the program. +The *note id* is assigned when the note is created, and that's how you refer to the note in the program. You can see the IDs assigned to each note when listing them. ##### Plain listing vs "colorful" @@ -147,6 +166,15 @@ And the script will take care of putting everything back where it belongs. > > *Keep in mind that all your existing notes will be overwritten in the process.* +##### Git + +Starting with version 0.4, git support has been added, so now you can sync your notes to a git remote. The program lets you specify a few options like: + - your git executable + - the remote address + - how long before syncing again to the remote + - a nickname for the computer where this script is running. + This is helpful if you want to sync your notes on multiple computers, to know from which client something has appened to git. + ### Installing Simply copy the script in your $PATH and make it executable, something like this should work: @@ -192,9 +220,12 @@ It'd mean so much to receive some feedback, patches if you feel like contributin ### ChangeLog + * v0.4 - GIT support. Some UX improvements + - Sync all your notes to a git remote. + * v0.3 - backups management. Some UX improvements - * create and restore backups of all your notes and settings. - * display notes using predefined PAGER variable or define your own program to use. + - create and restore backups of all your notes and settings. + - display notes using predefined PAGER variable or define your own program to use. * v0.2 - debugging implemented - you can now generate a debug log in case something doesn't work diff --git a/SOURCE/CORE/git.sh b/SOURCE/CORE/git.sh index 3ddec6c..42c89a8 100644 --- a/SOURCE/CORE/git.sh +++ b/SOURCE/CORE/git.sh @@ -89,13 +89,15 @@ gitremove() { $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 + if [[ "$OK" ]]; then + echo "Deleting note ID ${NOTE}" + cd $BASEDIR + $GIT rm notes/${FILE} + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing note ID ${NOTE}." + $GIT push origin master + fi fi else # no git, so we just keep going diff --git a/SOURCE/CORE/helpers.sh b/SOURCE/CORE/helpers.sh index 38da28c..3f013f2 100644 --- a/SOURCE/CORE/helpers.sh +++ b/SOURCE/CORE/helpers.sh @@ -3,7 +3,7 @@ check_noteID() { IN=$1 case $IN in ''|*[!0-9]*) - return 1 + false ;; *) echo "$IN" @@ -29,29 +29,37 @@ helptext() { echo -e " -v | --version\t\t: Print version" echo -e " --userconf\t\t\t: Export User config file" echo -e " --backup []\t\t: Backup your data in your destination folder" + echo -e " --showconf\t\t\t: Display running options" + echo -e " --sync\t\t\t: Sync notes to git repository" echo "" echo -e "if a non option is passed and is a valid note ID, the note will be displayed." } configtext() { [ $USEGIT ] && GITUSE="enabled" || GITUSE="disabled" + if [ -n $GITCLIENT ]; then + CLIENTGIT="$( hostname )" + else + CLIENTGIT="$GITCLIENT" + fi clear echo -e "${BASENAME} configuration is:" - echo -e "base directory: ${BASEDIR}/" - echo -e "notes archive: ${NOTESDIR}/" - echo -e "notes database: ${DB}" - echo -e "rc file: $RCFILE" - echo -e "debug file: /tmp/debug_bash-note.log" - - echo -e "text editor: ${EDITOR}" - echo -e "terminal: ${TERMINAL}" - echo -e "jq executable: ${JQ}" - echo -e "PAGER: ${PAGER}" - - echo -e "GIT use: ${GITUSE}" - echo -e "GIT remote: ${GITREMOTE}" - echo -e "GIT sync delay: ${GITSYNCDELAY}" + echo -e "\tbase directory: ${BASEDIR}/" + echo -e "\tnotes archive: ${NOTESDIR}/" + echo -e "\tnotes database: ${DB}" + echo -e "\trc file: $RCFILE" + echo -e "\tdebug file: /tmp/debug_bash-note.log" + echo + echo -e "\ttext editor: ${EDITOR}" + echo -e "\tterminal: ${TERMINAL}" + echo -e "\tjq executable: ${JQ}" + echo -e "\tPAGER: ${PAGER}" + echo + echo -e "\tGIT: ${GITUSE} - ${GIT}" + echo -e "\tGIT remote: ${GITREMOTE}" + echo -e "\tGIT sync delay: ${GITSYNCDELAY}" + echo -e "\tGIT client name: ${CLIENTGIT}" } # this function returns a random 2 words title diff --git a/SOURCE/head.sh b/SOURCE/head.sh index bce0d44..42e17c6 100644 --- a/SOURCE/head.sh +++ b/SOURCE/head.sh @@ -49,11 +49,11 @@ NOTESDIR=${BASEDIR}/notes # If you want to store your notes in a git repository set this to true USEGIT=true -# Address of your remote repository +# Address of your remote repository. Without this GIT will refuse to work GITREMOTE=${GITREMOTE:-""} # How long should we wait (in seconds) between sync on the git remote. Default 3600 (1 hour) GITSYNCDELAY=${GITSYNCDELAY:-"3600"} -# The name of this client. Defaults to the output of hostname +# The name of this client. If left empty, defaults to the output of hostname GITCLIENT=${GITCLIENT:-""} } # end set_defaults, do not change this line. diff --git a/notes.sh b/notes.sh index 089daca..5aa82c2 100755 --- a/notes.sh +++ b/notes.sh @@ -49,11 +49,11 @@ NOTESDIR=${BASEDIR}/notes # If you want to store your notes in a git repository set this to true USEGIT=true -# Address of your remote repository +# Address of your remote repository. Without this GIT will refuse to work GITREMOTE=${GITREMOTE:-""} # How long should we wait (in seconds) between sync on the git remote. Default 3600 (1 hour) GITSYNCDELAY=${GITSYNCDELAY:-"3600"} -# The name of this client. Defaults to the output of hostname +# The name of this client. If left empty, defaults to the output of hostname GITCLIENT=${GITCLIENT:-""} } # end set_defaults, do not change this line. @@ -167,7 +167,7 @@ check_noteID() { IN=$1 case $IN in ''|*[!0-9]*) - return 1 + false ;; *) echo "$IN" @@ -193,29 +193,37 @@ helptext() { echo -e " -v | --version\t\t: Print version" echo -e " --userconf\t\t\t: Export User config file" echo -e " --backup []\t\t: Backup your data in your destination folder" + echo -e " --showconf\t\t\t: Display running options" + echo -e " --sync\t\t\t: Sync notes to git repository" echo "" echo -e "if a non option is passed and is a valid note ID, the note will be displayed." } configtext() { [ $USEGIT ] && GITUSE="enabled" || GITUSE="disabled" + if [ -n $GITCLIENT ]; then + CLIENTGIT="$( hostname )" + else + CLIENTGIT="$GITCLIENT" + fi clear echo -e "${BASENAME} configuration is:" - echo -e "base directory: ${BASEDIR}/" - echo -e "notes archive: ${NOTESDIR}/" - echo -e "notes database: ${DB}" - echo -e "rc file: $RCFILE" - echo -e "debug file: /tmp/debug_bash-note.log" - - echo -e "text editor: ${EDITOR}" - echo -e "terminal: ${TERMINAL}" - echo -e "jq executable: ${JQ}" - echo -e "PAGER: ${PAGER}" - - echo -e "GIT use: ${GITUSE}" - echo -e "GIT remote: ${GITREMOTE}" - echo -e "GIT sync delay: ${GITSYNCDELAY}" + echo -e "\tbase directory: ${BASEDIR}/" + echo -e "\tnotes archive: ${NOTESDIR}/" + echo -e "\tnotes database: ${DB}" + echo -e "\trc file: $RCFILE" + echo -e "\tdebug file: /tmp/debug_bash-note.log" + echo + echo -e "\ttext editor: ${EDITOR}" + echo -e "\tterminal: ${TERMINAL}" + echo -e "\tjq executable: ${JQ}" + echo -e "\tPAGER: ${PAGER}" + echo + echo -e "\tGIT: ${GITUSE} - ${GIT}" + echo -e "\tGIT remote: ${GITREMOTE}" + echo -e "\tGIT sync delay: ${GITSYNCDELAY}" + echo -e "\tGIT client name: ${CLIENTGIT}" } # this function returns a random 2 words title @@ -331,13 +339,15 @@ gitremove() { $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 + if [[ "$OK" ]]; then + echo "Deleting note ID ${NOTE}" + cd $BASEDIR + $GIT rm notes/${FILE} + $GIT add . + $GIT commit -m "$(basename $0) - ${GITCLIENT} removing note ID ${NOTE}." + $GIT push origin master + fi fi else # no git, so we just keep going