help-bash
[Top][All Lists]
Advanced

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

Re: Colouring commands on terminal to be green


From: Greg Wooledge
Subject: Re: Colouring commands on terminal to be green
Date: Sun, 27 Jun 2021 12:43:03 -0400

> From: Koichi Murase <myoga.murase@gmail.com>
> I'm not sure if this works in every possible case because it's merely
> a hack, but you may modify PS1 and PS0 as
> 
> PS1=$PS1'\[\e[32m\]'
> PS0='\e[39m'$PS0

On Sun, Jun 27, 2021 at 05:32:13PM +0200, lisa-asket@perso.be wrote:
> What isĀ  "\e[39m" exactly ?

This is one of the reasons why I don't endorse hard-coding escape
sequences in your configuration.  Not only are the escape sequences
incomprehensible, but they also aren't the same for every terminal
type.

It should be reasonable to guess from context that what Koichi's PS0 is
supposed to do is reset the green color back to the original foreground
color.  (Whether it actually does that will depend on your terminal.)

You've got the PS1 variable which is expanded and printed *before*
the user begins typing, and then the PS0 variable which is expanded
and printed *after* the user finishes typing, but before the command
is executed.

A more terminal-independent method of configuration would look something
like this:

green=$(tput setaf 2)
normal=$(tput sgr0)
PS1=$PS1'\[$green\]'
PS0='$normal'$PS0



reply via email to

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