Last active
January 31, 2025 15:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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