From 5dd0c7ce9f665454a87af35f85921abfc6d719cb Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 29 May 2024 20:31:08 +0200 Subject: [PATCH] Improved list-memos.ps1 and remember.ps1 --- scripts/list-memos.ps1 | 35 ++++++++++++++++------------------- scripts/remember.ps1 | 16 ++++++++++------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/scripts/list-memos.ps1 b/scripts/list-memos.ps1 index c94745f5..46e0c83d 100755 --- a/scripts/list-memos.ps1 +++ b/scripts/list-memos.ps1 @@ -1,8 +1,8 @@ <# .SYNOPSIS - Lists your memo entries + Lists your remembered entries .DESCRIPTION - This PowerShell script lists all memo entries in Memos.csv in your home folder. + This PowerShell script lists all entries in 'Remember.csv' in your home folder. .EXAMPLE PS> ./list-memos.ps1 .LINK @@ -11,26 +11,23 @@ Author: Markus Fleschutz | License: CC0 #> - try { - $Path = "~/Memos.csv" - if (Test-Path "$Path" -pathType leaf) { - write-progress "Reading $Path ..." - $Table = Import-CSV "$Path" - write-progress -completed "Reading $Path" - - "" - "Time Text" - "---- ----" - foreach($Row in $Table) { - $Time = $Row.Time - $Text = $Row.Text - "$Time $Text" - } - } else { - "Sorry, no memos saved yet" + $path = "~/Remember.csv" + if (-not(Test-Path "$path" -pathType leaf)) { + "Nothing to remember." exit 1 } + + Write-Progress "Reading $path ..." + $table = Import-CSV "$path" + Write-Progress -completed "Done." + + foreach($row in $table) { + $unixTimestamp = [int64]$row.TIMESTAMP + $time = (Get-Date -day 1 -month 1 -year 1970 -hour 0 -minute 0 -second 0).AddSeconds($unixTimestamp) + $text = $row.TEXT.trim() + "⚠️ NOTE: $text (remembered $time)" + } exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/scripts/remember.ps1 b/scripts/remember.ps1 index a5093775..12f0df21 100755 --- a/scripts/remember.ps1 +++ b/scripts/remember.ps1 @@ -2,12 +2,12 @@ .SYNOPSIS Remembers a text .DESCRIPTION - This PowerShell script saves the given text to Memos.csv in your home folder. + This PowerShell script saves the given text to 'Remember.csv' in your home folder. .PARAMETER text1 Specifies the text to memorize .EXAMPLE PS> ./remember.ps1 "Buy apples" - ✔️ Saved to /home/Markus/Memos.csv in 0s. + ✔️ Saved to /home/Markus/Remember.csv in 0s. .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -20,13 +20,17 @@ try { if ($text1 -eq "") { $text1 = Read-Host "Enter what needs to be remembered" } $stopWatch = [system.diagnostics.stopwatch]::startNew() - $timestamp = Get-Date -format FileDateTimeUniversal - $path = "~/Memos.csv" + + [string]$timestampString = Get-Date -UFormat %s + $timestampString = $timestampString -replace ',','.' + [int64]$unixTimestamp = $timestampString + + $path = "~/Remember.csv" if (-not(Test-Path "$path" -pathType leaf)) { - Write-Output "TIME,TEXT" > $path + Write-Output "TIMESTAMP,TEXT" > $path } - Write-Output "$($timestamp),$text1 $text2 $text3" >> $path + Write-Output "$($unixTimestamp),$text1 $text2 $text3" >> $path $path = Resolve-Path $path [int]$elapsed = $stopWatch.Elapsed.TotalSeconds