What to Test

1. What to Test

I have bad memory, so usually when I find something nice I write it in some note taking app. But I don't like needing to have some app open that I'm not using most of the time and when searching most of the note apps are not good to search by keyword.


So last year I implemented two simple shell scripts one to remember a note(remember) and another to search for some keyword in all my notes(remindme).


We will be using these scripts as backend so the UIs that will be implement only need to have their necessary UI construction code.


Now I present the code and structure for these scripts:

Remember

The objective of the remember script is to allow me to just type remember 'Found cool tech - www.tec.com' and store the note.


It receives a string and stores it in a file. If the user does not supply any argument, the program will wait for the user input and will store the note when Ctrl + D is pressed.

{remember.sh 1}
#!/bin/bash
# remember -- An easy command line based reminder pad

{Remember File, 1}

{If No Arguments, 1}
    # Prompt the user for input and append to the rememberfile whatever they wrote.
    echo "Enter note, end with ^D: "
    cat - >> $rememberfile
else
    # Send any arguments passed to the script into the remeberfile.
    echo $@ >> $rememberfile
fi

exit 0

Remindme

The objective of the remindme command is to filter and display notes taken with the remember command.


It verifies if the rememberfile already exists and displays a warning if not. If the user passed arguments when calling the script it will filter lines in the remember file according to the keywords. If no arguments were passed it displays all the file.

{remindme.sh 1}
#!/bin/bash

# remindme -- Searches a data file for matching lines or,
# if no argument is specified, shows the entire contents of the data file

{Remember File, 1}

if [ ! -f $rememberfile ] ; then
    echo "$0: You don't seem to have a .remember file." >&2
    echo "To remedy this, please use 'remember' to add reminders" >&2
    exit 1
fi

{If No Arguments, 1}
    # Display the whole rememberfile when not given any search criteria.
    more $rememberfile
else
    # Otherwise, search through the file for the given terms, and display the results neatly
    grep -i -- "$@" $rememberfile | ${PAGER:-more}
fi

exit 0

The remember file will be an hidden file called .remember in the current user personal directory.

{Remember File 1}
rememberfile="$HOME/.remember"

Used in section 1

Validation to check if no arguments were received.

{If No Arguments 1}
if [ $# -eq 0 ] ; then

Used in section 1


Next Chapter