232effadb92ebfe22d13df11b08647add39abf27
[bash-notes.git] / notes.sh
1 #! /bin/bash
2
3 # bash-notes © 2023 by danix is licensed under CC BY-NC 4.0.
4 # To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/
5
6 # to debug the script run it like:
7 # DEBUG=true notes.sh ...
8 # and check /tmp/debug_bash-notes.log
9 if [[ $DEBUG == true ]]; then
10 exec 5> /tmp/debug_bash-notes.log
11 BASH_XTRACEFD="5"
12 PS4='$LINENO: '
13 set -x
14 fi
15
16 PID=$$
17 BASENAME=$( basename "$0" )
18 NOW=$(date +%s)
19
20 VERSION="0.4git"
21 DBVERSION=${VERSION}_${NOW}
22
23 set_defaults() {
24 # Binaries to use
25 JQ=${JQ:-/usr/bin/jq}
26 EDITOR=${EDITOR:-/usr/bin/vim}
27 TERMINAL=${TERMINAL:-/usr/bin/alacritty}
28 # Git binary only used if $USEGIT is true - See below
29 GIT=${GIT:-/usr/bin/git}
30 # add options for your terminal. Remember to add the last option to execute
31 # your editor program, otherwise the script will fail.
32 # see example in the addnote function
33 TERM_OPTS="--class notes --title notes -e "
34 # Setting PAGER here overrides whatever is set in your default shell
35 # comment this option to use your default pager if set in your shell.
36 PAGER=${PAGER:-/usr/bin/more}
37
38 # set this to true to have output in plain text
39 # or use the -p option on the command line before every other option
40 PLAIN=false
41 # base directory for program files
42 BASEDIR=${BASEDIR:-~/.local/share/bash-notes}
43 # notes database in json format
44 DB=${BASEDIR}/db.json
45 # directory containing the actual notes
46 NOTESDIR=${BASEDIR}/notes
47
48 ### GIT SUPPORT
49
50 # If you want to store your notes in a git repository set this to true
51 USEGIT=true
52 # Address of your remote repository. Without this GIT will refuse to work
53 GITREMOTE=${GITREMOTE:-""}
54 # How long should we wait (in seconds) between sync on the git remote. Default 3600 (1 hour)
55 GITSYNCDELAY=${GITSYNCDELAY:-"3600"}
56 # The name of this client. If left empty, defaults to the output of hostname
57 GITCLIENT=${GITCLIENT:-""}
58
59 } # end set_defaults, do not change this line.
60
61 set_defaults
62
63 # Do not edit below this point
64 RCFILE=${RCFILE:-~/.config/bash-notes.rc}
65 TMPDB=/tmp/db.json
66
67 if [ ! -x "$JQ" ]; then
68 echo "jq not found in your PATH"
69 echo "install jq to continue"
70 exit 1
71 fi
72
73 # IMPORT USER DEFINED OPTIONS IF ANY
74 if [[ -f $RCFILE ]]; then
75 # shellcheck disable=SC1090
76 source "$RCFILE"
77 fi
78
79 # We prevent the program from running more than one instance:
80 PIDFILE=/var/tmp/$(basename "$0" .sh).pid
81
82 # Make sure the PID file is removed when we kill the process
83 trap 'rm -f $PIDFILE; exit 1' TERM INT
84
85 if [[ -r $PIDFILE ]]; then
86 # PIDFILE exists, so I guess there's already an instance running
87 # let's kill it and run again
88 # shellcheck disable=SC2046,SC2086
89 kill -s 15 $(cat $PIDFILE) > /dev/null 2>&1
90 # should already be deleted by trap, but just to be sure
91 rm "$PIDFILE"
92 fi
93
94 # create PIDFILE
95 echo $PID > "$PIDFILE"
96
97 # Export config to file
98 export_config() {
99 if [ -r ${RCFILE} ]; then
100 echo "Backing up current '${RCFILE}'...."
101 mv -f ${RCFILE} ${RCFILE}.$(date +%Y%m%d_%H%M)
102 fi
103 echo "Writing '${RCFILE}'...."
104 sed -n '/^set_defaults() {/,/^} # end set_defaults, do not change this line./p' $0 \
105 | grep -v set_defaults \
106 | sed -e 's/^\([^=]*\)=\${\1:-\([^}]*\)}/\1=\2/' \
107 > ${RCFILE}
108 if [ -r ${RCFILE} ]; then
109 echo "Taking no further action."
110 exit 0
111 else
112 echo "Could not write '${RCFILE}'...!"
113 exit 1
114 fi
115 }
116
117 # we should expand on this function to add a sample note and explain a little bit
118 # how the program works.
119 firstrun() {
120 [ -f $RCFILE ] && RC=$RCFILE || RC="none"
121
122 clear
123 echo "${BASENAME} configuration:
124
125 base directory: ${BASEDIR}/
126 notes archive: ${NOTESDIR}/
127 notes database: ${DB}
128 rc file: $RC
129 text editor: ${EDITOR}
130 terminal: ${TERMINAL}
131 jq executable: ${JQ}
132 "
133
134 echo "Now I'll create the needed files and directories."
135 read -r -p "Do you wish to continue? (y/N) " ANSWER
136 case $ANSWER in
137 y|Y )
138 mkdir -p $NOTESDIR
139 cat << __EOL__ > ${DB}
140 {
141 "params": {
142 "version": "${VERSION}",
143 "dbversion": "${DBVERSION}"
144 },
145 "git": {
146 "lastpull": ""
147 },
148 "notes": []
149 }
150 __EOL__
151 echo; echo "All done, you can now write your first note."
152 ;;
153 * )
154 echo "No changes made. Exiting"
155 exit
156 ;;
157 esac
158 }
159
160 # check for notes dir existance and create it in case it doesn't exists
161 if [[ ! -d $NOTESDIR ]]; then
162 # we don't have a directory. FIRST RUN?
163 firstrun
164 fi
165 # check if input is a number, returns false or the number itself
166 check_noteID() {
167 IN=$1
168 case $IN in
169 ''|*[!0-9]*)
170 false
171 ;;
172 *)
173 echo "$IN"
174 ;;
175 esac
176 }
177
178 helptext() {
179 echo "Usage:"
180 echo " $0 [PARAMS] [note ID]..."
181 echo ""
182 echo "${BASENAME} parameters are:"
183 echo -e " -h | --help\t\t\t: This help text"
184 echo -e " -p | --plain\t\t\t: Output is in plain text"
185 echo -e "\t\t\t\t (without this option the output is formatted)"
186 echo -e "\t\t\t\t (this option must precede all others)"
187 echo -e " -l | --list\t\t\t: List existing notes"
188 echo -e " -a | --add=[\"<title>\"]\t: Add new note"
189 echo -e " -e | --edit=[<note>]\t\t: Edit note"
190 echo -e " -d | --delete=[<note> | all] : Delete single note or all notes at once"
191 echo -e " -s | --show=[<note>]\t\t: Display note using your favourite PAGER"
192 echo -e " -r | --restore=[<dir>]\t: Restore a previous backup from dir"
193 echo -e " -v | --version\t\t: Print version"
194 echo -e " --userconf\t\t\t: Export User config file"
195 echo -e " --backup [<dest>]\t\t: Backup your data in your destination folder"
196 echo -e " --showconf\t\t\t: Display running options"
197 echo -e " --sync\t\t\t: Sync notes to git repository"
198 echo ""
199 echo -e "if a non option is passed and is a valid note ID, the note will be displayed."
200 }
201
202 configtext() {
203 [ $USEGIT ] && GITUSE="enabled" || GITUSE="disabled"
204 if [ -n $GITCLIENT ]; then
205 CLIENTGIT="$( hostname )"
206 else
207 CLIENTGIT="$GITCLIENT"
208 fi
209 clear
210 echo -e "${BASENAME} configuration is:"
211
212 echo -e "\tbase directory: ${BASEDIR}/"
213 echo -e "\tnotes archive: ${NOTESDIR}/"
214 echo -e "\tnotes database: ${DB}"
215 echo -e "\trc file: $RCFILE"
216 echo -e "\tdebug file: /tmp/debug_bash-note.log"
217 echo
218 echo -e "\ttext editor: ${EDITOR}"
219 echo -e "\tterminal: ${TERMINAL}"
220 echo -e "\tjq executable: ${JQ}"
221 echo -e "\tPAGER: ${PAGER}"
222 echo
223 echo -e "\tGIT: ${GITUSE} - ${GIT}"
224 echo -e "\tGIT remote: ${GITREMOTE}"
225 echo -e "\tGIT sync delay: ${GITSYNCDELAY}"
226 echo -e "\tGIT client name: ${CLIENTGIT}"
227 }
228
229 # this function returns a random 2 words title
230 random_title() {
231 # Constants
232 X=0
233 DICT=/usr/share/dict/words
234 OUTPUT=""
235
236 # total number of non-random words available
237 COUNT=$(cat $DICT | wc -l)
238
239 # while loop to generate random words
240 while [ "$X" -lt 2 ]
241 do
242 RAND=$(od -N3 -An -i /dev/urandom | awk -v f=0 -v r="$COUNT" '{printf "%i\n", f + r * $1 / 16777216}')
243 OUTPUT+="$(sed `echo $RAND`"q;d" $DICT)"
244 (("X = X + 1"))
245 [[ $X -eq 1 ]] && OUTPUT+=" "
246 done
247
248 echo $OUTPUT
249 }
250
251 # check if GITCLIENT has been set or set it to the output of hostname
252 if [ -z "$GITCLIENT" ]; then
253 GITCLIENT=$( hostname )
254 fi
255 # returns true if the argument provided directory is a git repository
256 is_git_repo() {
257 DIR=$1
258 if [[ -d $DIR ]]; then
259 cd $DIR
260 if git rev-parse 2>/dev/null; then
261 true
262 else
263 false
264 fi
265 fi
266 }
267
268 # sync local repository to remote
269 # accepts -f parameter to skip last sync check
270 gitsync() {
271 FORCE=$1
272 if [[ $USEGIT && -n $GITREMOTE ]]; then
273 [ $PLAIN == false ] && echo "Syncing notes with git on remote \"$GITREMOTE\""
274 NOWSYNC=$(date +%s)
275 if [[ $FORCE == "-f" ]]; then
276 $JQ --arg n "$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB
277 mv $TMPDB $DB
278 cd $BASEDIR
279 [ $PLAIN == false ] && $GIT pull || $GIT pull -q
280 else
281 # LASTSYNC is the last time we synced to the remote, or 0 if it's the first time.
282 LASTSYNC=$($JQ -r '.git["lastpull"] // 0' "$DB")
283 SYNCDIFF=$(( ${NOWSYNC} - ${LASTSYNC} ))
284 if (( $SYNCDIFF > $GITSYNCDELAY )); then
285 #more than our delay time has passed. We can sync again.
286 $JQ --arg n "$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB
287 mv $TMPDB $DB
288 cd $BASEDIR
289 [ $PLAIN == false ] && $GIT pull || $GIT pull -q
290 else
291 # Last synced less than $GITSYNCDELAY seconds ago. We shall wait
292 [ $PLAIN == false ] && echo "Last synced less than $GITSYNCDELAY seconds ago. We shall wait"
293 fi
294 fi
295 else
296 # no git, so we just keep going
297 true
298 fi
299 }
300
301 # add note to git and push it to remote
302 gitadd() {
303 if [[ $USEGIT && -n $GITREMOTE ]]; then
304 [ $PLAIN == false ] && echo "Adding note to remote \"$GITREMOTE\""
305 cd $BASEDIR
306 $GIT add .
307 $GIT commit -m "$(basename $0) - adding note from ${GITCLIENT}"
308 $GIT push origin master
309 else
310 # no git, so we just keep going
311 true
312 fi
313 }
314
315 # edited note added to git and pushed it to remote
316 gitedit() {
317 if [[ $USEGIT && -n $GITREMOTE ]]; then
318 [ $PLAIN == false ] && echo "Editing note on remote \"$GITREMOTE\""
319 cd $BASEDIR
320 $GIT add .
321 $GIT commit -m "$(basename $0) - ${GITCLIENT} note edited."
322 $GIT push origin master
323 else
324 # no git, so we just keep going
325 true
326 fi
327 }
328
329 # add note to git and push it to remote
330 gitremove() {
331 NOTE=$1
332 FILE=$2
333 if [[ $USEGIT && -n $GITREMOTE ]]; then
334 [ $PLAIN == false ] && echo "Deleting notes from remote \"$GITREMOTE\""
335 if [ "all" == $NOTE ];then
336 echo "Deleting all notes"
337 cd $BASEDIR
338 $GIT rm notes/*
339 $GIT commit -m "$(basename $0) - ${GITCLIENT} removing all notes."
340 $GIT push origin master
341 else
342 local OK=$(check_noteID "$NOTE")
343 if [[ "$OK" ]]; then
344 echo "Deleting note ID ${NOTE}"
345 cd $BASEDIR
346 $GIT rm notes/${FILE}
347 $GIT add .
348 $GIT commit -m "$(basename $0) - ${GITCLIENT} removing note ID ${NOTE}."
349 $GIT push origin master
350 fi
351 fi
352 else
353 # no git, so we just keep going
354 true
355 fi
356 }
357
358 # check for USEGIT and subsequent variables
359 if [[ $USEGIT && -n $GITREMOTE ]]; then
360 # GIT is a go.
361 if ! is_git_repo $BASEDIR; then
362 # initializing git repository
363 cd $BASEDIR
364 $GIT init
365 echo "adding all files to git"
366 $GIT add .
367 $GIT commit -m "$(basename $0) - initial commit from ${GITCLIENT}"
368 $GIT remote add origin $GITREMOTE
369 $GIT push -u origin master
370 fi
371 elif [[ $USEGIT && -z $GITREMOTE ]]; then
372 echo "GITREMOTE variable not set. reverting USEGIT to false"
373 USEGIT=false
374 fi
375
376 addnote() {
377 # attempt syncing before adding a note
378 gitsync -f
379 # remove eventually existing temp DB file
380 if [[ -f $TMPDB ]]; then
381 rm $TMPDB
382 fi
383
384 RTITLE=$(random_title)
385 [[ -z "$1" ]] && NOTETITLE="$RTITLE" || NOTETITLE="$1"
386 echo "adding new note - \"$NOTETITLE\""
387 # shellcheck disable=SC2086
388 LASTID=$($JQ '.notes[-1].id // 0 | tonumber' $DB)
389 # [ "" == $LASTID ] && LASTID=0
390 NOTEID=$(( LASTID + 1 ))
391 # shellcheck disable=SC2086
392 touch ${NOTESDIR}/${NOW}
393 # shellcheck disable=SC2016
394 $JQ --arg i "$NOTEID" --arg t "$NOTETITLE" --arg f "$NOW" '.notes += [{"id": $i, "title": $t, "file": $f}]' "$DB" > $TMPDB
395 # shellcheck disable=SC2086
396 mv $TMPDB $DB
397 # example for alacritty:
398 # alacritty --class notes --title notes -e /usr/bin/vim ...
399 # shellcheck disable=SC2086,SC2091
400 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${NOW})
401 # add note to git and push to remote
402 gitadd
403 }
404 backup_data() {
405 BACKUPDIR="$1"
406 echo "backing up data in $BACKUPDIR"
407
408
409 if [ -d $BACKUPDIR ]; then
410 if [ $(/bin/ls -A $BACKUPDIR) ]; then
411 echo "$BACKUPDIR is not empty. Cannot continue"
412 exit
413 else
414 echo "$BACKUPDIR is ok. Continuing!"
415 fi
416 else
417 # BACKUPDIR doesn't exists
418 echo "$BACKUPDIR doesn't exists"
419 read -r -p "Do you want me to create it for you? (y/N) " ANSWER
420 case $ANSWER in
421 y|Y )
422 mkdir -p $BACKUPDIR
423 ;;
424 * )
425 echo "No changes made. Exiting"
426 exit
427 ;;
428 esac
429 fi
430 # ok, we have a backup directory
431 if [ -r $RCFILE ]; then
432 BCKUP_COMM=$(rsync -avz --progress ${RCFILE}* ${BASEDIR}/ ${BACKUPDIR})
433 else
434 BCKUP_COMM=$(rsync -avz --progress ${BASEDIR}/ ${BACKUPDIR})
435 fi
436 # run the command
437 if [ "$BCKUP_COMM" ]; then
438 echo -e "All files backed up."
439 echo -e "BACKUP directory:\t$BACKUPDIR"
440 tree $BACKUPDIR | $PAGER
441 echo; echo "BACKUP COMPLETED"
442 fi
443 }
444
445 backup_restore() {
446 BACKUPDIR="$1"
447 echo "restoring backup from $BACKUPDIR"
448 echo "This will overwrite all your notes and configurations with the backup."
449 read -r -p "Do you want to continue? (y/N) " ANSWER
450 case $ANSWER in
451 y|Y )
452 # restoring rc file
453 BACKUPRC=$(basename $RCFILE)
454 if [ -r ${BACKUPDIR}/${BACKUPRC} ]; then
455 if [ -r ${RCFILE} ]; then
456 echo "Backing up current '${RCFILE}'...."
457 mv -f ${RCFILE} ${RCFILE}.$(date +%Y%m%d_%H%M)
458 fi
459 cp --verbose ${BACKUPDIR}/${BACKUPRC} $RCFILE
460 fi
461 # restoring notes directory
462 if [ -d $BACKUPDIR/notes ]; then
463 if [ $(/bin/ls -A $NOTESDIR) ]; then
464 rm --verbose $NOTESDIR/*
465 fi
466 cp -r --verbose $BACKUPDIR/notes $BASEDIR
467 fi
468 # restoring database
469 BACKUPDB=$(basename $DB)
470 if [ -f ${BACKUPDIR}/${BACKUPDB} ]; then
471 if [ -r ${DB} ]; then
472 echo "Backing up current '${DB}'...."
473 mv -f ${DB} ${DB}.$(date +%Y%m%d_%H%M)
474 fi
475 cp --verbose ${BACKUPDIR}/${BACKUPDB} $DB
476 fi
477 # restoring git repo subdirectory
478 if [ -d $BACKUPDIR/.git ]; then
479 if [ /bin/ls -A ${BASEDIR}/.git ]; then
480 rm -rf ${BASEDIR}/.git
481 fi
482 cp -r --verbose ${BACKUPDIR}/.git ${BASEDIR}/
483 fi
484 ;;
485 * )
486 echo "No changes made. Exiting"
487 exit
488 ;;
489 esac
490 }
491
492 editnote() {
493 NOTE=$1
494 # shellcheck disable=SC2155
495 local OK=$(check_noteID "$NOTE")
496 if [ ! "$OK" ]; then
497 echo "invalid note \"$NOTE\""
498 echo "Use the note ID that you can fetch after listing your notes"
499 exit 1
500 fi
501
502 # shellcheck disable=SC2016,SC2086
503 TITLE=$($JQ --arg i $OK '.notes[] | select(.id == $i) | .title' $DB)
504 # shellcheck disable=SC2016,SC2086
505 FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB)
506 if [ "$TITLE" ]; then
507 echo "editing note $TITLE"
508 # shellcheck disable=SC2086,SC2091
509 $(${TERMINAL} ${TERM_OPTS} ${EDITOR} ${NOTESDIR}/${FILE})
510 gitedit
511 else
512 echo "note not found"
513 exit 1
514 fi
515 }
516 listnotes() {
517 # attempt syncing before listing all notes
518 gitsync
519 # [ $PLAIN == true ] && echo "output is plain text" || echo "output is colored"
520 if [[ $(ls -A "$NOTESDIR") ]]; then
521 if [ $PLAIN == false ]; then
522 echo "listing all notes"
523 echo ""
524 fi
525 [ $PLAIN == false ] && echo "[ID] [TITLE] [CREATED]"
526 for i in "${NOTESDIR}"/*; do
527 # shellcheck disable=SC2155
528 local fname=$(basename $i)
529 DATE=$(date -d @${fname} +"%d/%m/%Y %R %z%Z")
530 # shellcheck disable=SC2016,SC2086
531 TITLE=$($JQ -r --arg z $(basename $i) '.notes[] | select(.file == $z) | .title' $DB)
532 # shellcheck disable=SC2016,SC2086
533 ID=$($JQ -r --arg z $(basename $i) '.notes[] | select(.file == $z) | .id' $DB)
534 [ $PLAIN == false ] && echo "[${ID}] ${TITLE} ${DATE}" || echo "${ID} - ${TITLE} - ${DATE}"
535 done
536 else
537 echo "no notes yet. You can add your first one with: ${BASENAME} -a \"your note title\""
538 fi
539 }
540 rmnote() {
541 # remove eventually existing temp DB file
542 if [[ -f $TMPDB ]]; then
543 rm $TMPDB
544 fi
545
546 NOTE=$1
547 if [ "all" == "$NOTE" ]; then
548 echo "You're going to delete all notes."
549 read -r -p "Do you wish to continue? (y/N) " ANSWER
550 case $ANSWER in
551 y|Y )
552 # shellcheck disable=SC2086
553 $JQ 'del(.notes[])' $DB > $TMPDB
554 # shellcheck disable=SC2086
555 mv $TMPDB $DB
556 # shellcheck disable=SC2086
557 rm $NOTESDIR/*
558 gitremove "all"
559 echo "Deleted all notes"
560 ;;
561 * )
562 echo "Aborting, no notes were deleted."
563 exit 1
564 ;;
565 esac
566 else
567 # shellcheck disable=SC2155
568 local OK=$(check_noteID "$NOTE")
569 if [ ! "$OK" ]; then
570 echo "invalid note \"$NOTE\""
571 echo "Use the note ID that you can fetch after listing your notes"
572 sleep 1
573 exit 1
574 fi
575
576 # shellcheck disable=SC2016,SC2086
577 TITLE=$($JQ --arg i $OK '.notes[] | select(.id == $i) | .title' $DB)
578 # shellcheck disable=SC2016,SC2086
579 FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB)
580 if [ "$TITLE" ]; then
581 # shellcheck disable=SC2016,SC2086
582 $JQ -r --arg i $OK 'del(.notes[] | select(.id == $i))' $DB > $TMPDB
583 # shellcheck disable=SC2086
584 mv $TMPDB $DB
585 rm $NOTESDIR/$FILE
586 gitremove $OK $FILE
587 echo "Deleted note $TITLE"
588 sleep 1
589 exit
590 else
591 echo "note not found"
592 sleep 1
593 exit 1
594 fi
595 fi
596 }
597 shownote() {
598 NOTE=$1
599
600 # shellcheck disable=SC2155
601 local OK=$(check_noteID "$NOTE")
602 if [ ! "$OK" ]; then
603 echo "invalid note \"$NOTE\""
604 echo "Use the note ID that you can fetch after listing your notes"
605 exit 1
606 fi
607
608 FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB)
609
610 if [ "$FILE" ]; then
611 $PAGER ${NOTESDIR}/${FILE}
612 fi
613 }
614 # shellcheck disable=SC2006
615 GOPT=$(getopt -o hvplr:a:e:d:s: --long help,version,list,plain,userconf,showconf,sync,restore:,backup:,add:,edit:,delete:,show: -n 'bash-notes' -- "$@")
616
617 # shellcheck disable=SC2181
618 if [ $? != 0 ] ; then helptext >&2 ; exit 1 ; fi
619
620 # Note the quotes around `$GOPT': they are essential!
621 eval set -- "$GOPT"
622 unset GOPT
623
624 while true; do
625 case "$1" in
626 -h | --help )
627 helptext
628 exit
629 ;;
630 -v | --version )
631 echo $BASENAME v${VERSION}
632 exit
633 ;;
634 -p | --plain )
635 PLAIN=true
636 shift
637 ;;
638 -l | --list )
639 listnotes
640 exit
641 ;;
642 -a | --add )
643 shift 2
644 addnote "$TITLE"
645 exit
646 ;;
647 -e | --edit )
648 shift 2
649 editnote "$NOTE"
650 exit
651 ;;
652 -d | --delete )
653 shift 2
654 rmnote "$NOTE"
655 exit
656 ;;
657 -s | --show )
658 shift 2
659 shownote "$NOTE"
660 exit
661 ;;
662 -r | --restore )
663 shift 2
664 backup_restore $RDIR
665 exit
666 ;;
667 --sync )
668 # I'm forcing it because if you run it manually, chances are that you need to.
669 gitsync -f
670 shift
671 exit
672 ;;
673 --userconf )
674 export_config
675 # shellcheck disable=SC2317
676 echo "config exported to \"$RCFILE\""
677 # shellcheck disable=SC2317
678 exit
679 ;;
680 --showconf )
681 configtext
682 exit
683 ;;
684 --backup )
685 shift 2
686 backup_data $BDIR
687 exit
688 ;;
689 -- )
690 shift
691 break
692 ;;
693 * )
694 break
695 ;;
696 esac
697 done
698
699 for arg; do
700 if [ $(check_noteID $arg) ]; then
701 shownote $arg
702 else
703 helptext
704 exit
705 fi
706 done