backups management. Some UX improvements v0.3
authordanix <danix@danix.xyz>
Fri, 7 Apr 2023 09:01:14 +0000 (11:01 +0200)
committerdanix <danix@danix.xyz>
Fri, 7 Apr 2023 09:01:14 +0000 (11:01 +0200)
README.md
SOURCE/CORE/helpers.sh
SOURCE/main.sh
notes.sh

index 88b8389..0901435 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,19 +4,30 @@
 
 I've found myself in need of a simple way to take notes, and since the other solutions available didn't meet my needs, I've decided to write my own script.
 
-It's a simple (enough) bash script, the only dependance (yet) is [jq](https://stedolan.github.io/jq/).
+It's a simple (enough) bash script, the only dependence (yet) is [jq](https://stedolan.github.io/jq/).
 
 here's all the functions that are now available:
 
 ```bash
--h | --help                    : This help text
--p | --plain                   : Output is in plain text (without this option the output is colored)
--l | --list                    : List existing notes
--a | --add "<title>"           : Add new note
--e | --edit <note>             : Modify note
--d | --delete [<note> | all]   : Delete note
--v | --version                 : Print version
---userconf                     : Export User config file
+Usage:
+  notes.sh [PARAMS] ...
+
+notes parameters are:
+  -h | --help                   : This help text
+  -p | --plain                  : Output is in plain text
+                                  (without this option the output is formatted)
+                                  (this option must precede all others)
+  -l | --list                   : List existing notes
+  -a | --add=["<title>"]        : Add new note
+  -e | --edit=[<note>]          : Edit note
+  -d | --delete=[<note> | all]  : Delete single note or all notes at once
+  -s | --show=[<note>]          : Display note using your favourite PAGER
+  -r | --restore=[<dir>]        : Restore a previous backup from dir
+  -v | --version                : Print version
+  --userconf                    : Export User config file
+  --backup [<dest>]             : Backup your data in your destination folder
+
+if a non option is passed and is a valid note ID, the note will be displayed.
 ```
 
 All the basic functionalities are present and working, it probably needs some polishing and some testing, so if you want to give it a try, let me know what you think.
@@ -28,27 +39,32 @@ By default the directory will be populated in `~/.local/share/bash-notes`.
 
 If you want to modify the predefined settings, you can export a user configuration file by running
 
-```notes.sh --userconf```
+```bash
+notes.sh --userconf
+```
 
-And you'll have all your settings in `~/.config/bash-notes.rc`. This file will be sourced everytime you run the script.
+And you'll have all your settings in `~/.config/bash-notes.rc`. This file will be sourced every time you run the script.
 
-You can change all these settings:
+You can change all these settings by editing the file:
 
 ```bash
 # Binaries to use
-JQ=/usr/bin/jq
-EDITOR=/usr/bin/vim
-TERMINAL=/usr/bin/alacritty
+JQ=${JQ:-/usr/bin/jq}
+EDITOR=${EDITOR:-/usr/bin/vim}
+TERMINAL=${TERMINAL:-/usr/bin/alacritty}
 # 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}
 
 # 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=~/.local/share/bash-notes
+BASEDIR=${BASEDIR:-~/.local/share/bash-notes}
 # notes database in json format
 DB=${BASEDIR}/db.json
 # directory containing the actual notes
@@ -63,14 +79,28 @@ Special attention is needed when specifying the options, in my case, using [alac
 
 bash-notes can:
 
- * write a new note `--add "Your note title"` or in short `-a "Your note title"`
- * modify an existing note `--edit [note ID]`, short version `-e [note ID]`
- * delete a note `--delete [note ID]`, or `-d [note ID]`
- * delete all notes `--delete all`, or `-d all`
+ * write a new note `--add="Your note title"` or in short `-a"Your note title"`
+
+ * modify an existing note `--edit=[note ID]`, short version `-e[note ID]`
+
+ * delete a note `--delete=[note ID]`, or `-d[note ID]`
+
+ * delete all notes `--delete=all`, or `-dall`
+
  * list existing notes `--list` or `-l` in short
 
+ * 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.
+
+   ```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.
 
+##### Plain listing vs "colorful"
+
 The `--plain` or `-p` option in short, dictates how the output from the script is formatted, here's a sample listing of all the notes:
 
 ```bash
@@ -91,10 +121,32 @@ notes.sh -pl
 ```
 
 It's just a proof of concept at the moment, but the idea is to use a more interesting output maybe using markup, and strip it down in plain mode. After all is still a work in progress.
