Created
May 6, 2022 02:47
-
-
Save ndgnuh/f5e5f5eb387422f69751fa7e58b9b23e to your computer and use it in GitHub Desktop.
Slugify file names
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
#!/bin/sh | |
if [ -z "$1" ]; then | |
echo "slugifile <file name> [.ext]" | |
fi | |
bn=$(basename "$1" "$2") | |
slug=$(echo "$bn" | iconv -t ascii//TRANSLIT | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z) | |
if [ -z "$2" ]; then | |
echo "$slug" | |
else | |
echo "$slug.$2" | sed 's/\.\./\./' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment