I'm trying to create a simple prompt using escape characters to define the colors of the prompt components:
PROMPT=$'\e[0;35m%n\e[0m \e[0;92m%~\e[0m \e[0;97m$ \e[0m'
This works fine except for one thing - when I go to tab-complete my cursor (and the associated command to be completed) gets shifted to the right.
A little googling led me here: https://github.com/robbyrussell/oh-my-zsh/issues/23
Changing the prompt formatting to something like:
PROMPT='%{$fg[green]%}%n%'
fixes the problem. However, the green, magenta, blue, etc. color options are more limiting in terms of the colors that you can choose than using the escape characters along with the color codes shown above.
I cannot figure out how to format the first prompt shown above so that the tab completion issue goes away. I've a tried a few different permutation with regards to where to put the %{ and they all just end up breaking prompt string.
What is the correct way to format this? OR, is there a way to access more colors using the $fg[COLOR]
scheme than red, blue, magenta, etc.?
You could put the %{
… %}
around the escape characters.
%{...%}
Include a string as a literal escape sequence. The string within the braces should not change the cursor position.
--
zshmisc(1) SIMPLE PROMPT ESCAPES, Visual effects
So, the below simplified erroneuos case,
PROMPT=$'\e[0;35m%n\e[0m '
could be
PROMPT=$'%{\e[0;35m%}%n%{\e[0m%} '
And why PROMPT='%{$fg[green]%}%n%'
works because the escape sequences which $fg[green]
produces are correctly wrapped within %{...%}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With