Skip to content

Cookbook

The cookbook includes a wide range of examples of Espanso matches, all of which can be copied or adapted. It contains over 110 matches, which range from simple to advanced. Some of the matches have been adapted from examples found online. I have included links to the original source, which usually include a relevant discussion thread.

Cookbook of Espanso matches

Contents

The contents of the EspansoEdit cookbook have been reproduced online here in response to requests from Espanso users on macOS who are unable to run EspansoEdit. The code blocks are rendered with Shiki based on a YAML language grammar. This does not provide the full range of Espanso-specific highlighting that is shown in EspansoEdit.

  1. Espanso essentials
    1.1 Basic examples
    1.2 Regex triggers
    1.3 Tips and tricks

  2. Extensions
    2.1 Choice
    2.2 Date and time
    2.3 Forms

  3. Web related
    3.1 Email
    3.2 HTML and Markdown
    3.3 Outlook

  4. Script and Shell
    4.1 PowerShell inline
    4.2 PowerShell anchors
    4.3 CMD batch files

1. Espanso essentials

1.1 Basic examples

# EspansoEdit 1.4.5 Cookbook - 1.1 Basic examples
matches:
# Personal
- trigger: ':fn'
replace: 'forename middlename surname'
- trigger: ':adr'
replace: 'address'
- trigger: ':eml'
# Use a word trigger as the next trigger starts with the same letters
replace: 'email address'
word: true
- trigger: ':emla'
replace: 'email address alternate'
- triggers: [':tel', ':cell']
# Multiple triggers can be used to expand a match
replace: 'phone number'
# Search engine queries
- trigger: ':ddg'
replace: 'https://duckduckgo.com/?q='
- trigger: ':ggl'
replace: 'https://google.com/search?q='
- triggers: ':wiki'
replace: 'https://en.wikipedia.org/w/?search='
- trigger: ":yt"
# Insert clipboard content as query term
replace: https://youtube.com/results?q={{clipb}}'
vars: [{ name: "clipb", type: "clipboard"}]
# Miscellaneous
- trigger: ':ax'
# Enter :ax to expand in lower case and :AX to expand in capitals
replace: 'anaphylaxis'
propagate_case: true
word: true
- trigger: "committment"
# Use match to correct a word that you sometimes misspell
replace: "commitment"
- trigger: ':gom'
replace: 'git push origin main'
- trigger: ':gmo'
replace: 'git pull origin main'
- trigger: ':ip'
replace: '{{output}}'
vars:
- name: output
type: shell
params:
cmd: "curl 'https://api.ipify.org'"
- trigger: ':weather'
replace: '{{output}}'
vars:
- name: output
type: shell
params:
cmd: "curl 'http://wttr.in/?format=3'"

1.2 Regex triggers

