# Define a bash command to open a daily notes file
Sun Jan 10 2021
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
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
NOTESvariable. - 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
TODAYexists in theNOTESdirectory. - If it does not yet exist, use
sedto replace the word "TODAY" in the template file with the current date and output it into a new file calledTODAY. - 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
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.
Thank you for reading my blog! If you enjoyed this post, you're welcome to subscribe via RSS here (opens new window) (I can recommend NetNewsWire on iOS).