diff options
| -rw-r--r-- | .bash/aliases.bash | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/.bash/aliases.bash b/.bash/aliases.bash index 8f29423..a09ba54 100644 --- a/.bash/aliases.bash +++ b/.bash/aliases.bash @@ -109,6 +109,44 @@ xstat() { printf "%s\t%s\n" "${crtime}" "${target}" done } +# ----- DECORATIVE STUFF ----- # +function coleval { + mycols="$COLUMNS" + if [ -z "$COLUMNS" ]; then mycols="$(tput cols 2>/dev/null)"; fi + if [ -z "$COLUMNS" ]; then mycols=20; fi + printf '%b' "$mycols" +} +function hsep { + mycols="$(coleval)" + nocalc=0 + declare mychar + while [ "$#" -gt 0 ]; do + case "$1" in + '-i') nocalc=1; shift ;; + *) mychar="$1"; shift ;; + esac + done + [ -z "$mychar" ] && return 1 + [ "$(printf '%b' "$mychar" | wc --chars)" -ne 1 ] && return 2 + if [ "$nocalc" -ne 1 ]; then + # if we encounter a one-char three-byte character, we may have hit a Unicode + # symbol that indeed is a little wider. Use bashes mathematical division- it rounds + # down, but this is what we want as we cannot split a character into parts :-) + # The result might be significantly narrower than the terminal's width, but for + # now we don't have any better math. + [ "$(printf '%b' "$mychar" | wc --bytes)" -eq 3 ] && mycols="$(( 4 * mycols / 9 ))" + fi + for (( i=0;i<mycols;++i )); do + printf '%b' "$mychar" + done + printf '\n' +} +alias hdash='hsep "-"' +alias hddash='hsep "="' +#alias hline='hsep -i "─"' +alias hline='hsep -i "─"' +alias hdline='hsep -i "═"' +alias hfline='hsep -i "━"' # ----- PACKAGE MANAGERS ----- # if [ -x "/usr/bin/paru" ];then alias pkgclean="paru --noconfirm -Sc" |
