Home

Awesome

⚠️ UPDATE (NOV 2023): This plugin is not maintained. Do not install it, use supported alternatives.

⚠️ CM6-based editor (default option in Obsidian >= v13.0.0) is not supported. Consider using Legacy editor.

demo

Text Expander Plugin

The plugin replaces shortcuts of format {{<text>}} on <kbd>Tab</kbd> press. The replacement can be either static text or the result of execution of arbitrary commands.

⚠️ Currently, the plugin supports Windows only partially. See the Known Issues section.

Use Cases

Installation

Open Settings > Third-party plugins > Community Plugins > Browse, then search for Text Expander and click Install.

Settings

The shortcuts are defined as a JSON-list of entries, each containing three fields: regex (required), replacement (optional) and command (optional).

Default Shortcuts

Below is the default configuration that can be changed in Settings > Plugin Options > Text Expander > Shortcuts:

[
    {
        "regex": "^trigger$",
        "replacement": "## Example replacement\n- [ ] ",
    },
    {
        "regex": "^now$",
        "command": "printf `date +%H:%M`",
    },
    {
        "regex": "^py:",
        "command": "echo <text> | cut -c 4- | python3"
    },
    {
        "regex": "^eval:",
        "command": "echo <text> | cut -c 6- | python3 -c 'print(eval(input()), end=\"\")'"
    },
    {
        "regex": "^shell:",
        "command": "echo <text> | cut -c 7- | sh"
    },
    {
        "regex": "^tool:",
        "command": "echo <text> | cut -c 6- | python3 <scripts_path>/tool.py"
    },
    {
        "regex": "^sympy:",
        "command": "echo <text> | cut -c 7- | python3 <scripts_path>/sympy_tool.py"
    }
]

Variables

With <variable_name> you can insert the value of a variable into the command field before it is executed. The following variables can be used:

Example flows

Example #1

Example #2

Example #3

Custom Scripts

You can place any scripts to <vault_path>/.obsidian/scripts to use them in commands. The examples folder contains two sample scripts, enabling {{tool: and {{sympy: shortcuts.

Security

As the plugin is shell-powered, one can easily run destructive commands just by typing {{shell:rm -rf ...}}<kbd>Tab</kbd>. Think twice before pressing <kbd>Tab</kbd> when your cursor is on something like {{shell:...}}. I also strongly discourage using the {{shell:...}} pattern, which was added mostly for demonstration purposes, and recommend writing python scripts instead.

Future Work

Known Issues

Credits

The project was inspired by the PoC text expander implementation. I also used certain ideas from the Run Snippets plugin.

Release Notes

1.1.0

1.0.1