Espanso (text expander) Snippet Showcase

Espanso (multi-platform text expander) Snippet Showcase

[x] Linux [x] MacOS [x] Windows [-] iOS [-] Android

Espanso (GitHub) is a file-based, system-wide text expander available for Linux, MacOS and Windows. Since it’s obviously in use by many Obsidians, I thought it might be worthwhile to have a Snippet Showcase for it.

Note: Espanso doesn’t work on mobile.

To keep this somehow readable, let’s agree on some simple rules here, please:

  • Use a H2 header (##) to say what the snippet does in a short phrase (i.e. “ISO-8601 date shortcuts”).
  • Use a line like above to clearly state if your snippet works on [x] Linux, [x] MacOS and/or [x] Windows so users will instantly know if it works on their platform. This is crucial if using shell commands!
    • [x] = yes, it works and I have tested it
    • [-] = no, it doesn’t work on this platform (i.e., Windows PowerShell commands on Linux or MacOS)
    • [?] = I really don’t know and I can’t test it, but I suppose it might.
  • No posts stating “It can be done with Alfred/aText/Autohotkey/Whatever”. We appreciate that, but this thread is about espanso.
  • If you change or update your snippet, please do in the original post, maybe followed by a short change log. Don’t create a new post for each change—others will thank you, and links stay intact.

’nuf said—let’s start!

4 Likes

Recommended packages to install

[x] Linux [x] MacOS [x] Windows

Espanso has predefined packages which can be installed in a terminal by using espanso install <package_name>.

Here is a list of currently available packages: https://hub.espanso.org/

Here’s what I have installed. Recommendations welcome.

  • All Emojis - 0.1.0 (espanso install all-emojis) (Cheat sheet)
    • Note: You don’t have to re-learn: This uses the same emoji code names as this forum and most other big players like Discord. (Underscores in names have been replaced by blanks, for ease of typing, so it’s not :white_check_mark: but :white check mark:.)
  • HTML utilities package - 0.1.1 (espanso install html-utils-package)

Useful commands, key combinations and links

[x] Linux [x] MacOS [x] Windows

Location of your files

espanso path

will return a list of paths to your Config, Packages and Data files.

For use within Obsidian, you can construct a link to quickly open your default.yml like so: Take the “Config” path from above command and make a file:// link in your note to default.yml:

I’m on Linux, so mine looks as follows:

- Local [default.yml](file:///home/matthias/.config/espanso/default.yml)

Note: You cannot use $HOME or ~ as an abbreviation for your home folder here!

Now, in Obsidian, I only have to click on the default.yml link and it will open in the associated program (a text editor, in my case).

Temporarily dIsabling espanso

For documentaion and other purposes, you might want to temporarily disable espanso: Hit Alt twice in rapid succession. You should get an on-screen notification.

**TODO: ** What is the key on a Mac? Opt?

This is a toggle, so doing it again will re-enable espanso.

Auto-reload when changing default.yml

Whenever you change and save default.yml (which contains your snippets), you should get a “Config reloaded” notification. Espanso tries to detect changes and reloads automatically.

If this should fail for some reason or other, type espanso restart in a console.

ISO-8601 date and datetime strings

[x] Linux [x] MacOS [x] Windows

We often need (or want) ISO-8601-compatible date and/or datetime strings, for example in YAML, to be used with Dataview.

Commands

Here is my set of commands:

  • :date – returns a date like 2021-08-01
  • :d-1 – returns yesterday’s date like 2021-07-31
  • :d+1 – returns tomorrow’s date like 2021-08-02
  • :dt – returns a datetime like 2021-08-01T13:38:57
  • :dz – returns a datetime plus timezone offset like 2021-08-01T13:39:40+02:00

Snippet

  # Dates (example: 2021-07-31 13:56:00 UTC+02:00)
  # returns "2021-07-31"
  - trigger: ":date"
    replace: "{{mydate}}"
    vars:
      - name: mydate
        type: date
        params:
          format: "%Y-%m-%d"
  # returns "2021-07-31T13:56:00"
  - trigger: ":dt"
    replace: "{{mydate}}"
    vars:
      - name: mydate
        type: date
        params:
          format: "%FT%T"
  # returns "2021-07-31T13:56:00+02:00"
  - trigger: ":dz"
    replace: "{{mydate}}"
    vars:
      - name: mydate
        type: date
        params:
          format: "%FT%T%:z"

  # yesterday
  - trigger: ":d-1"
    replace: "{{mydate}}"
    vars:
      - name: mydate
        type: date
        params:
          format: "%Y-%m-%d"
          offset: -86400

  # tomorrow
  - trigger: ":d+1"
    replace: "{{mydate}}"
    vars:
      - name: mydate
        type: date
        params:
          format: "%Y-%m-%d"
          offset: 86400

(I included yesterday and tomorrow examples here because the offset: parameter is badly documented but useful. It uses seconds as unit.)

A <kbd>…</kbd> command for the forums and Obsidian

[x] Linux [x] MacOS [x] Windows

I hate having to manually type <kbd>bla-bla</kbd> in my notes and in the forum, just to get a bla-bla key!

So I use espanso for that. To stay compatible with the HTML utilities package (espanso install html-utils-package), I use a double colon :: as trigger start here:

  # HTML <kbd>|</kbd>
  - trigger: "::kbd"
    replace: >-
       <kbd>$|$</kbd>

The $|$ sequence places the cursor in between <kbd> and </kbd>, after expansion, so I just have to type whatever key name I want.

Installing modulo, espanso’s forms GUI, on Linux

[x] Linux [-] MacOS [-] Windows

Note: This is only required on Linux. MacOS and Windows versions above 0.7 apparently have it included.

Espanso can run without having modulo installed—you only lose the forms input.

Installing modulo is pretty straightforward, it being packaged as an AppImage. Here’s one way (of many) to install modulo on a Linux system (Linux Mint, in my case). I store AppImages in a separate AppImages folder within my home folder.

# Make sure to have the $HOME/AppImages directory
mkdir -p $HOME/AppImages

# Download the latest Modulo AppImage in the $HOME/opt
wget https://github.com/federico-terzi/modulo/releases/latest/download/modulo-x86_64.AppImage -O $HOME/AppImages/modulo.AppImage

# Make it executable:
chmod +x $HOME/AppImages/modulo.AppImage

# Create a link to make modulo available as "modulo"
sudo ln -s $HOME/AppImages/modulo.AppImage /usr/bin/modulo

Note that these steps can be changed in many ways, the only requirement is that the modulo binary is available as modulo in the PATH.

Try by typing modulo --version or modulo --help in a console.

To activate, espanso mut be restarted:

espanso restart

I have been using Espanso for a few years and love it. Thanks to you I added the Mac package.

I mostly use key codes to make Espanso type for me, e.g. I use dyx to get today’s date in the format YYYY-MM-DD (e.g. 2021-08-03).

I use a snippet from Mara to do Admonitions.

1 Like

Copy clipboard to Obsidian (Markdown) code block

[x] Linux [x] MacOS [x] Windows

Just came up in the Discord again, so I checked what I use. It even hops back to the first three backticks so you can enter the codeblock language:

  # Paste clipboard unformatted as Markdown codeblock
  - trigger: "ccc"
    force_clipboard: true
    replace: "```$|$\n{{clipboard}}\n```\n"
    vars:
      - name: "clipboard"
        type: "clipboard"

You can, of course, change your trigger to anything else.

2 Likes