Espanso logo - a gradient green to yellow italics I with a wavy symbol over it of the same green to yellow color

Command Line Text Expansion with Espanso by Ed Tobias

Hi folks, this is Ed Tobias AKA Mr. Ed. I’d like to tell you about an open source text expansion app called Espanso. Espanso works a lot like TextExpander, you know, Allison’s second favorite app after Excel? It was created by Federico Terzi, a talented software engineer from Bologna Italy. The app is free, but I did toss a few bucks Federico’s way for all his hard work.

The app has a lot of features that distinguish it from TextExpander, but you have to be willing to tap into your nerdy side to take advantage of them. Just like TextExpander, it replaces trigger text with snippets of text that you define. The difference is that Espanso doesn’t use a GUI-like TextExpander to define your snippets. Instead, it uses a separate text file written using YAML.

Now I know most of you are already experts at writing in YAML since you follow Bart’s PBS series, so I’m sure this chance to put it to practice is already making you giddy.

Before we get started we need to install it first. It runs on MacOS, Windows, and Linux – but unfortunately, there is no current iOS version. If you are a Homebrew user, it is simple to install. Just type

brew install espanso

into your terminal window. If you don’t use brew, you can download the app bundle from espanso.org/…. Once installed, it will create an Espanso folder in your documents directory. Inside the Espanso folder are two other folders, Config and Match. Inside the Match folder is a base.yml file where you store your snippets.

You can edit that file with any app that works with plain text files – I use VS Code myself, but you can use BBEdit, or simply TextEdit. You can add additional files to the Match folder and Espanso will read them all in automatically. This way you can organize your snippets by putting email snippets in an email.yml file, or coding snippets in a code.yml file. As long as they are all in the Match folder, they will be loaded.

To add additional functionality you can precede the file name with an underscore, eg: _code.yml. This prevents Espanso from loading snippets in that file automatically. Why would you want that you ask? Well, that is where the Config folder comes in. You can add a file in the config folder, say vscode.yml and place a specific config YAML in the file,

filter_exec: "Visual Studio Code.app"

extra_includes:
- "../match/_code.yml"

What this does is load the snippets from the _code.yml file, but only when using the VS Code app. This way you don’t have to worry about typing away in an email and suddenly plopping down a glop of code in the middle of your message.

You can also add a file in the Config folder to disable Espanso completely for any app you specify. For example, if you don’t want Espanso to run while using the Terminal app you can place the file terminal.yml in the Config folder and have it contain the YAML,

filter_exec: Terminal
enable: false

This makes sure that Espanso does not run while using the terminal app. By the way, the name of the file could be anything, like fred.yml, as long as it has the proper YAML inside.

In addition to writing your own snippets, you can install packages contributed by other users of Espanso that have specific snippets. These packages can be found on the Espanso hub at hub.espanso.org/….

Some of these packages take advantage of more advanced features of Espanso, like creating variables in the snippets, or issuing shell commands and getting the standard output as the snippet. You can write snippets that offer pull down menus to select your replacement text, or get the current date or time and embed it in the text. The depth of the tool is really amazing if you’re not afraid to get a little nerdy.

So what are you waiting for? Reread Bart’s tutorial on YAML and get started with Espanso.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top