1- #! /bin/bash
1+ #! /usr/ bin/env bash
22# post_slug - Convert strings into URL or filename-friendly slugs
33#
44# Performs multiple transformations:
@@ -52,13 +52,13 @@ post_slug() {
5252
5353 # Replace all multiple occurrences of {sep_char} with a single {sep_char}.
5454 # input_str=$(echo "$input_str" | sed -e "s/$sep_char\{2,\}/$sep_char/g")
55- while [[ " $input_str " == * " $sep_char " $sep_char * ]]; do
55+ while [[ " $input_str " == * " $sep_char$sep_char " * ]]; do
5656 input_str=" ${input_str// " $sep_char " $sep_char / $sep_char } "
5757 done
5858
5959 # Remove leading and trailing {sep_char}.
60- input_str=" ${input_str# " ${ sep_char} " } "
61- input_str=" ${input_str% " ${ sep_char} " } "
60+ input_str=" ${input_str# " $sep_char " } "
61+ input_str=" ${input_str% " $sep_char " } "
6262
6363 if (( max_len)) ; then
6464 if (( ${# input_str} > max_len )) ; then
@@ -73,8 +73,16 @@ declare -fx post_slug
7373# Exit if script being executed directly (not sourced)
7474[[ " ${BASH_SOURCE[0]} " == " ${0} " ]] || return 0
7575
76- #! /bin/bash #semantic -------- -------------------------------------------------
76+ #! /usr/ bin/env bash #semantic -------------------------------------------------
7777set -euo pipefail
78+ shopt -s inherit_errexit shift_verbose
79+
80+ VERSION=' 1.0.0'
81+ SCRIPT_PATH=$( realpath -- " $0 " )
82+ SCRIPT_DIR=${SCRIPT_PATH%/* }
83+ SCRIPT_NAME=${SCRIPT_PATH##*/ }
84+ # shellcheck disable=SC2034 # Standard BCS metadata variables
85+ readonly -- VERSION SCRIPT_PATH SCRIPT_DIR SCRIPT_NAME
7886
7987show_help () {
8088 cat << -'EOT '
@@ -120,7 +128,10 @@ Examples:
120128EOT
121129}
122130
123- [[ " ${1:- } " == ' -h' || " ${1:- } " == ' --help' ]] && { show_help; exit 0; }
131+ main () {
132+ [[ " ${1:- } " == ' -h' || " ${1:- } " == ' --help' ]] && { show_help; exit 0; }
133+ post_slug " $@ "
134+ }
124135
125- post_slug " $@ "
136+ main " $@ "
126137# fin
0 commit comments