# EspansoEdit 1.4.5 Cookbook - 1.2 Regex triggers
# NB A Regex trigger cannot exceed 30 characters in length
matches:
- regex: "(?P<month>\\d{2})/(?P<day>\\d{2})/(?P<year>\\d{2})"
# Enter trigger of type 24/11/24
replace: "Date: {{year}}-{{month}}-{{day}}"
- regex: "(?P<user>[a-z0-9._%+-]+)@(?P<domain>[a-z0-9.-]+)\\.(?P<tld>[a-z.]{5,})"
# Enter trigger of type alex@isp.com.au
replace: "User: {{user}}\nDomain: {{domain}}\nTLD: {{tld}}"
- regex: "class-(?P<cat>[a-z]+)-(?P<typ>[a-z]+)-(?P<dat>\\d+)"
# Enter trigger of type class-fiction-romantic-2023
replace: "Classification category: {{cat}}; type: {{typ}}; year: {{dat}}"
- regex: :hor(?P<hor>\d+)ver(?P<ver>\d+)\D
# Enter trigger of type :hor10ver20
# \D looks for any non-digit character to terminate the string
replace: 'Length of horizontal axis = {{hor}} cm; length of vertical axis = {{ver}} cm'
- regex: (?P<word>\S+)\s+(?P<punct>[.,;:!?])
# Removes spaces between a word and a punctuation sign
# From https://github.com/espanso/espanso/issues/1727
replace: "{{word}}{{punct}} "
- regex: "vbl\\((?P<vbl>.*?)\\)"
# Enter trigger of type vbl(xyz) followed by space
replace: "This example uses variable type {{vbl}}."
word: true
- regex: :04(?P<gp1>\d{2})(?P<gp2>\d{3})(?P<gp3>\d{3})
# Reformat an Australian mobile number with trigger of type :0444444444
replace: "04{{gp1}} {{gp2}} {{gp3}}"
- regex: :hor(?P<hor>\d+)ver(?P<ver>\d+)\D
# Enter trigger of type :hor10ver20
# \D looks for any non-digit character to terminate the string
replace: 'Length of horizontal axis = {{hor}} cm; length of vertical axis = {{ver}} cm'
- regex: ":(?P<num>\\d*)\\s*usd" # US Dollar
# Enter trigger of type :33usd
# From https://discord.com/channels/884163483409731584/1013914627886817372/1262267355438907477
replace: "${{num}}"
- regex: ":(?P<num>\\d*)\\s*euro" # Euro
replace: "{{num}}€"
- regex: ":(?P<num>\\d*)\\s*ukp" # British Pound
replace: "£{{num}}"
- regex: ":(?P<num>\\d*)\\s*yen" # Japanese Yen
replace: "{{num}}¥"
- regex: ":(?P<num>\\d*)\\s*inr" # Indian Rupee
replace: "{{num}}?"
- regex: ":(?P<num>\\d*)\\s*swf" # Swiss Franc
replace: "{{num}} CHF"
- regex: ":(?P<num>\\d*)\\s*aud" # Australian Dollar
replace: "AU${{num}}"
- regex: ":(?P<num>\\d*)\\s*cad" # Canadian Dollar
replace: "CA${{num}}"
- regex: ":(?P<num>\\d*)\\s*hkd" # Hong Kong Dollar
replace: "HK${{num}}"
- regex: ":(?P<num>\\d*)\\s*nzd" # New Zealand Dollar
replace: "NZ${{num}}"
- regex: ":(?P<num>\\d*)\\s*won" # South Korean Won
replace: "{{num}}?"

1.3 Tips and tricks

# EspansoEdit 1.4.5 Cookbook - 1.3 Tips and tricks
# To prevent a trigger from expanding press the right arrow key after the first character
# The cursor will not move and the trigger can then be entered without expanding
# Tip source: https://discord.com/channels/884163483409731584/1013916990760554608/1231263840445141002
matches:
- {trigger: abc, replace: def, word: true}
# A match can be entered on a single line using YAML flow style
- trigger: ':ttxt1'
# Comments below the trigger will fold correctly with EspansoEdit code folding
replace: 'rtxt1'
- trigger: ':ttxt2' # Comments on the same line as the trigger also fold correctly
replace: 'rtxt2'
- trigger: ':ttxt3'
replace: 'rtxt3'
# Comments above the trigger will fold with the previous trigger
- trigger: ':ttxt4'
replace: 'rtxt4'
- trigger: ':iata'
# Labels can be used to create a menu of choices in the Espanso search bar
replace: LHR (London Heathrow Airport)
label: 1. London Heathrow
- trigger: ':iata'
replace: SYD (Sydney Kingsford-Smith Airport)
label: 2. Sydney Kingsford-Smith
- trigger: ':iata'
replace: SIN (Singapore Changi Airport)
label: 3. Singapore Changi
- trigger: ":smile"
# Use match to create shortcut for an emoji
replace: "??"

2. Extensions

2.1 Choice

