diff options
| author | mail_redacted_for_web | 2026-04-19 10:46:10 +0200 |
|---|---|---|
| committer | mail_redacted_for_web | 2026-04-19 10:46:10 +0200 |
| commit | 1998c2e12d19cc8cb739a5bdacf88386afdf5d0a (patch) | |
| tree | 714451a3e436aebe01fcfbef5c55ea2974bc47ff | |
| parent | 2bb726171720cdecc7ddd7cd1416f82b7f33d8c4 (diff) | |
| download | dotfiles-1998c2e12d19cc8cb739a5bdacf88386afdf5d0a.tar.bz2 | |
feat: introduce horizontal line drawers and terminal width calculator
| -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" |
