Advertisement
smeech

Double capitals

Mar 18th, 2024 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.30 KB | Software | 0 0
  1. # Espanso - corrects double-capitals typoed at beginnings of words (Linux & ?WSL)
  2. # Responds to two capitals, followed by two or more lower-case letters (to exclude
  3. # plurals of short acronyms)
  4.   - regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
  5.     replace: "{{output}}{{end}}"
  6.     vars:
  7.       - name: output
  8.         type: shell
  9.         params:
  10.           cmd: sed -E 's/(.)(.*)/\1\L\2/' <<< "{{chars}}"
  11.  
  12. # Alternatively:
  13.   - regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
  14.     replace: "{{output}}{{end}}"
  15.     vars:
  16.       - name: output
  17.         type: shell
  18.         params:
  19.           cmd: |
  20.            chars="{{chars}}"
  21.             echo "${chars:0:1}$(echo ${chars:1} | tr '[:upper:]' '[:lower:]')"
  22.  
  23. # Python:
  24.   - regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
  25.     replace: "{{output}}{{end}}"
  26.     vars:
  27.       - name: output
  28.         type: script
  29.         params:
  30.           args:
  31.            - python
  32.             - -c
  33.             - print("{{chars}}"[0] + "{{chars}}"[1:].lower())
  34.  
  35. # PowerShell:
  36.   - regex: (?P<chars>\b[[:upper:]]{2,}[[:lower:]]{2,})(?P<end>\W)
  37.     replace: "{{output}}{{end}}"
  38.     vars:
  39.       - name: output
  40.         type: shell
  41.         params:
  42.           shell: pwsh
  43.           cmd: ("{{chars}}"[0] + "{{chars}}".Substring(1).ToLower())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement