|
1 | 1 | # GitNow — Speed up your Git workflow. 🐠 |
2 | 2 | # https://github.com/joseluisq/gitnow |
3 | 3 |
|
4 | | -# adapted from https://gist.github.com/oneohthree/f528c7ae1e701ad990e6 |
5 | | -function __gitnow_slugify |
6 | | - # Lowercase + ASCII transliteration; `/` and `.` are preserved since they |
7 | | - # are valid in git branch names (e.g. `fix/v1.2`). |
8 | | - string join ' ' -- $argv | command iconv -f UTF-8 -t ascii//TRANSLIT | string lower | string replace -ra '[^a-z0-9./-]+' '_' | string replace -ra '^[-_./]+|[-_./]+$' '' |
| 4 | +function __gitnow_slugify -d "Turns free text into a git-safe, lowercase branch slug" |
| 5 | + # Pure Fish, no iconv: `iconv //TRANSLIT` is GNU-only in practice (macOS |
| 6 | + # iconv rejects or drops accented characters). Transliterate the common |
| 7 | + # Latin accents by hand, lowercase, then map anything else non-ASCII to |
| 8 | + # `_`. `/` and `.` are preserved since they are valid in branch names. |
| 9 | + set -l s (string join ' ' -- $argv) |
| 10 | + |
| 11 | + set s (string replace -ra '[àáâäãåāÀÁÂÄÃÅĀ]' a -- $s) |
| 12 | + set s (string replace -ra '[èéêëēÈÉÊËĒ]' e -- $s) |
| 13 | + set s (string replace -ra '[ìíîïīÌÍÎÏĪ]' i -- $s) |
| 14 | + set s (string replace -ra '[òóôöõøōÒÓÔÖÕØŌ]' o -- $s) |
| 15 | + set s (string replace -ra '[ùúûüūÙÚÛÜŪ]' u -- $s) |
| 16 | + set s (string replace -ra '[ýÿÝŸ]' y -- $s) |
| 17 | + set s (string replace -ra '[ñÑ]' n -- $s) |
| 18 | + set s (string replace -ra '[çÇ]' c -- $s) |
| 19 | + set s (string replace -ra '[ß]' ss -- $s) |
| 20 | + set s (string replace -ra '[æÆ]' ae -- $s) |
| 21 | + set s (string replace -ra '[œŒ]' oe -- $s) |
| 22 | + |
| 23 | + string lower -- $s | string replace -ra '[^a-z0-9./-]+' '_' | string replace -ra '^[-_./]+|[-_./]+$' '' |
9 | 24 | end |
0 commit comments