diff --git a/functions b/functions index 06aeaf8..f9d2e71 100644 --- a/functions +++ b/functions @@ -374,10 +374,12 @@ subboxborder(){ # For printing center-justified text. To change the padding character, replace the ' ' <~~ whitespace in front of the '{' in the padding variable center(){ - #local padding=""; - padding="$(printf '%0.1s' \ {1..100})" - #padding=" " - printf '%*.*s %s %*.*s\n' 0 "$(((BOXWIDTH-2-${#1})/2))" "${left_border}${padding}" "$1" 0 "$(((BOXWIDTH-1-${#1})/2))" "${padding}${right_border}" + local padding="" + padding="$(printf ' %.0s' {1..100})" + local string_length=${#1} + local padding_length=$(( (BOXWIDTH - 2 - string_length) / 2 )) + printf "%s%s %s %s%s\n" "$left_border" "${padding:0:padding_length}" "$1" "${padding:0:padding_length}" "$right_border" + #printf '%*.*s %s %*.*s\n' 0 "$(((BOXWIDTH-2-${#1})/2))" "${left_border}${padding}" "$1" 0 "$(((BOXWIDTH-1-${#1})/2))" "${padding}${right_border}" #printf "%s %s %s %s %s\n" "$left_border" "$padding" "$1" "$padding" "$right_border"; #echo -en "\r${ESC}[$(((BOXWIDTH-${#1})/2))C$@\r${ESC}[${BOXWIDTH}C\n" } @@ -588,7 +590,7 @@ trim() { strip-html-tags() { local input="$1" - local stripped=$(echo "$input" | sed 's/<[^>]*>//g') + local stripped=$(echo "$input" | sed 's/<[^>]*>//g' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') echo "$stripped" }