# create PIDFILE
echo $PID > $PIDFILE
+# check if input is a number, returns false or the number itself
+function check_noteID() {
+ IN=$1
+ case $IN in
+ ''|*[!0-9]*)
+ return 1
+ ;;
+ *)
+ echo $IN
+ ;;
+ esac
+}
+
function helptext() {
echo "Usage:"
- echo " $0 [OPTION] ..."
+ echo " $0 [PARAMS] ..."
echo ""
cat << __NOWCONF__
${BASENAME} configuration is:
notes archive: ${NOTESDIR}/
notes database: ${DB}
rc file: $RCFILE
+
text editor: ${EDITOR}
terminal: ${TERMINAL}
jq executable: ${JQ}
echo ""
echo "The script's parameters are:"
echo " -h | --help : This help text"
+ echo " -p | --plain : Output is in plain text"
+ echo " (without this option the output is colored)"
echo " -l | --list : List existing notes"
echo " -a | --add <title> : Add new note"
echo " -m | --modify <note> : Modify note"
- echo " -d | -date <note> : Modify date for note"
+ echo " -d | --date <note> : Modify date for note"
echo " -r | --remove <note> : Remove note"
echo " -v | --version : Print version"
echo " --userconf : Export User config file"
}
function listnotes() {
- echo "list all notes"
+ echo "listing all notes"
+ [ $PLAIN == true ] && echo "output is plain text" || echo "output is colored"
+ echo ""
+ echo "[ID] [TITLE]"
+ for i in ${NOTESDIR}/*; do
+ TITLE=$($JQ -r --arg z $(basename $i) '.notes[] | select(.file == $z) | .title' $DB)
+ ID=$($JQ -r --arg z $(basename $i) '.notes[] | select(.file == $z) | .id' $DB)
+
+ echo "[${ID}] ${TITLE}"
+ done
}
function editnote() {
- echo "edit note \"${1}\""
+ NOTE=$1
+ local OK=$(check_noteID $NOTE)
+ if [ ! $OK ]; then
+ echo "invalid note \"$NOTE\""
+ exit 1
+ fi
+
+ TITLE=$($JQ --arg i $OK '.notes[] | select(.id == $i) | .title' $DB)
+ FILE=$($JQ -r --arg i $OK '.notes[] | select(.id == $i) | .file' $DB)
+ if [ "$TITLE" ]; then
+ echo "editing note $TITLE"
+ $(${TERMINAL} --class notes --title notes -e ${EDITOR} ${NOTESDIR}/${FILE})
+ else
+ echo "note not found"
+ exit 1
+ fi
}
function datenote() {
- echo "edit date for note \"${1}\""
+ NOTE=$1
+ local OK=$(check_noteID $NOTE)
+ [ $OK ] && echo "editing date for note $OK" || echo "invalid note \"$NOTE\""
# FILEDATE=$(date -d @$NOW +%d/%m/%Y_%T)
}
function rmnote() {
NOTE=$1
- echo "removing note $NOTE"
+ local OK=$(check_noteID $NOTE)
+ [ $OK ] && echo "removing note $OK" || echo "invalid note \"$NOTE\""
}
function export_config() {
# NOTE: This requires GNU getopt. On Mac OS X and FreeBSD, you have to install this
# separately; see below.
-GOPT=`getopt -o hvla:m:d:r: --long help,version,list,userconf,add:,modify:,date:,remove:,editor:,storage: \
+GOPT=`getopt -o hvpla:m:d:r: --long help,version,list,plain,userconf,add:,modify:,date:,remove:,editor:,storage: \
-n 'bash-notes' -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$GOPT': they are essential!
eval set -- "$GOPT"
+PLAIN=false
+
while true; do
case "$1" in
-h | --help )
echo $BASENAME v${VERSION}
exit
;;
+ -p | --plain )
+ PLAIN=true
+ shift
+ ;;
-l | --list )
listnotes
exit