# EspansoEdit 1.4.5 Cookbook - 2.1 Choice extension
# The global_vars section can be added to any YML file(s)
# Variables in this section are available globally
global_vars:
- name: genre
type: echo
params:
echo: |
Animation
Biography
Musical
matches:
- trigger: ":film"
form: |
[[choices]]
form_fields:
choices:
type: choice
values: "{{genre}}"
- trigger: :em
# From smeech at https://www.reddit.com/r/espanso/comments/1gkd8ip/what_am_i_missing/
replace: "{{output}}"
vars:
- name: output
type: choice
params:
values:
- label: 1. Gmail
id: xxx@gmail.com
- label: 2. Outlook
id: xxx@outlook.com
- trigger: ':quote'
# Example of use of choice extension
replace: '{{output}}'
vars:
- name: output
type: choice
params:
values:
- 'Every moment is a fresh beginning.'
- 'Everything you can imagine is real.'
- 'Whatever you do, do it well.'
- trigger: :cb3
replace: "First choice:{{output1}}; second choice:{{output2}}; third choice: {{output3}}"
vars:
- name: output1
type: choice
params:
values: [a, b, c]
- name: output2
type: choice
params:
values: [d, e, f]
- name: output3
type: choice
params:
values: [g, h, i]
- trigger: ':f1'
html: |
You voted <span style='color: #318CE7; text-transform:uppercase'>
{{form1.vote}}</span><br>Thanks for your vote!
vars:
- name: 'form1'
type: form
params:
layout: 'Your choice: [[vote]]'
fields:
vote:
type: list
values:
- Yes
- No
- Other
- trigger: ':f3'
form: |
[[choices]]
form_fields:
choices:
type: list
values:
- Yes
- No
- Other

2.2 Date and time

# EspansoEdit 1.4.5 Cookbook - 2.2 Date and time
matches:
- trigger: ':dat'
replace: '{{mydate}}'
vars:
- name: mydate
type: date
params:
format: '%d/%m/%y'
- trigger: ':tim'
replace: '{{time}}'
vars:
- name: time
type: date
params:
format: '%H:%M'
- trigger: ':now'
replace: "It is now {{mytime}}"
vars:
- name: mytime
type: date
params:
format: '%H.%M'
- trigger: ':tdf'
replace: '{{today}}'
label: 'Date today forwards'
vars:
- name: today
type: date
params:
format: '%-e/%-m/%y'
- trigger: ':tdb'
replace: '{{today}}'
label: 'Date today backwards'
vars:
- name: today
type: date
params:
format: '%y%m%d'
- trigger: ':tdx'
replace: '{{today}}'
label: 'Date today forwards expanded'
vars:
- name: today
type: date
params:
format: '%a %-e %b %Y'
- trigger: ":tdto"
# Expanded example: 2024-11-14 17:23:55 UTC+11:00
replace: "{{mydate}}"
label: 'Date and time with timezone offset'
vars:
- name: mydate
type: date
params:
format: "%F %T UTC%:z"
- trigger: ':tmw'
replace: 'tomorrow'
word: true
- trigger: ':tmwf'
replace: '{{mytime}}'
vars:
- name: mytime
type: date
params:
format: '%x'
offset: 86400 # The offset parameter must be specified in seconds
- trigger: ':yd'
replace: 'yesterday'
word: true
- trigger: ':ydf'
replace: '{{mytime}}'
vars:
- name: mytime
type: date
params:
format: '%x'
offset: -86400

2.3 Forms

# EspansoEdit 1.4.5 Cookbook - 2.3 Forms
matches:
- trigger: ":greet"
form: |
Hi. My name is [[name]] and my email address is [[email]].
Please send me a message if you need any further details.
- trigger: :mvt
# Input arrows from a dropdown with arrows specified in Unicode
form: "[[arrows]]"
form_fields:
arrows:
type: choice
values:
- "\u2190"
- "\u2191"
- "\u2192"
- "\u2193"
default: "\u2190"
- trigger: ':f2'
markdown: |
**{{form1.vote}}**
vars:
- name: 'form1'
type: form
params:
layout: '[[vote]]'
fields:
vote:
type: list
values:
- 1
- Yes
- 2
- No
- 3
- Other
- trigger: ':fmix'
replace: |
Name: {{form1.name}}
Gender: {{form1.gender}}
vars:
- name: 'form1'
type: form
params:
layout: |
What is your name?: [[name]]
What is your gender?: [[gender]]
fields:
gender:
type: list
values:
- Male
- Female
- Other

