diff options
Diffstat (limited to 'bin/slugify')
-rwxr-xr-x | bin/slugify | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/bin/slugify b/bin/slugify index aa3b50a..955a849 100755 --- a/bin/slugify +++ b/bin/slugify @@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - slugify < STDIN + slugify [CONTENT...] slugify -h EOF } @@ -16,16 +16,19 @@ help() { Options: -h, --help show this message + CONTENT a literal string to be slugified + "slugify" the input string, removing diacritics and punctuation - from the string, on a best-effort basis. + from the string, on a best-effort basis. If CONTENT is not + given, get data from STDIN. Examples: Slugify the input string: - $ echo 'Saçi-pererê, tomando açaí!!' | slugify + $ slugify 'Saçi-pererê, tomando açaí!!' saci-perere-tomando-acai EOF } @@ -60,10 +63,21 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -iconv -ct ASCII//TRANSLIT | - tr '[:upper:]' '[:lower:]' | - sed \ - -e 's/[^a-z0-9]/-/g' \ - -e 's/--*/-/g' \ - -e 's/^-//' \ - -e 's/-$//' + +esc() { + iconv -ct ASCII//TRANSLIT | + tr '[:upper:]' '[:lower:]' | + sed \ + -e 's/[^a-z0-9]/-/g' \ + -e 's/--*/-/g' \ + -e 's/^-//' \ + -e 's/-$//' +} + +if [ $# = 0 ]; then + esc +else + for s in "$@"; do + printf '%s\n' "$s" | esc + done +fi |