42 lines
1008 B
Plaintext
42 lines
1008 B
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
# Versión simplificada y adaptada de bash-slugify
|
||
|
# https://github.com/brutus/bash-slugify
|
||
|
slugify () {
|
||
|
local name="$@"
|
||
|
local gluechars='-_. '
|
||
|
local safechars="${gluechars}a-zA-Z0-9"
|
||
|
|
||
|
# convert to lowercase
|
||
|
name=$(echo "${name}" | tr A-ZÄÖÜ a-zäöü)
|
||
|
|
||
|
# remove special chars
|
||
|
name=$(echo "${name//[^${safechars}]/}")
|
||
|
|
||
|
# consolidate spaces
|
||
|
name=$(echo "${name}" | tr -s '[:space:]')
|
||
|
|
||
|
# replace spaces with dashes
|
||
|
name=$(echo "${name}" | tr ' ' '-')
|
||
|
|
||
|
# remove spaces around dashes and underscores
|
||
|
name=$(echo "${name// -/-}")
|
||
|
name=$(echo "${name//- /-}")
|
||
|
name=$(echo "${name// _/_}")
|
||
|
name=$(echo "${name//_ /_}")
|
||
|
|
||
|
# trim spaces
|
||
|
name=$(echo "${name}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||
|
|
||
|
# replace special chars
|
||
|
name=$(echo "${name//[^${safechars}]/$REPLACEMENT_CHAR}")
|
||
|
|
||
|
## REPLACE SPACES
|
||
|
name=$(echo "${name// /$SPACE_CHAR}")
|
||
|
|
||
|
# return slug
|
||
|
echo "${name}"
|
||
|
}
|
||
|
|
||
|
echo $(slugify "$@")
|