Espanso Text Expansion

Problem

Repetitive typing of common phrases, code snippets, dates, and signatures wastes time and introduces errors. Need cross-platform text expansion that works in terminal environments.

Solution

Espanso is a cross-platform, open-source text expander using YAML configuration:

# ~/.config/espanso/match/base.yml
 
# Simple replacement
- trigger: ':me'
  replace: 'Chris Sullo | sullo@example.com | 555-867-5309'
 
# Variables (date/time)
- trigger: ':now'
  replace: "It's {{time}}"
  vars:
    - name: time
      type: date
      params:
        format: '%H:%M'
 
# Form prompts
- trigger: ':greet'
  form: |
    Hey $name,
    Happy Birthday!
 
# Regex capture
- regex: ":greet\\((?P<person>.*)\\)"
  replace: "Hey {{person}},\nHappy Birthday!"
 
# Shell commands
- trigger: ':myip'
  replace: '{{output}}'
  vars:
    - name: output
      type: shell
      params:
        cmd: 'curl ifconfig.me'
 
# Base64 encoding via regex + shell
- regex: ":b64\\((?P<val>.*?)\\)"
  replace: '{{output}}'
  vars:
    - name: output
      type: shell
      params:
        cmd: "echo '{{val}}' | base64 | tr -d '\\n'"

Usage

Basic Configuration

# Open config for editing
espanso edit
 
# Restart after changes
espanso restart
 
# Check status
espanso status

Common Patterns

Email signatures:

- trigger: ':sig'
  replace: |
    Best regards,
    {{name}}
    {{title}}
  vars:
    - name: name
      type: echo
      params:
        echo: 'John Doe'
    - name: title
      type: echo
      params:
        echo: 'Senior Engineer'

Date stamps:

- trigger: ':date'
  replace: '{{date}}'
  vars:
    - name: date
      type: date
      params:
        format: '%Y-%m-%d'
 
- trigger: ':ps'
  replace: 'Pentest Status: {{output}}'
  vars:
    - name: output
      type: shell
      params:
        cmd: "date '+%B %d, %Y'"

Clipboard operations:

- trigger: ':paste'
  replace: '{{clipboard}}'
  vars:
    - name: 'clipboard'
      type: 'clipboard'

Trade-offs

When to Use

  • Cross-platform consistency needed (Linux, macOS, Windows)
  • Terminal-centric workflow
  • Shell command integration required
  • Simple YAML configuration preferred

When NOT to Use

  • Key remapping needed (use AutoHotkey)
  • GUI automation required (use PyAutoGUI)
  • Window management (use Hammerspoon)

Comparison with AutoHotkey

FeatureEspansoAutoHotkey
Text expansionSuperior (YAML, forms)Powerful but quirky
Cross-platformYesWindows only
System automationNoneFull (mouse, windows)
External logicShell commandsBuilt-in
ConfigurationYAMLCustom scripting

Source

Extracted from espanso evaluation research.