3.1 Email

# EspansoEdit 1.4.5 Cookbook - 3.1 Email
matches:
- regex: ':em(;|a)'
# Enter :em; to display a menu of email addresses in the Espanso search bar
# Or enter a trigger such as :ema to expand a single email address directly
replace: 'alex@contacts.com'
- regex: ':em(;|b)'
replace: 'blake@contacts.com'
- regex: ':em(;|c)'
replace: 'chris@contacts.com'
- trigger: ':sig'
replace: |
My name
My personal blog: https://mydomain.com/
_.~"~._.~"~._.~"~._.~"~._
word: true
- trigger: ':sig2'
# Signature from image file
image_path: '$CONFIG/img/signature.png'
- trigger: ':soc'
replace: "Twitter: @mydomain\nFacebook: https://www.facebook.com/mydomain\nLinkedIn: https://www.linkedin.com/in/mydomain"

3.2 HTML and Markdown

# EspansoEdit 1.4.5 Cookbook - 3.2 HTML and Markdown
matches:
- trigger: ':bold'
replace: '<b>$|$</b>'
- trigger: ':br'
replace: '<br />'
- trigger: ':div'
replace: '<div>$|$</div>'
- trigger: ':fraction'
replace: '<sup>$|$</sup>&frasl;<sub></sub>'
- trigger: ':h1'
replace: '<h1>$|$</h1>'
- trigger: ':h2'
replace: '<h2>$|$</h2>'
- trigger: ':h3'
replace: '<h3>$|$</h3>'
- trigger: ':hr'
replace: '<hr />'
- trigger: ':img'
replace: "<img src=\"$|$\" alt=\"\" />"
- trigger: ":link"
# Create HTML link using URL from clipboard
replace: "<a href=\"{{clipb}}\" />$|$</a>"
vars:
- name: "clipb"
type: "clipboard"
- trigger: ':list'
replace: "<ol>\n <li>$|$"
- trigger: ':para'
replace: '<p>$|$</p>'
- trigger: ':span'
replace: '<span>$|$</span>'
- trigger: ':sub'
replace: '<sub>$|$</sub>'
- trigger: ':sup'
replace: '<sup>$|$</sup>'
- trigger: ':mdcb'
# Insert a Markdown code block
replace: "```\n$|$\n```"
- trigger: ':mdlnk'
# Create Markdown link using URL from clipboard
replace: "[$|$]({{clipb}})"
vars:
- name: "clipb"
type: "clipboard"
- regex: ':ml(?P<page>.*?):'
# Create Markdown link to page on your domain
# Enter trigger of type :mlpage:
replace: "[{{page}}](https://mydomain.com/{{page}})"
- trigger: ':md2txt'
# Convert Markdown to plain text
# Adapted from https://discord.com/channels/884163483409731584/1013902954350248008/1304173862820511784
replace: "{{output}}"
vars:
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
# Function to convert Markdown to plain text
function Convert-MarkdownToText {
param (
[string]$markdown
)
# Split the input into lines to process each line individually
$lines = $markdown -split "`n"
$inCodeBlock = $false
$plainTextLines = $lines | ForEach-Object {
# Toggle code block flag when encountering ``` lines
if ($_ -match '^\s*```') {
$inCodeBlock = -not $inCodeBlock
# Skip the ``` lines themselves
return
}
# Capture content without modification if in a code block
if ($inCodeBlock) {
return $_
}
# Process each line for Markdown syntax if not in a code block
$_ -replace '^\s*#{1,6}\s*(.+)$', '$1' | # Headers
ForEach-Object { $_ -replace '\*\*([^\*]+)\*\*', '$1' } | # Bold
ForEach-Object { $_ -replace '\*([^\*]+)\*', '$1' } | # Italic
ForEach-Object { $_ -replace '__(.+?)__', '$1' } | # Bold underline
ForEach-Object { $_ -replace '_(.+?)_', '$1' } | # Italic underline
ForEach-Object { $_ -replace '\[([^\]]+)\]\([^\)]+\)', '$1' } | # Links
ForEach-Object { $_ -replace '!\[([^\]]*)\]\([^\)]+\)', '$1' } | # Images
ForEach-Object { $_ -replace '`(.+?)`', '$1' } | # Inline code
ForEach-Object { $_ -replace '``(.+?)``', '$1' } | # More inline code
ForEach-Object { $_ -replace '^\s*[-\*\+]\s+', '' } | # Unordered list markers
ForEach-Object { $_ -replace '^\s*\d+\.\s+', '' } | # Ordered list markers
ForEach-Object { $_ -replace '^\s*>\s+', '' } | # Blockquotes
ForEach-Object { $_ -replace '\[\[([^\]]+)\]\]', '$1' } # [[Text]]
}
# Join the processed lines back into a single string
$plainText = ($plainTextLines -join "`n").Trim()
return $plainText
}
# Convert input from Markdown to plain text
$markdownText = Get-Clipboard
$plainText = Convert-MarkdownToText -markdown $markdownText
Write-Output $plainText

