Skip to content

Instantly share code, notes, and snippets.

@AviDuda
Last active October 29, 2016 15:01
Show Gist options
  • Save AviDuda/aaca171bf4b12ac9a23240b1e74e9233 to your computer and use it in GitHub Desktop.
Save AviDuda/aaca171bf4b12ac9a23240b1e74e9233 to your computer and use it in GitHub Desktop.
Daily journal helper
# Script for keeping a daily journal.
#
# Expected file structure:
#
# template.txt
# bin
# journal.ps1
# journal
# {year}
# {month}
# {year}-{month}-{day}.txt
#
# Set the $EDITOR environment variable to your preferred editor.
#
# Run like this:
# journal [-Days=<int>] [-When <DateTime>]
# Examples:
# journal -When 2016-10-28 (or just journal 2016-10-28) - opens the journal for the specified day
# journal -1 - opens the journal for yesterday
param (
# Add or remove days from the specified date
[Parameter()]
[Int]
$Days = 0
,
# Date of the journal entry as YYYY-MM-DD, default today
[Parameter()]
[DateTime]
$When = (Get-Date)
)
$ErrorActionPreference = "Stop"
$When = $When.AddDays($Days)
$Folder = $When.ToString("yyyy\\MM")
$File = "$($When.ToString('yyyy-MM-dd')).txt"
$Location = "$PSScriptRoot\..\journal\$Folder\$File"
Write-Host Current journal: $Location
if (! (Test-Path $Location)) {
Write-Host Creating a new journal...
New-Item -Force $Location | Out-Null
Copy-Item "$PSScriptRoot\..\template.txt" $Location | Out-Null
}
Write-Host Running editor...
& $Env:EDITOR $Location
# PLAN
-
# REALITY
-
# SUMMARY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment