Skip to content

Instantly share code, notes, and snippets.

@saml
Created January 30, 2013 17:36
Show Gist options
  • Save saml/4674977 to your computer and use it in GitHub Desktop.
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
#!/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