bash 如何在 Macbook 上为 oh-my-zsh 更改 $PS1?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35281630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change my $PS1 on a Macbook for oh-my-zsh?
提问by Daniel Dao
I'm trying to find the PS1 variable in oh-my-zsh and change it so iTerm doesn't look as clogged up. Running the following command:
我正在尝试在 oh-my-zsh 中找到 PS1 变量并对其进行更改,以便 iTerm 看起来不会被阻塞。运行以下命令:
echo $PS1
gives me this
给我这个
%{%f%b%k%}$(build_prompt)
Additionally, I've attempted to edit the .zshrc file and put
另外,我试图编辑 .zshrc 文件并把
export PS1="random-text"
but it didn't work. I've tried to look around for the PS1 variable, but couldn't locate it.
但它没有用。我试图四处寻找 PS1 变量,但找不到它。
If it also helps, I'm running El Capitan on my laptop right now. I couldn't find any similar questions to what I posted so any help would be greatly appreciated.
如果它也有帮助,我现在正在我的笔记本电脑上运行 El Capitan。我找不到与我发布的内容类似的问题,因此将不胜感激。
回答by Caleb Adams
Changing your Theme:
改变你的主题:
To edit your prompt in oh-my-zsh you need to edit a PROMPT
variable in your theme instead of PS1
. In your .zshrc file you will find a line that looks something like this:
要在 oh-my-zsh 中编辑提示,您需要PROMPT
在主题中编辑变量而不是PS1
. 在您的 .zshrc 文件中,您将找到如下所示的一行:
ZSH_THEME="themename"
oh-my-zsh stores these themes in the ~/.oh-my-zsh/themes
folder. If you ls ~/.oh-my-zsh/themes
you will see a list of themes that you can change. The above theme would be named themename.zsh-theme
in this directory.
oh-my-zsh 将这些主题存储在~/.oh-my-zsh/themes
文件夹中。如果您ls ~/.oh-my-zsh/themes
将看到可以更改的主题列表。上述主题将themename.zsh-theme
在此目录中命名 。
Customizing your Theme:
自定义您的主题:
If you want a simple way to customize your oh-my-zsh theme you can copy a file already in this theme folder and edit that.
如果您想要一种简单的方法来自定义您的 oh-my-zsh 主题,您可以复制此主题文件夹中已有的文件并进行编辑。
To change your prompt simply edit the PROMPT
variable. For example:
要更改提示,只需编辑PROMPT
变量即可。例如:
PROMPT=">>"
This would make two >
's your prompt.
这将使两个>
提示。
I like editing the already existing simple theme. the simple.zsh-theme file looks like this:
我喜欢编辑已经存在的简单主题。simple.zsh-theme 文件如下所示:
PROMPT='%{$fg[green]%}%~%{$fg_bold[blue]%}$(git_prompt_info)%{$reset_color%} '
ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" ?"
ZSH_THEME_GIT_PROMPT_CLEAN=" ?"
Applying the Changes:
应用更改:
Now just change the theme in your in your .zshrc file:
现在只需更改 .zshrc 文件中的主题:
ZSH_THEME="simple"
And reload oh-my-zsh with:
并使用以下命令重新加载 oh-my-zsh:
. ~/.zshrc
回答by Alvin Smith
For POWERLEVEL9K
对于 POWERLEVEL9K
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir)
回答by blondeau
To edit PS1 in zsh:
在 zsh 中编辑 PS1:
PS1='[random-text]'