diff options
author | EuAndreh <eu@euandre.org> | 2022-09-01 15:44:20 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-09-01 15:44:20 -0300 |
commit | 375378e93025f347ce4ed596d908959c1298520e (patch) | |
tree | 8f396972be537193d917f01f027b81794ea93e31 | |
parent | etc/ssh/known_hosts: Add camarada.site entry (diff) | |
download | dotfiles-375378e93025f347ce4ed596d908959c1298520e.tar.gz dotfiles-375378e93025f347ce4ed596d908959c1298520e.tar.xz |
bin/slugify: Add new (working) utility
-rwxr-xr-x | bin/slugify | 69 |
1 files changed, 69 insertions, 0 deletions
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/-$//' |