Skip to content

Instantly share code, notes, and snippets.

@ndgnuh
Created May 6, 2022 02:47
Show Gist options
  • Save ndgnuh/f5e5f5eb387422f69751fa7e58b9b23e to your computer and use it in GitHub Desktop.
Save ndgnuh/f5e5f5eb387422f69751fa7e58b9b23e to your computer and use it in GitHub Desktop.
Slugify file names
#!/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