3.3 Outlook

# EspansoEdit 1.4.5 Cookbook - 3.3 Outlook
matches:
# Outlook search filter shortcuts
- regex: ':ol(;|b)'
replace: 'body:'
label: 'Outlook body'
- regex: ':ol(;|f)'
replace: 'from:'
label: 'Outlook from'
- regex: ':ol(;|ha)'
replace: 'hasattachment:true'
label: 'Outlook has attachment'
- regex: ':ol(;|hf)'
replace: 'hasflag:true'
label: 'Outlook has flag'
- regex: ':ol(;|s)'
replace: 'subject:'
label: 'Outlook subject'
- regex: ':ol(;|t)'
replace: 'to:'
label: 'Outlook to'
# Other Outlook shortcuts
- regex: ':ol(;|tf)'
# Replace MyUserName with your actual username
replace: '{{output}}'
label: 'Open Outlook template folder'
vars:
- name: output
type: shell
params:
cmd: "start \"C:\\Users\\MyUserName\\AppData\\Roaming\\Microsoft\\Templates\\\""
- trigger: ':olevent'
# Run PowerShell script to add an Outlook event
replace: '{{output}}'
vars:
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
# Adapted from https://stackoverflow.com/questions/54926561
$outlook = new-object -com outlook.application
$CalItem = "1"
$newAppt = $outlook.CreateItem($CalItem)
$newAppt.Body = "Test text from EspansoEdit 1.4.5 Cookbook using PowerShell"
$newAppt.Subject = "Test event from EspansoEdit 1.4.5 Cookbook"
$DateString = Get-Date
$newAppt.Start = $DateString
$newAppt.AllDayEvent = 1
$newAppt.ReminderSet = 0
$newAppt.BusyStatus = 0
$newAppt.Save()

4. Script and Shell

4.1 PowerShell inline

# EspansoEdit 1.4.5 Cookbook - 4.1 PowerShell inline scripts
matches:
- trigger: ':wex'
# Run Windows Explorer
replace: "{{output}}"
vars:
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- Start-Process -FilePath "c:\windows\explorer.exe"
- trigger: ':dato'
# Output today's date in ordinal format Friday November 1st 2024
# Function adapted from: https://stackoverflow.com/questions/38177219/
replace: '{{output}}'
vars:
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
function Get-DaySuffix {
Param([System.DateTime]$date)
switch ($date.Day) {
{$_ -in 1,21,31} { 'st'}
{$_ -in 2,22} { 'nd'}
{$_ -in 3,23} { 'rd'}
Default {'th'}
}
}
$d = (Get-Date).AddDays(0)
$ds = Get-DaySuffix $d
"{0} {1:MMMM} {2}{3} {4}" -f $d.DayOfWeek, $d, $d.Day, $ds, $d.Year
- regex: (?P<count>[+]\d+)(?P<unit>[n])
# Output clipboard text n times with numbering
# Trigger is of type +3n
replace: "{{output}}"
vars:
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
$raw = Get-Clipboard
1..{{count}} | ForEach-Object {Write-Host "$raw" $_.ToString().PadLeft(2, '0') -separator ''}
- trigger: ":e2new"
# Use a form as a basic GUI to add a new match to a match file
# Adapted from https://www.reddit.com/r/espanso/comments/smrtvi/basic_add_snippet_gui_using_espanso/
replace: "{{output}}"
vars:
- name: 'form1'
type: form
params:
layout: |
Add a new match
Trigger [[trig]]
Replace [[repl]]
Word [[word]]
fields:
word:
type: list
values: |
true
false
default: 'false'
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
$trig = '{{form1.trig}}'
$repl = "{{form1.repl}}"
$word = "{{form1.word}}"
"`n` - trigger: $trig`n` replace: $repl`n` word: $word" `
| Out-File -FilePath $env:APPDATA\\espanso\\match\\base.yml `
-Append -Encoding Utf8
- trigger: :getnum
# Example of use of a trigger with Excel automation
# A form is used to prompt for client name
# The name is then matched in a spreadsheet and client file number is obtained
replace: "{{output}}"
vars:
- name: "form1"
type: form
params:
layout: |
Client name: [[cname]]
- name: output
type: script
params:
args:
- C:\Program Files\PowerShell\7\pwsh.exe
- -Command
- |
$raw = "{{form1.cname}}"
$Excel = New-Object -ComObject Excel.Application
$Workbook = $Excel.Workbooks.Open('c:\YourPath\YourSpreadsheet.xlsx')
$WorkSheet = $Workbook.Sheets.Item(IndexOfYourWorksheet)
$Found = $WorkSheet.Cells.Find($raw)
# Next line applies if file number is in next column
$FileNum = $WorkSheet.Cells($Found.Row, $Found.Column + 1)
Write-Host "Client name:" $raw "; client file number:" $FileNum.Value()

4.2 PowerShell anchors

