Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Colored PS1

From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
Subject: Re: Colored PS1
Date: Thu, 08 Sep 2005 02:39:21 +0000

Hi Bart !

 First of all and most important:
 ***$fg_very_very_bold[RED]THANK YOU VERY VERY MUCH!$fg_very_very_bold[BLACK]***
 for your help and patience with my English confusions !!!

 This helps me a lot to understand things !

> On Sep 7,  7:21pm, Meino Christian Cramer wrote:
> }
> }  Now I would write:
> } 
> } 	   export PS1=$fb_bold[black]%M$fb_no_bold[black]:%2d
> }  
> }  But this would not work (that's why I wrote my mail...).  As I
> }  understand your mail, I had to enclose the "literally escape
> }  sequence" (whatever this is...I am no native English speaker and if
> }  translated to german this makes really no sense - as with so many 
> }  technospeak expressions...
> "literal" (not "literally") in that context means "unchanged; exactly
> the way it appears."

  ...do have to say more about my English? I think...no...this is

> "escape sequence" in the context of terminals means "a series of ASCII
> characters, often beginning with the ESC (\033, \x1B) character."  It
> is common for terminals and terminal emulators to recognize such a
> series of characters in the output and alter the terminal's behavior.

  ...oh I see...something like "commands"! :)

  ( "assembler for terminals" -- either it works or you gut stuck ;)

> The "colors" (aka "colours") function sets up an associative array
> with values that are various such terminal control strings (which
> would have been a better thing to call them than "escape sequences",
> but historically they were named the latter because they allow the
> terminal to "escape" from it's routine job of displaying and instead
> do something special).  So when you write $fg_bold[black], you are
> asking zsh to insert the control string that changes the terminal's
> foreground to bold and black.
> The trouble is that "escape sequnce" in the context of a prompt means
> one of the pairs of characters that begins with a percent (%) sign.
> Again this is from the concept of a special combination of characters
> causing a change (an escape from) the usual interpretation of such
> characters.
> ...do I understand this cxorrectly? In other words:
  The trouble is, that a escape seuence can be misinterpreted as a
> special sign of the prompt expanding itsself ?
> Thus, one uses "prompt escape sequences" to surround "terminal escape
> sequences," and this clash of terminology is often enough to confuse
> native English speakers; so you shouldn't feel too bad.
> }  And how should I figure out, whether the cursor position would
> }  have been changed...???
> In the worst case, you go look at the documentation for an ANSI standard
> terminal, find the control string that's being used, and determine from
> the definition whether any cursor movement is involved.

  URKS! I am not lazy in reading documentations, I am lesser good in
  understanding (english) documentations...but the effort must be in a
  reasonable relation to what I want to achieve.

> Usually, though, you just use your common sense.  Does the cursor move
> when the color changes from white to red, or plain to bold?  No, it does
> not, so the string value of $fg_bold[black] does not move the cursor.
> }  So I would guess this cames more closer to what is right:
> } 
> } 	   export PS1=%{$fg_bold[black]%}%M%{$fg_no_bold[black]%}:%2d
> } 
> }  but this one produces 
> } 
> }        }solfire:/home/mccramer
> Are you quite sure that you have all the % signs in the right places?
> My first suspicion would be that you wrote "PS1=%{$fg_bold[black]}..."
> (note missing % before the } there).

  I dont think, that braces got messed up. I checked that with
  MicroEmacs's (the editor I use to use...) "goto-matching-fence" and
  kept an eye on the %'s....

> This can also be affected by various setopts such as SH_WORD_SPLIT and
> PROMPT_SUBST and KSH_ARRAYS.  For example, $fg_bold[black] means
> something entirely different when KSH_ARRAYS is set.

  I didn't set KSH_ARRAYS and SH_WORD_SPLIT. But I am not sure whether
  I set "various setopts" ;)
> I strongly suggest that you unsetopt PROMPT_SUBST, and protect against
> SH_WORD_SPLIT by placing double quotes around the assignment:
>     export PS1="%{$fg_bold[black]%}%M%{$fg_no_bold[black]%}:%2d "
> }  Enclosing the whole thing in ${...} gives me no prompt at all.
> I'm surprised it didn't give a syntax error.  One almost never wants
> ${...} around "the whole thing" unless one understands exactly what
> one is doing.

  Yes, you are right...I didnt want it ;))))
> }  And what is the reason for the ps_beg/ps_end trick? Why no to write
> }  everyting in one big term ?
> Easier to read it, and to edit it later.  That's all.

Finally this works for me:

autoload -U colors && colors
export prompt=%{$fg_no_bold[red]%}%M%{$fg_no_bold[black]%}:%{$fg_no_bold[blue]%}
export PS1=$prompt

Setting PS1 directly without the addtional step using $prompt it does
not work.

No I am happy haveing a colored prompt -- only wihing that sometimes
zshall would be more understandable than totally complete. Only me two

Thank you very much for all your help and patience, Bart ! :O)

Have a nice day!

Messages sorted by: Reverse Date, Date, Thread, Author