10/23/2018 - 12:44 PM

Logbook Initiation Function #Shell #Ubuntu

Logbook Initiation Function #Shell #Ubuntu

LASTCREATEDFILE="$(date +'%Y-%m-%d')"

touch ~/logbook/$(date '+%Y-%m-%d').md

# Add date to the logbook
OUTPUT="$({ echo "The logbook dates at:"; date +'%Y-%m-%d';} | tr "\n" " ")"

# remove any whitespaces if exist
LINE="$(echo $OUTPUT | xargs)"

# add this to the file
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
sed -i 's/[[:space:]]*$//' $FILE

# Add Instructions to the file (if no exist)

grep -qF -- "$LINE1" "$FILE" || echo "$LINE1" >> "$FILE"

LINE2="1. Consider the problem you’re attempting to solve."
grep -qF -- "$LINE2" "$FILE" || echo "$LINE2" >> "$FILE"

LINE3="2. Describe your method for solving it."
grep -qF -- "$LINE3" "$FILE" || echo "$LINE3" >> "$FILE"

LINE4="3. Describe the process of carrying out the method."
grep -qF -- "$LINE4" "$FILE" || echo "$LINE4" >> "$FILE"

LINE5="4. Record what happened, and ask how it could be improved."
grep -qF -- "$LINE5" "$FILE" || echo "$LINE5" >> "$FILE"

# Open the file
sudo atom ~/logbook/${LASTCREATEDFILE}.md

# The two line way

# echo -n "The logbook dates at: " >> ~/logbook/${LASTCREATEDFILE}.md
# date +'%Y-%m-%d' >>  ~/logbook/${LASTCREATEDFILE}.md