Created
January 30, 2013 17:36
-
-
Save saml/4674977 to your computer and use it in GitHub Desktop.
make slug out of title. slugify.bash 'Surface to Air: The Brand Givenchy and Vuitton Hire to Stay Cool' 24
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/bash | |
title="$1" | |
max_length="${2:-48}" | |
slug="$({ | |
tr '[A-Z]' '[a-z]' | tr -cs '[[:alnum:]]' '-' | |
} <<< "$title")" | |
slug="${slug##-}" | |
slug="${slug%%-}" | |
slug="${slug:0:$max_length}" | |
echo "$slug" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment