Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active October 27, 2025 13:57
Show Gist options
  • Select an option

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

Select an option

Save smeech/f7128328215346a89911151cd9800500 to your computer and use it in GitHub Desktop.
[Sentence capitalise] Capitalise new sentence after period, question or exclamation mark. #espanso #regex #bash #python
# Capitalises first letter after sentence-ending punctuation, skipping exceptions
- regex: (?P<before>\b[\w.]+[.?!])\s(?P<firstchar>[a-z])(?P<therest>\w*\W)
replace: "{{before}} {{capital}}{{therest}}"
vars:
- name: capital
type: script
params:
args:
- python
- -c
- |
exceptions = {"etc.", "i.e.", "e.g.", "Prof."}
print("{{firstchar}}" if "{{before}}" in exceptions else "{{firstchar}}".upper())
# Capitalise new sentence after period, question or exclamation mark, skip "etc."
- regex: (?P<before>\b[\w.]+[.?!])\s(?P<firstchar>[a-z])(?P<therest>\w*\W)
replace: "{{before}} {{capital}}{{therest}}"
vars:
- name: capital
type: shell
params:
cmd: |
EXCEPTIONS=("etc." "i.e." "e.g." "Prof.")
# Check if 'before' exactly matches any exception
if printf "%s\n" "${EXCEPTIONS[@]}" | grep -Fxq "{{before}}"; then
echo "{{firstchar}}" # leave lowercase
else
echo "{{firstchar}}" | tr '[:lower:]' '[:upper:]'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment