Created
January 19, 2023 04:45
-
-
Save CodeAlDente/d426c9fd001139d253ea368e181c49e5 to your computer and use it in GitHub Desktop.
Simple "slugify" to give filenames a unified structure to handle them
This file contains 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
# Slugify | |
# | |
# URL: https://duncanlock.net/blog/2021/06/15/good-simple-bash-slugify-function/ | |
# | |
# Transliterate everything to ASCII | |
# Strip out apostrophes | |
# Anything that's not a letter or number to a dash | |
# Strip leading & trailing dashes | |
# Everything to lowercase | |
function slugify() { | |
iconv -t ascii//TRANSLIT \ | |
| tr -d "'" \ | |
| sed -E 's/[^a-zA-Z0-9]+/-/g' \ | |
| sed -E 's/^-+|-+$//g' \ | |
| tr "[:upper:]" "[:lower:]" | |
} |
Author
CodeAlDente
commented
Jan 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment