Last active
November 2, 2025 12:21
-
-
Save oneohthree/f528c7ae1e701ad990e6 to your computer and use it in GitHub Desktop.
Quick bash slugify
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
| echo "$STRING" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's good to replace multiple
sedprocesses with a single one using multiple-eparameters.It's good to use
[:alnum:]instead of[^a-zA-Z0-9].It's good to use
tr "[:upper:]" "[:lower:]"instead oftr A-Z a-zas a matter of principle for the goal of lowercasing input. To know thattr A-Z a-zis good enough requires verifying what comes before in the pipeline, and knowing howiconvworks. That's added mental burden.Putting it together: