简体   繁体   中英

Zsh theme not working properly on OSX

Just got started with zsh yesterday but I'm having a lot of trouble getting themes to work. Here is what is showing on my ZSH prompt:

$fg[cyan][$fg[white] keithy $fg[cyan]] [$fg[white]~/Desktop$fg[cyan]] >$reset_color

My ~/.zshrc

source ~/.antigen.zsh

antigen theme jdavis/zsh-files themes/jdavis

Thanks

TL;DR: Corrected .zshrc is provided at the bottom. You might want to try it first, see it working, then come back to read the explanations.


Inspecting antigen.zsh and jdavis.zsh-theme , it looks like you have two problems:

  1. You haven't loaded and executed the colors function anywhere. Add

     autoload -U colors && colors 

    to your .zshrc .

  2. PROMPT is single-quoted and not parsed. You need to use the PROMPT_SUBST option option to parse the prompt string. Add

     setopt promptsubst 

    to your .zshrc . What the option does, according to the linked documentation:

    If set, parameter expansion , command substitution and arithmetic expansion are performed in prompts. Substitutions within prompts do not affect the command status.

So your .zshrc should look like

source ~/.antigen.zsh
autoload -U colors && colors
setopt promptsubst
antigen theme jdavis/zsh-files themes/jdavis

It looks like you're trying to use a prompt with color codes from Oh-my-zsh , and perhaps you haven't defined those colors. Try adding the spectrum.zsh file from Oh-my-zsh (if you don't want to run the entire package) to your source list, or (not sufficient, see comments) redefining the colors in your prompt to default zsh colors . You can play with the colors using the spectrum_ls function defined in spectrum.zsh or by changing numeric values in this one-liner (051 is a bright cyan):

zsh -c 'print -P -- "%F{051}Hello, World%f"'

Here is an example of a prompt without the colors defined (top), and a prompt where Oh-my-zsh has been sourced prior to defining PROMPT (bottom): Zsh提示示例

Edit:

See the answer by 4ae1e1 for the individual requirements (Oh-my-zsh automatically sets them).

PATH is single quoted by default, and is not parsed because of this. Rewrite the var with double quoted string

PATH="$PATH"
source ~/.antigen.zsh
antigen theme jdavis/zsh-files themes/jdavis

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM