4 minute read

The Code

Want to skip straight to the good stuff? The Code is here:

Github

Introduction

This is a shorter post to round out 2022. I hope you have enjoyed the launch of the blog thus far.

Text expanders are as simple as the name implies, ways to expand larger amounts of text from smaller inputs. This is handy for accuracy and efficiency in repetitive tasks. Essentially a text expander detects when you type pre-defined words and keystrokes and replaces those with output which can be pre-defined or dynamic.

Espanso

Espanso is an open source, cross-platform, privacy focused text expander.

Privacy and security are paramount when you are installing an application that more or less functions as a key-logger. Espanso is coded in Rust, which I’m not familiar with, so I can’t review the source code and verify the security that way.

Reading the Espanso Security Policy details the applications workings, such as that it only records the 3 most recent keystrokes by default. Combining the aforementioned security policy with the stellar reputation this application has in the open-source community, and my cursory network traffic investigations I am comfortable installing this tool.

Warning Notice: You should always verify these sorts of claims for yourself when installing a tool like this.

Matches

One of the best things about espanso is its simplicity. All you have to do is set up your text snippets and assign them a trigger word or phrase. Then, whenever you type that trigger word or phrase, espanso will automatically insert the corresponding text snippet for you. This can save you a ton of time and effort when you’re typing, especially if you frequently use the same phrases or blocks of text.

Matches are configured in a .yaml file. These files can be found in the espanso path. After installation you can view your path by running

espanso path

You will get something along these lines on macOS for example

Config: /Users/username/Library/Application Support/espanso
Packages: /Users/username/Library/Application Support/espanso/match/packages
Runtime: /Users/username/Library/Caches/espanso

In ‘Application Support/espanso/matches’ lives base.yml This is where all your matches live. You can edit this file to add matches as you see fit. Espanso will load all config files in the matches directory so you can break up your configuration into multiple files, such as code-snippets.yml, markdown.yml etc.

I’ve uploaded my config here and will detail some of my favourite matches.

:tkv this is one of my favourites. During the course of my employment I have to frequently add the tag //TICKET#(Number)// to my work. I cannot underestimate how valuable this shortcut is. The configuration looks like this:

 # Add Ticket format
   # With clipboard
  - trigger: ":tkv"
    replace: "//TICKET#{{clipboard}}//"
    vars:
      - name: "clipboard"
        type: "clipboard"

In this match, {{clipboard}} uses espanso built in clipboard support to automatically input the data from the clipboard. In this case the output would look something like this //TICKET#123456//. It’s great to be able to grab a ticket and add the format wherever needed.

Espanso is pretty clever and is not limited to just text for text replacement. For example, it can provide output from an OS shell as a replacement for a match; Here is some example config that allows a match to output your WAN IP address by calling an API with curl:

   # Outputs public IP address
  - trigger: ":ip"
    replace: ""
    vars:
      - name: output
        type: shell
        params:
          cmd: "curl 'https://api.ipify.org'"

These are just some small examples that provide a glimpse into the possibilities. My linked config has more.

Extra Tips

Espanso has a built in search bar, this means you don’t have to remember every single trigger to get all your matches. For example, I use Espanso to help me format my markdown posts - particularly I lean into it to format the Notices for me.

I have all my matches for the notices triggered by ‘:mdnotice’. This triggers the search bar. Screenshot of the Espanso Search bar This allows you to choose your match! You can also bring up the search bar at any time, on macOS the command is Option + Space.

Portability

Because Espanso uses a text based config it is super portable. I use GitHub to sync my config across devices. It can be handy to keep images and other things in the configuration. Thankfully this is made easy by using $CONFIG. This will always output the path to the $CONFIG location and allows matches to work across different machines.

Final thoughts

I’m very happy using espanso, but sometimes it gets in the way - particularly on remote machines. All it takes to disable is to quickly visit the toolbar, right click disable. You can also set up hotkeys to do this if you wish.

Espanso has been very useful to me, hopefully it or another text expander like it will be useful to you! If you have any suggestions for my config or any comments please create an issue or a pull request.

Happy New Year!