coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Would a patch adding color to cat(1) be accepted?


From: Pádraig Brady
Subject: Re: Would a patch adding color to cat(1) be accepted?
Date: Tue, 10 Oct 2017 01:43:16 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 08/10/17 12:31, Eric Pruitt wrote:
> I am going to modify cat(1) to add an option to embolden and / or color
> symbols added by "--show-nonprinting", "--show-ends" and "--show-tabs".
> Maintainers, is this a change you would be willing to merge into
> Coreutils codebase? I ask because the manner & style I would use to
> write a patch intended for my own use would differ from that of a change
> intended for upstream, and I would like to avoid writing the patch twice
> if there was some hope of it being accepted.
> 
> The implementation I currently have in mind would work much like
> colorization in ls(1) and grep(1): a "--color" option would be added
> that could be set to "always", "never" (default) or "auto"; user-defined
> colors would be controlled by the "CAT_COLORS" environment variable
> containing escape sequences used to color symbols associated with each
> of the aforementioned command line flags; and when "CAT_COLORS" is
> unset, the default escape sequence used by all three options would be
> simply make the text bold. Using the same two-character convention used
> by GREP_COLORS and LS_COLORS, the default value of of "CAT_COLORS" would
> be "np=01:nl=01:tb=01"; "np" is short for "non-printing", "nl" is short
> for newline a la "--show-ends" and "tb" is short for "tab."
> 
> I often find myself using xxd(1) after running "cat -A" to confirm some
> characters are what I think they are. With the proposed feature, it
> would be easier determine at a glance if certain characters are literal
> values that appear in the original data or if they were added by cat(1).
> 
> Please let me know what you think,
> Eric

This idea has some merit, though I'd prefer not to have
cat needing to deal with CAT_COLORS etc.
I wonder would it be possible to add an appropriate
filter to GNU highlight to support this?
One can also leverage existing tools to do what you want like:

  cat-A-color() {
    HLI=`tput smso`; RST=`tput sgr0`
    sed "s/$/$HLI\$$RST/" "$@" | less -EXRU
  }

cheers,
Pádraig.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]