Skip to content

Instantly share code, notes, and snippets.

@mjnbrn
Last active March 5, 2022 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjnbrn/c3548991b15af555af12a08bfaf1b8bf to your computer and use it in GitHub Desktop.
Save mjnbrn/c3548991b15af555af12a08bfaf1b8bf to your computer and use it in GitHub Desktop.
I am Grateful that I am not Normal

But Why

A friend of mine recently mentioned practicing Gratitude. The idea stuck with me, but I'm not capable of not over-complicating things.

SO, I wrote this little script that just logs things I'm grateful for as I think of them. Because life's too short (Fuck if that isn't my new catchphrase) to dwell on what makes you unhappy.

Usage

Call gratitude.ps1. You can either pass it an array of strings to populate new data (AND SEE IT RETURNED TO THE SCREEN [SO FANCY {WOW}]) OR pass it nothing to print your whole list of gratefuls.

(base) PS C:\code> .\gratitude.ps1 "Coheed & Cambria","soap"

2022-03-05T00:22-05:00 - Coheed & Cambria
2022-03-05T00:22-05:00 - soap
(base) PS C:\code>
(base) PS C:\code> .\gratitude.ps1                          

2022-03-05T00:09-05:00 - mechanical keyboads
2022-03-05T00:09-05:00 - anime
2022-03-05T00:09-05:00 - freckles
2022-03-05T00:10-05:00 - weighted blankets
2022-03-05T00:10-05:00 - long sleeves
2022-03-05T00:10-05:00 - tacos
2022-03-05T00:22-05:00 - Coheed & Cambria
2022-03-05T00:22-05:00 - soap
(base) PS C:\code>

Parting Notes

I am prone to overcomplicating things. This is one example. Anyway, I hope this helps you like I want it to help me.

param (
[string[]]$Gratefuls
)
begin {
$Gratefile = "C:\code\grateful.log"
if (-not (Test-Path $Gratefile)) {
$null = New-Item -ItemType file -Path $Gratefile -Force
}
$Timestamp = (Get-Date -Format "yyyy-MM-ddTHH:mmzzzz")
}
process {
if ($Gratefuls) {
$gcount = $Gratefuls.Count
foreach ($Grateful in $Gratefuls) {
Add-content -Path $Gratefile -Value "$Timestamp - $Grateful"
}
}
}
end {
if ($Gratefuls) { Get-content $Gratefile | Select-Object -last $gcount } else { Get-content $Gratefile }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment