You are not logged in.

#1 2017-08-10 20:25:06

tholmes
Member
Registered: 2013-02-26
Posts: 5

util-linux column utility bug with ansi escape sequences

I use a script that formats git log output using git pretty printing, sed, and column for layout. After installing util-linux-2.30.1-2-x86_64.pkg.tar.xz my output has become corrupted.

The script is this pretty_git_log function found here: https://raw.githubusercontent.com/garyb … githelpers

#!/bin/bash

# Log output:
#
# * 51c333e    (12 days)    <Gary Bernhardt>   add vim-eunuch
#
# The time massaging regexes start with ^[^<]* because that ensures that they
# only operate before the first "<". That "<" will be the beginning of the
# author name, ensuring that we don't destroy anything in the commit message
# that looks like time.
#
# The log format uses } characters between each field, and `column` is later
# used to split on them. A } in the commit subject or any other field will
# break this.

HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(bold red)%d%Creset"
SUBJECT="%s"

FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"

ANSI_BLACK='\033[30m'
ANSI_BLACK_BOLD='\033[0;30;1m'
ANSI_RED='\033[31m'
ANSI_RED_BOLD='\033[0;31;1m'
ANSI_GREEN='\033[32m'
ANSI_GREEN_BOLD='\033[0;32;1m'
ANSI_YELLOW='\033[33m'
ANSI_YELLOW_BOLD='\033[0;33;1m'
ANSI_BLUE='\033[34m'
ANSI_BLUE_BOLD='\033[0;34;1m'
ANSI_MAGENTA='\033[35m'
ANSI_MAGENTA_BOLD='\033[0;35;1m'
ANSI_CYAN='\033[36m'
ANSI_CYAN_BOLD='\033[0;36;1m'
ANSI_WHITE='\033[37m'
ANSI_WHITE_BOLD='\033[0;37;1m'
ANSI_RESET='\033[0m'


show_git_head() {
    pretty_git_log -1
    git show -p --pretty="tformat:"
}

pretty_git_log() {
    git log --graph --pretty="tformat:${FORMAT}" $* |
        # Replace (2 years ago) with (2 years)
        sed -Ee 's/(^[^<]*) ago\)/\1)/' |
        # Replace (2 years, 5 months) with (2 years)
        sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
        # Line columns up based on } delimiter
        column -s '}' -t |
        # Color merge commits specially
        sed -Ee "s/(Merge (branch|remote-tracking branch|pull request) .*$)/$(printf $ANSI_RED)\1$(printf $ANSI_RESET)/" |
        # Page only if we're asked to.
        if [ -n "$GIT_NO_PAGER" ]; then
            cat
        else
            # Page only if needed.
            less --quit-if-one-screen --no-init --RAW-CONTROL-CHARS --chop-long-lines
        fi
}

before:

* 41c0f8add  (4 months)  <anukin>                  KAFKA-5049; Chroot check should be done for each ZkUtils instance

after:

* \x1b[33m41c0f8add\x1b[m  \x1b[32m(4 months)\x1b[m  \x1b[1;34m<anukin>\x1b[m                 \x1b[1;31m\x1b[m KAFKA-5049; Chroot check should be done for each ZkUtils instance 

If I revert util-linux to util-linux-2.29-2-x86_64.pkg.tar.xz the output is as expected.

Other related info. I use Termite for my terminal but this behavior is reproducible in xterm as well.

Filed a bug report: https://bugs.archlinux.org/task/55100

Last edited by tholmes (2017-08-10 20:36:26)

Offline

#2 2017-08-11 14:34:35

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,811
Website

Re: util-linux column utility bug with ansi escape sequences

First of all, nice script! smile

The problem appears to be with this line:

column -s '}' -t |

If I change it to this:

column -s '}' |

then it looks pretty again. I'm afraid I don't know why though. sad

You can read the "column" Release Notes here (page find for "column:") https://www.kernel.org/pub/linux/utils/ … leaseNotes

Offline

Board footer

Powered by FluxBB