Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active November 23, 2025 05:17
Show Gist options
  • Select an option

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

Select an option

Save smeech/affa291af51c5bea7a8c1f6d589c0584 to your computer and use it in GitHub Desktop.
[Double capitals] Corrects double-capitals typoed at beginnings of words (Linux & ?WSL) #espanso #regex #sed #python #powershell #bash
# corrects double-capitals typoed at beginnings of words
- regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
replace: "{{output}}{{end}}"
vars:
- name: output
type: script
params:
args:
- python
- -c
- |
excluded = {"VSCodium", "VSCode", "SSHKey", "VMWare"}
print("{{chars}}" if "{{chars}}" in excluded else "{{chars}}".capitalize())
# corrects double-capitals typoed at beginnings of words
# Gets around the lack of "lookaround" in Espanso Rust regex
- regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
replace: "{{output}}{{end}}"
vars:
- name: output
type: shell
params:
cmd: |
w="{{chars}}"
case "$w" in
# Exceptions
VSCodium|VSCode|SSHKey|VMWare)
printf '%s' "$w"
;;
*)
rest="${w:1}"
printf '%s%s' "${w::1}" "${rest,,}"
;;
esac
# PowerShell:
- regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
replace: "{{output}}{{end}}"
vars:
- name: output
type: shell
params:
shell: pwsh
cmd: ("{{chars}}"[0] + "{{chars}}".Substring(1).ToLower())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment