+echo $PID > "$PIDFILE"
+
+# Export config to file
+function export_config() {
+ if [ -r ${RCFILE} ]; then
+ echo "Backing up current '${RCFILE}'...."
+ mv -f ${RCFILE} ${RCFILE}.$(date +%Y%m%d_%H%M)
+ fi
+ echo "Writing '${RCFILE}'...."
+ sed -n '/^set_defaults() {/,/^} # end set_defaults, do not change this line./p' $0 \
+ | grep -v set_defaults \
+ | sed -e 's/^\([^=]*\)=\${\1:-\([^}]*\)}/\1=\2/' \
+ > ${RCFILE}
+ if [ -r ${RCFILE} ]; then
+ echo "Taking no further action."
+ exit 0
+ else
+ echo "Could not write '${RCFILE}'...!"
+ exit 1
+ fi
+}
+
+# we should expand on this function to add a sample note and explain a little bit
+# how the program works.
+function firstrun() {
+ [ -f $RCFILE ] && RC=$RCFILE || RC="none"
+
+ clear
+ echo "${BASENAME} configuration:
+
+base directory: ${BASEDIR}/
+notes archive: ${NOTESDIR}/
+notes database: ${DB}
+rc file: $RC
+text editor: ${EDITOR}
+terminal: ${TERMINAL}
+jq executable: ${JQ}
+"
+
+ echo "Now I'll create the needed files and directories."
+ read -r -p "Do you wish to continue? (y/N) " ANSWER
+ case $ANSWER in
+ y|Y )
+ mkdir -p $NOTESDIR
+ cat << __EOL__ > ${DB}
+{
+ "params": {
+ "version": "${VERSION}",
+ "dbversion": "${DBVERSION}"
+ },
+ "notes": []
+}
+__EOL__
+ echo; echo "All done, you can now write your first note."
+ ;;
+ * )
+ echo "No changes made. Exiting"
+ exit
+ ;;
+ esac
+}
+
+# check for notes dir existance and create it in case it doesn't exists
+if [[ ! -d $NOTESDIR ]]; then
+ # we don't have a directory. FIRST RUN?
+ firstrun
+fi
+# 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
+}