help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] colorful shell without echo -e?


From: Greg Wooledge
Subject: Re: [Help-bash] colorful shell without echo -e?
Date: Fri, 14 Jun 2013 10:11:40 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Jun 14, 2013 at 01:47:14PM +0000, adrelanos wrote:
> I am mostly using
> 
>     set -x
> 
> and
> 
>    true "message here"
> 
> for running my scripts.
> 
> Using "true" instead of echo prevents showing the output message twice,
> which is exactly like I prefer.
> 
> Can I have it both ways? I mean, can I use "true" and still have
> colorful output? Maybe some setting for the terminal?

imadev:~$ red=$(tput setaf 1) normal=$(tput sgr0)
imadev:~$ set -x
imadev:~$ : "${red}a message${normal}"
+ : 'a message'

You can't see it in the email, but "a message" is red on my terminal.


> Subject: Re: [Help-bash] colorful shell without echo -e?

Gah!  Nobody should be using echo -e, ever, for anything.

If you want to put raw escape sequences in a format string, and have
them interpreted, use printf.  But you don't really want that.

If you want to use terminal features without putting terminal-specific
escape sequences in your code (this is what you want), then capture the
output of tput and reuse it, and I showed.

Someone will probably respond by saying "but you're old, Greg, and there
are no more terminals except emulators that all use ANSI, and there's
this new RFC and everything", but those are silly people that you can
ignore.

Don't hardcode terminal escape sequences in programs.  Use the system's
terminal libraries (the bash interface to which is tput) to generate
the correct codes for you.



reply via email to

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