aboutsummaryrefslogtreecommitdiff
path: root/bin/slugify
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-09-01 15:44:20 -0300
committerEuAndreh <eu@euandre.org>2022-09-01 15:44:20 -0300
commit375378e93025f347ce4ed596d908959c1298520e (patch)
tree8f396972be537193d917f01f027b81794ea93e31 /bin/slugify
parentetc/ssh/known_hosts: Add camarada.site entry (diff)
downloaddotfiles-375378e93025f347ce4ed596d908959c1298520e.tar.gz
dotfiles-375378e93025f347ce4ed596d908959c1298520e.tar.xz
bin/slugify: Add new (working) utility
Diffstat (limited to 'bin/slugify')
-rwxr-xr-xbin/slugify69
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/-$//'