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

Re: Colored PS1

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."

"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.

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

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.

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).

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 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.
}  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.

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