git:last-changed: Fix truncation of colored lines
`cut` counts bytes instead of printable character, making it truncate colored lines too early. Fix this by using awk and adding the length difference between a colored and uncolored version to the allowed length. COLUMNS is a shell variable and thus needs exporting for `ENVIRON` to see it in awk.
This commit is contained in:
@@ -22,4 +22,9 @@ ls -1p --color="$color_set" "$@" \
|
||||
done \
|
||||
| sort -r -t$'\t' -k2,2 \
|
||||
| column -s$'\t' -t \
|
||||
| cut -c -"$COLUMNS"
|
||||
| env COLUMNS="$COLUMNS" awk \
|
||||
'{
|
||||
sanit = gensub(/\033\[[0-9;]*m/, "", "g", $0);
|
||||
trunc_len = ENVIRON["COLUMNS"] + length($0) - length(sanit) - 3;
|
||||
print gensub("^(.{" trunc_len "}).{4,}$", "\\1...", "g")
|
||||
}'
|
||||
|
||||
Reference in New Issue
Block a user