简体   繁体   English

Zsh主题在OSX上无法正常工作

[英]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. 刚刚开始使用zsh,但我在使主题工作方面遇到了很多麻烦。 Here is what is showing on my ZSH prompt: 以下是我的ZSH提示中显示的内容:

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

My ~/.zshrc 我的〜/ .zshrc

source ~/.antigen.zsh

antigen theme jdavis/zsh-files themes/jdavis

Thanks 谢谢

TL;DR: Corrected .zshrc is provided at the bottom. TL; DR:已更正.zshrc位于底部。 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: 检查antigen.zshjdavis.zsh-theme ,它看起来像你有两个问题:

  1. You haven't loaded and executed the colors function anywhere. 您没有在任何地方加载和执行colors功能 Add

     autoload -U colors && colors 

    to your .zshrc . 你的.zshrc

  2. PROMPT is single-quoted and not parsed. PROMPT是单引号而不是解析的。 You need to use the PROMPT_SUBST option option to parse the prompt string. 您需要使用PROMPT_SUBST选项选项来解析提示字符串。 Add

     setopt promptsubst 

    to your .zshrc . 你的.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 所以你的.zshrc应该是这样的

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. 看起来你正试图使用​​来自Oh-my-zsh的颜色代码的提示,也许你还没有定义那些颜色。 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 . 尝试将来自Oh-my-zsh的spectrum.zsh文件(如果您不想运行整个包)添加到源列表,或者 (不够,请参阅注释)将提示中的颜色重新定义为默认的zsh颜色 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): 您可以使用的颜色发挥spectrum_ls中定义的函数spectrum.zsh或在这一个班轮改变数值(051是一个明亮的蓝绿色):

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): 这是一个没有定义颜色的提示(顶部)的示例,以及在定义PROMPT (底部)之前已经获取Oh-my-zsh的提示: Zsh提示示例

Edit: 编辑:

See the answer by 4ae1e1 for the individual requirements (Oh-my-zsh automatically sets them). 有关个别要求,请参阅4ae1e1的答案(Oh-my-zsh会自动设置它们)。

PATH is single quoted by default, and is not parsed because of this. 默认情况下, PATH是单引号,因此不会对其进行解析。 Rewrite the var with double quoted string 用双引号字符串重写var

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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