From 80d506b338e9618557c8eb45f08e3d4d1887d23f Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Mon, 28 Nov 2022 21:34:18 -0600 Subject: [PATCH] bin/git-branch-dates: Smarter automatic line truncation --- bin/git-branch-dates | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/git-branch-dates b/bin/git-branch-dates index a33fa00..9b2bb9a 100755 --- a/bin/git-branch-dates +++ b/bin/git-branch-dates @@ -10,8 +10,17 @@ if [[ "$1" = "-v" || "$1" = "-vv" ]]; then shift format="$format"'|%(color:yellow)%(objectname:short)%(color:reset) %(contents:subject)' fi + +# For the `cut`-based line truncation handling below, since `cut` works based +# on chars/bytes and since the `git branch` will contain SGR escape sequences +# for coloring, predict how many "extra" bytes will be in each line due to the +# coloring in the `format` defined above. +extra_color_len=26 + git branch \ --color=always \ --sort=-committerdate \ --format="$format" \ - $* | column -ts'|' + $* \ + | column -ts'|' \ + | cut -c 1-$(expr $(tput cols) + $extra_color_len) -- 2.47.1