That’s my new note. I created it with this script, that ChatGPT helped me to create.
Sure! Here’s a script that creates a markdown file with the specified front matter and opens it in your
$EDITOR
. The script ensures the target directory exists by usingmkdir -p
.
#!/bin/bash
# Define the directory and file paths
DIRECTORY="/path/to/notes/$(date +%Y)"
mkdir -p "$DIRECTORY"
FILE="$DIRECTORY/note-$(date +%Y-%m-%d-%H%M%S).md"
# Get the current date and time in the desired formats
CURRENT_DATETIME=$(date +"%Y-%m-%dT%H:%M:%S%z")
CURRENT_DATE=$(date +"%a, %b %d at %H:%M")
# Define the front matter
FRONT_MATTER="+++
title = 'Quick Note from $CURRENT_DATE'
date = \"$CURRENT_DATETIME\"
draft = false
tags = ['note']
+++"
# Create the markdown file with the front matter
echo -e "$FRONT_MATTER\n" > "$FILE"
# Open the file in the user's default editor
${EDITOR:-nano} "$FILE"
Explanation:
Setup Directory and File Paths:
- The directory for the current year is created if it doesn’t exist.
- Define the path for the note file, including a timestamp to ensure unique filenames.
Get Current Date and Time:
CURRENT_DATETIME
gets the current date and time in the format required for the front matter.CURRENT_DATE
gets the current date and time in a more readable format for the title.
Define Front Matter:
- The front matter includes the title, date, draft status, and tags.
Create Markdown File:
- The front matter is written to the new markdown file.
Open the File in Editor:
- The file is opened in the user’s default editor, falling back to
nano
if$EDITOR
is not set.
- The file is opened in the user’s default editor, falling back to
You can customize the DIRECTORY
variable to point to your desired notes location. Save this script and make it executable with chmod +x scriptname.sh
, then run it whenever you need to create a quick note.