zsh-users
 help / color / mirror / code / Atom feed
* Colorize command output
@ 2005-02-21 16:16 Ralph Pöllath
  2005-02-21 16:34 ` zzapper
  0 siblings, 1 reply; 3+ messages in thread
From: Ralph Pöllath @ 2005-02-21 16:16 UTC (permalink / raw)
  To: zsh-users

Hi,

To make conflicts stand out, I'd like to colorize the output of the svn 
command so that lines starting with C are displayed in red. My first 
shot at this was

% svn status | sed -e 's/^C/\e[31mC\e[0m/g'

but the escapes aren't interpreted. Can anyone help?

Thanks,
-Ralph.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Colorize command output
  2005-02-21 16:16 Colorize command output Ralph Pöllath
@ 2005-02-21 16:34 ` zzapper
  2005-02-21 18:35   ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2005-02-21 16:34 UTC (permalink / raw)
  To: zsh-users

On Mon, 21 Feb 2005 17:16:43 +0100,  wrote:

>Hi,
>
>To make conflicts stand out, I'd like to colorize the output of the svn 
>command so that lines starting with C are displayed in red. My first 
>shot at this was
>
>% svn status | sed -e 's/^C/\e[31mC\e[0m/g'
>
I guess you could cheat by using grep as a colorizer

echo "fred" | grep --color '.' 

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Colorize command output
  2005-02-21 16:34 ` zzapper
@ 2005-02-21 18:35   ` Oliver Kiddle
  0 siblings, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2005-02-21 18:35 UTC (permalink / raw)
  To: zsh-users

zzapper wrote:
> On Mon, 21 Feb 2005 17:16:43 +0100,  wrote:
> 
> >
> >To make conflicts stand out, I'd like to colorize the output of the svn 
> >command so that lines starting with C are displayed in red. My first 
> >shot at this was
> >
> >% svn status | sed -e 's/^C/\e[31mC\e[0m/g'

Escapes like \e are not expanded by sed. You can used the shell's $'...'
form of quoting to expand them, however.

    svn status | sed -e $'s/^C/\e[31m&\e[0m/g'

Note also, that you can use & in the replacement part of sed's s
command. That substitutes whatever was matched.

> I guess you could cheat by using grep as a colorizer
> 
> echo "fred" | grep --color '.' 

That's not quite the same. It highlights matching parts of a line so
lines not beginning with a C will be lost. I've attached below my old
hgrep script which highlights matches but outputs all lines. I find it
more useful than grep --color. It's meant for general cases, though, and
wouldn't be much use for colouring svn output.

Oliver

# hgrep - highlight grep

if (( ! $# )); then
  echo "Usage: $0:t [-e pattern...] [file...]" >&2
  return 1
fi

local -a regex
local htext=`echotc so` ntext=`echotc se`

while [[ "$1" = -e ]]; do
  regex=( $regex "$2" )
  shift 2
done

if (( ! $#regex )); then
  regex=( "$1" )
  shift
fi

regex=( "-e
s/${^regex[@]}/$htext&$ntext/g" )
sed ${(Ff)regex[@]} "$@"


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-02-21 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-21 16:16 Colorize command output Ralph Pöllath
2005-02-21 16:34 ` zzapper
2005-02-21 18:35   ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).