2022-02-09 07:29:05 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Produces a centered title in the middle of a horizontal rule of text.
|
|
|
|
|
2022-03-01 23:04:52 +00:00
|
|
|
pre='//'
|
|
|
|
|
2022-02-09 07:29:05 +00:00
|
|
|
_filter(){
|
|
|
|
[[ -n "$1" ]] && return 1
|
|
|
|
while IFS= read -ra args; do
|
|
|
|
"${FUNCNAME[1]}" "${args[@]}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
htitle() {
|
|
|
|
_filter "$@" && return $?
|
|
|
|
local str="$1" char="${2:--}"
|
|
|
|
local -i len=${#str}
|
|
|
|
local -i side=$((((HRULEWIDTH / 2) - len / 2) - 3))
|
|
|
|
local -i left=$side
|
|
|
|
local -i right=$side
|
|
|
|
(( len % 2 == 1 )) && ((right -= 1))
|
2022-03-01 23:04:52 +00:00
|
|
|
echo "$pre $(echon "$char" "$left") "$str" $(echon "$char" "$right")"
|
2022-02-09 07:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
htitle "$@"
|