# Define a bash command to open a daily notes file

I love taking notes and want to start keeping a separate note per work day. To make it quick to create and open such a note each day, I wanted to create a Bash function today.

I created a template note in which I wanted "TODAY" to be replaced with the current day's date:

# TODAY Planning and Review

## Motivation/Inspiration

## Meetings

## Tasks

## TODO

## TIL (Today I Learned)
1
2
3
4
5
6
7
8
9
10
11

Then I defined a command that:

  • Stores the directory in which I want to store notes in the NOTES variable.
  • Formats today's date in the format %Y-%m-%d, e.g. 2020-12-02, and stores it in a variable, TODAY.
  • Check whether a file with the name TODAY exists in the NOTES directory.
  • If it does not yet exist, use sed to replace the word "TODAY" in the template file with the current date and output it into a new file called TODAY.
  • Open the new (or existing) file called TODAY.
today() {
  NOTES="/home/username/daily-notes/"
  TODAY=`date +%Y-%m-%d`
  FILE="$NOTES/$TODAY.md"
  if ! [[ -f "$FILE" ]]; then
    sed  -e "s/TODAY/$TODAY/g" "$NOTES/template.md" > "$FILE"
  fi
  vim "$FILE"
}
1
2
3
4
5
6
7
8
9

I added to function to my /.zshrc file so that I can run today from anywhere in my terminal.

Last Updated: 4/14/2021, 10:41:39 AM