git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/.bash/aliases.bash
diff options
context:
space:
mode:
authormail_redacted_for_web 2026-04-19 10:46:10 +0200
committermail_redacted_for_web 2026-04-19 10:46:10 +0200
commit1998c2e12d19cc8cb739a5bdacf88386afdf5d0a (patch)
tree714451a3e436aebe01fcfbef5c55ea2974bc47ff /.bash/aliases.bash
parent2bb726171720cdecc7ddd7cd1416f82b7f33d8c4 (diff)
downloaddotfiles-1998c2e12d19cc8cb739a5bdacf88386afdf5d0a.tar.bz2
feat: introduce horizontal line drawers and terminal width calculator
Diffstat (limited to '.bash/aliases.bash')
-rw-r--r--.bash/aliases.bash38
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"