Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Custom Colors #1101

Closed
MMore opened this issue May 1, 2012 · 6 comments
Closed

Define Custom Colors #1101

MMore opened this issue May 1, 2012 · 6 comments

Comments

@MMore
Copy link
Contributor

MMore commented May 1, 2012

I tried to setup some custom colors in my zsh according to http://www.dawoodfall.net/index.php/custom-zsh-prompts. But it does not work.

ugrey="%{^[[01;04;30m%}"
PROMPT="%(!.%{$fg[red]%}.$ugrey%n@)%m:%{$fg_bold[green]%}%c %{$reset_color%}%# "

But in my shell this appears: ^[[01;04;30muser@host:~ %

Anyone?

@bendemaree
Copy link

oh-my-zsh uses spectrum by @sykora: https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/

So you can do something like this:

eval my_orange='$FG[202]'
eval my_purple='$FG[098]'
eval my_yellow='$FG[228]'

to retrieve colors from the $FG variable. They must be three digit zero-padded.

Enjoy!

@MMore
Copy link
Contributor Author

MMore commented May 6, 2012

Ok, I just tried your code.

eval my_purple='$FG[228]'
PROMPT="$my_purple%c %{$reset_color%}%# "

Result is a blinking path. There is no color, only my default color. Besides that, I am able to use predefined colors like %{$fg[red]%}. Do you have any ideas?

@bendemaree
Copy link

You must be sure you're actually using a 256-color terminal mode. For instance, on Ubuntu, one must usually run

export TERM="xterm-256color"

to enable 256-color support in Gnome Terminal. The reason I say this is it happened to me the other day...things were blinking and underlined and whatnot.

@MMore
Copy link
Contributor Author

MMore commented May 6, 2012

I am using the Terminal App of OSX. It seems to be that it ignores this TERM setting. In the preferences of this app there is also no option to enable the 256 color mode.

Is there another possibility to set custom colors in zsh?

Thank you!

@bendemaree
Copy link

I can't help much with Terminal.app; I use iTerm2 and you should check it out. It will support 256 colors.

The issue is not ZSH. Color codes must be interpreted by the terminal app. If the terminal only has limited (16 color) support, other codes will fall back to somewhat unpredictable values (like the blinking effect). The terminal must be able to parse the codes (like the ones you were originally working with, that are now supplied by the $FG variable) to show the colors.

@apjanke
Copy link
Contributor

apjanke commented Jun 8, 2015

FYI, current versions of Terminal.app have 256 color support, at least since Lion. (It declares $TERM as xterm-256color by default.) The setting for what $TERM it declares is in Preferences > Settings > Advanced > "Declare terminal as:", and is set on a per-profile basis.

BTW, inside prompts, you can use the more concise %F/%f codes. (%F{color} to start a color, %f to return to the default color.) Your prompt can be rewritten like this, and it works fine for me in Terminal.app on OS X 10.9.5.

PROMPT='%(!.%F{red}.%F{241}%n)@%m:%B%F{green}%c%f%b # '

screen shot 2015-06-08 at 9 59 48 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants