From 375378e93025f347ce4ed596d908959c1298520e Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 1 Sep 2022 15:44:20 -0300 Subject: bin/slugify: Add new (working) utility --- bin/slugify | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 bin/slugify (limited to 'bin') diff --git a/bin/slugify b/bin/slugify new file mode 100755 index 0000000..aa3b50a --- /dev/null +++ b/bin/slugify @@ -0,0 +1,69 @@ +#!/bin/sh +set -eu + + +usage() { + cat <<-'EOF' + Usage: + slugify < STDIN + slugify -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -h, --help show this message + + + "slugify" the input string, removing diacritics and punctuation + from the string, on a best-effort basis. + + + Examples: + + Slugify the input string: + + $ echo 'Saçi-pererê, tomando açaí!!' | slugify + saci-perere-tomando-acai + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + esac +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/-$//' -- cgit v1.2.3