# EspansoEdit 1.4.5 Cookbook - 4.2 Powershell anchor scripts
# These scripts make use of YAML anchors and aliases
# The keywords anchors: and anchor: are arbitrary
# It is essential to use & to denote an anchor and * to reference an anchor
anchors:
- anchor: &datemath |
switch ("{{unit}}") {
"d" { $date = (Get-Date).AddDays({{offset}}).ToString("dd/MM/yy") }
"w" { $date = (Get-Date).AddDays({{offset}} * 7).ToString("dd/MM/yy") }
"m" { $date = (Get-Date).AddMonths({{offset}}).ToString("dd/MM/yy") }
"y" { $date = (Get-Date).AddYears({{offset}}).ToString("dd/MM/yy") }
}
Write-Output $date
- anchor: &e2log |
# Output Espanso log
$e2 = 'C:\Users\Cam\AppData\Local\Programs\Espanso\espansod.exe'
&$e2 log | Out-File -FilePath $env:TEMP\tmp.log
$Array = Get-Content -Path $env:TEMP\tmp.log
[array]::Reverse($Array)
$Length = $Array.count
$Line = 1
$1..$Length | ForEach-Object {$Array[-$Line]; $Line++}
- anchor: &e2log10 |
# Output last 10 lines of Espanso log
$Array = Get-Content -Path $env:LocalAppData\espanso\espanso.log -Tail 10
$Length = $Array.count
$Line = 1
$1..$Length | ForEach-Object {$Array[-$Line]; $Line++}
# An anchor can be used to reference a file containing a PowerShell script
# Here the reference is to a script (not included) used to list installed apps
# Such a script (and more) can be found at https://github.com/fleschutz/PowerShell
- anchor: &listapps |
& d:\temp\ps_listapps.ps1
- anchor: &quotestr |
$raw = Get-Clipboard
Write-Host ("""$raw""")
- anchor: &tempconv |
# Conversion functions from https://github.com/NocTech/Temperature-Converter-PowerShell
function Convert-CelsiusToFahrenheit {
param (
[double]$celsius
)
$fahrenheit = ($celsius * 9/5) + 32
return $fahrenheit }
function Convert-FahrenheitToCelsius {
param (
[double]$fahrenheit
)
$celsius = ($fahrenheit - 32) * 5/9
return $celsius }
$tmp = {{tmp}}
$f = Convert-CelsiusToFahrenheit -celsius $tmp
$f = [math]::Round($f, 2)
$c = Convert-FahrenheitToCelsius -fahrenheit $tmp
$c = [math]::Round($c, 2)
$result = switch ("{{unit}}") {
"c" {Write-Host $tmp{c =}$f{f}; break}
"f" {Write-Host $tmp{f =}$c{c}; break}
default {Write-Host "Correctly formatted entry not detected"; break} }
- anchor: &wordcount |
$filePath = "D:\temp\test.bat"
$stats = Get-Content $filePath | Measure-Object -Word -Line -Character
"Words: $($stats.Words); Lines: $($stats.Lines); Characters: $($stats.Characters)"
matches:
- regex: !datemath (?P<offset>[+-]\d+)(?P<unit>[dwmy])
# Run PowerShell script to perform date arithmetic
# Regex trigger responds to keyboard entries such as -70d or +12w
replace: '{{output}}'
label: Date arithmetic with PowerShell
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *datemath]
- regex: !tempconv (?P<tmp>[+-]\d+)(?P<unit>[cf])
# Run PowerShell script to perform temperature conversion
# Regex trigger responds to keyboard entries such as -3c or +100f
replace: '{{output}}'
label: Temperature conversion with PowerShell
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *tempconv]
- trigger: 'e2log'
# Use shell extension to get Espanso log forwards - latest at bottom
replace: '{{output}}'
word: true
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *e2log]
- trigger: 'e2log10'
# Run PowerShell script to get last 10 lines of Espanso log using shell extension
replace: '{{output}}'
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *e2log10]
- trigger: ':listapps'
replace: '{{output}}'
label: PowerShell test
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *listapps]
- trigger: ':quotestr'
replace: '{{output}}'
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *quotestr]
- trigger: ':wordcount'
replace: '{{output}}'
vars:
- name: output
type: script
params:
args: [C:\Program Files\PowerShell\7\pwsh.exe, -Command, *wordcount]

4.3 CMD batch files

# EspansoEdit 1.4.5 Cookbook - 4.3 CMD batch files
matches:
- trigger: ':inln'
# Example of inline use of batch commands
replace: '{{output}}'
vars:
- name: output
type: shell
params:
cmd: >
cmd /v:on /c
"echo. &
echo ***DIR*** &
echo. &
dir *.*"
- trigger: ':ipc'
# Another example of inline use of batch commands
replace: '{{output}}'
vars:
- name: output
type: shell
params:
cmd: >
cmd /v:on /c
"echo. &
echo ***DIR*** &
echo. &
dir *.* &
echo. &
echo ***IPCONFIG*** &
ipconfig"
- trigger: ':bfm'
# Example of form entry with batch commands
replace: '{{output}}'
vars:
- name: 'form1'
type: form
params:
layout: 'Enter a number with at least 4 digits: [[anum]]'
- name: 'output'
type: 'shell'
params:
cmd: >
cmd /v:on /c
"echo. &
echo ***Last 3 digits of your number*** &
set input={{form1.anum}} &
set result=!input:~-4! & echo !result!"