#!/bin/bash set -eu function print_hr() { local str cols local start line end str="${1:-}" [[ -n $str ]] && str=" $str " cols=$((${COLUMNS:-$(tput cols)} - ${#str} - 3)) # start=$'\e(0'; end=$'\e(B'; line="qqq" start=''; end=''; line="─" while ((${#line}<$cols)); do line+=$line; done printf "╾" printf "%s%s%s" "$start" "${line:0:$((cols/2))}" "$end" printf "%s%s%s" "$start" "${line:0:$((cols/2))}" "$end" printf "%s" "$str" printf "%s%s%s" "$start" "${line:0:1}" "$end" printf "╼" printf "\n" } print_hr "$@"