-The plain option must precede all other options or it won't work. I'll try and fix this behaviour in the future.
+The plain option must precede all other options or it won't work. I'll try and fix this behavior in the future.
 
 I'd love to implement some kind of searching functionality, but I'll have to look into that.
 
+##### Backups
+
+Since version 0.3, this script can also handle backups of all your notes, you can specify a backup folder with
+
+```bash
+notes.sh --backup=/some/dir
+```
+
+and the script will create the directory if it doesn't exists and backup all your data, including the rc file if you made one.
+
+If you want to restore a backup you can do so with
+
+```bash
+notes.sh --restore=/some/dir
+```
+
+And the script will take care of putting everything back where it belongs. 
+
+> ##### A bit of a warning on restoring backups
+>
+> *Keep in mind that all your existing notes will be overwritten in the process.*
+
 ### Installing
 
 Simply copy the script in your $PATH and make it executable, something like this should work:
@@ -106,6 +158,8 @@ chmod 755 ~/bin/notes.sh
 
 Adapt to your needs as you see fit.
 
+The first time you run the script it will take care of creating all the files and folders it needs in the standard directories.
+
 ### Debugging
 
 If the script doesn't work for you for some reasons, you can turn on debugging by running the script like this:
@@ -124,12 +178,13 @@ There are of course things I'd love to add, but my main goal is for it to work t
 
 ### TO DO
 
- * add a way to search the notes
- * add a way to display a note without running vim
- * markdown?
-       - maybe implement an export feature that builds the html file from the note
- * write a bash completion script to enable autocomplete in the shell
- * other ideas may come [...]
+* add a way to search the notes
+* ~~add a way to display a note without running vim~~ *(done in version 0.3)*
+* markdown support?
+   * maybe implement an export feature that builds the html or pdf file from the note
+     (pandoc??)
+* write a bash completion script to enable autocomplete in the shell
+* other ideas may come [...]
 
 ### Contributing
 
@@ -137,6 +192,10 @@ It'd mean so much to receive some feedback, patches if you feel like contributin
 
 ### ChangeLog
 
+ * 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. 
+
  * v0.2 - debugging implemented
      - you can now generate a debug log in case something doesn't work
  * v0.1 - first public upload
@@ -145,7 +204,7 @@ It'd mean so much to receive some feedback, patches if you feel like contributin
 ### Mantainer
 
  * [danix](https://danix.xyz) - it's just me, really...
+
 ### LICENSE
 
 > bash-notes © 2023 by danix is licensed under CC BY-NC 4.0. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/
\ No newline at end of file
index f697c07..565413d 100644 (file)
@@ -13,7 +13,7 @@ function check_noteID() {
 
 function helptext() {
     echo "Usage:"
-    echo "  $0 [PARAMS] ..."
+    echo "  $0 [PARAMS] [note ID]..."
        echo ""
     echo "${BASENAME} parameters are:"
     echo -e "  -h | --help\t\t\t: This help text"
@@ -30,6 +30,7 @@ function helptext() {
     echo -e "  --userconf\t\t\t: Export User config file"
     echo -e "  --backup [<dest>]\t\t: Backup your data in your destination folder"
     echo ""
+    echo -e "if a non option is passed and is a valid note ID, the note will be displayed."
 }
 
 function configtext() {
index 476243b..be70a06 100644 (file)
@@ -120,3 +120,12 @@ while true; do
                        ;;
        esac
 done
+
+for arg; do
+       if [ $(check_noteID $arg) ]; then
+               shownote $arg
+       else
+               helptext
+               exit
+       fi
+done
index 6c81615..8a9c082 100755 (executable)
--- a/notes.sh
+++ b/notes.sh
@@ -161,7 +161,7 @@ function check_noteID() {
 
 function helptext() {
     echo "Usage:"
-    echo "  $0 [PARAMS] ..."
+    echo "  $0 [PARAMS] [note ID]..."
        echo ""
     echo "${BASENAME} parameters are:"
     echo -e "  -h | --help\t\t\t: This help text"
@@ -178,6 +178,7 @@ function helptext() {
     echo -e "  --userconf\t\t\t: Export User config file"
     echo -e "  --backup [<dest>]\t\t: Backup your data in your destination folder"
     echo ""
+    echo -e "if a non option is passed and is a valid note ID, the note will be displayed."
 }
 
 function configtext() {
@@ -537,3 +538,12 @@ while true; do
                        ;;
        esac
 done
+
+for arg; do
+       if [ $(check_noteID $arg) ]; then
+               shownote $arg
+       else
+               helptext
+               exit
+       fi
+done