I am after a pure bash solution to "slugify" a variable and that is not as ugly as mine.
slugify: lowercased, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with -. No leading / trailing -. A string suitable to use in URL hostnames and domain names is the result. An input is most likely a series of words with undesired characters in throughout such as:
'Effrafax_mUKwT'uP7(Garkbit<\1}@NJ"RJ"Hactar*S;-H%x.?oLazlarl(=Zss@c9?qick.:?BZarquonelW{x>g@'k'
Of which a slug would look like: 'effrafax-mukwt-up7-garkbit-1-njrjhactar-s-h-x-olazlarl-zss-c9-q'
slugify () {
next=${1//+([^A-Za-z0-9])/-}
next=${next:0:63}
next=${next,,}
next=${next#-}
next=${next%-}
echo $next
}
Also why doesn't ${next//^-|-$}
strip the prefix and suffix '-'
? Other suggestions?