@chopivy, thank you so much for this - I had no idea I could combine Windows PowerShell and espanso in this way until I saw your post. Adding a day of the week calculation for Windows users, following @mitzimbj suggestions above:
# This Monday
- trigger: ":>mon"
word: true
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: (echo "[[$(if([Int] (Get-Date).DayOfWeek.value__ -gt [Int] [DayOfWeek] 'Monday') {(((Get-Date).AddDays(7- ([Int] (Get-Date).DayOfWeek.value__ - [Int] [DayOfWeek] 'Monday'))) | Get-Date -UFormat "%Y-%m-%d")} Else {((Get-Date).AddDays(([Int] [DayOfWeek] 'Monday') - (Get-Date).DayOfWeek.value__) | Get-Date -UFormat "%Y-%m-%d")})]]")
This will return [[2020-07-20]]
Limitations: I wasn’t able to find the equivalent of @mitzimbj’s -v
command for Windows, so I used an if
statement instead. This means that you can’t do a properly formatted link [[2020-07-20 | Monday 20 July, 2020]]
as PowerShell throws an error when you try and open a second pipe | (Get-Date)
inside the if
and else
curly { }
braces. If anyone knows of a more elegant solution, I would love to hear it.
In situations where today is Monday and I want to fast-forward by a week instead (i.e. Monday > Monday) I use the # Next Week
script:
# Next Week
- trigger: ":>w"
word: true
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: (echo "[[$((Get-Date).AddDays(+7) | Get-Date -UFormat "%Y-%m-%d") | $((Get-Date).AddDays(+7) | Get-Date -UFormat "%A %d %B, %Y")]]")
Please feel free to amend and improve.