-v | --version : Print version
--userconf : Export User config file
--backup [<dest>] : 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.
```
```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.
### 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`
* 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"
>
> *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:
### 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
$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
IN=$1
case $IN in
''|*[!0-9]*)
- return 1
+ false
;;
*)
echo "$IN"
echo -e " -v | --version\t\t: Print version"
echo -e " --userconf\t\t\t: Export User config file"
echo -e " --backup [<dest>]\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
# 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.
# 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.
IN=$1
case $IN in
''|*[!0-9]*)
- return 1
+ false
;;
*)
echo "$IN"
echo -e " -v | --version\t\t: Print version"
echo -e " --userconf\t\t\t: Export User config file"
echo -e " --backup [<dest>]\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
$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