Skip to content

Instantly share code, notes, and snippets.

@RyanParsley
Last active April 9, 2024 13:45
Show Gist options
  • Save RyanParsley/12bb343c091e7dc167004bac7f4b295c to your computer and use it in GitHub Desktop.
Save RyanParsley/12bb343c091e7dc167004bac7f4b295c to your computer and use it in GitHub Desktop.
A nushell script to create a daily markdown note in a set directory. The full directory structure may not exist before running.
#!/usr/bin/env nu
# Set this to the root of your notes.
# Something like: "/Users/username/notes"
let note_dir = ""
let daily_dir = "journal/daily"
let current_year = (date now | format date "%Y")
let month_dir = (date now | format date "%m-%B")
let filename = (date now | format date "%Y-%m-%d.md")
let path = [$note_dir, $daily_dir, $current_year, $month_dir] | str join "/"
let absolute_file = [$path, $filename] | str join "/"
# This assures file creation works if the directory is incomplete.
# That would commonly happen at the beginning of years and each month.
mkdir $path
# TODO: Replace `touch` with template driven file creation
if not ($absolute_file | path exists) {
touch $absolute_file
}
nvim $absolute_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment