Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active January 31, 2025 15:53
Show Gist options
  • Select an option

  • Save smeech/eedc7965486067746b77f23d8903c492 to your computer and use it in GitHub Desktop.

Select an option

Save smeech/eedc7965486067746b77f23d8903c492 to your computer and use it in GitHub Desktop.
[Autocomplete brackets] Espanso trigger to autocomplete brackets etc. at the end of a string, on typing double-space. It will fall over if there's a single-quote within the string, however. #espanso #python #regex
# Espanso trigger to autocomplete brackets etc. at the end of a string, on typing double-space.
# It will fall over if there's a single-quote within the string, however.
matches:
- regex: '(?P<delim>[\[\(\{<"])(?P<string>.+) '
replace: "{{output}}"
vars:
- name: output
type: script
params:
args:
- python
- -c
- |
closing_chars = { '[': ']',
'{': '}',
'(': ')',
'<': '>',
'"': '"',
"'": "'" }
input_delim = '{{delim}}'
input_string = r'{{string}}'
closing_char = closing_chars.get(input_delim)
print(input_delim + input_string + closing_char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment