我可以在普通 bash shell 中使用 posh-git-bash,但不能在 oh-my-zsh 下使用它。
首先我关注github项目posh-git-sh创建 ~/git-prompt.sh,并将以下脚本添加到文件 ~/.bashrc 的底部
source ~/git-prompt.sh
PROMPT_COMMAND='__posh_git_ps1 "\u@\h:\w" "\\\$ ";'$PROMPT_COMMAND
重新打开终端,然后转到 git 项目文件夹,所有 git 提示都是正确的,符合我的预期。例如
Orion@Orions-machine-1:~/Source/MyProjects/deploy_tools [master ≡ +0 ~1 -0 | +1 ~0 -0]$
然后,我关注github项目oh-my-zsh安装 zsh 和 oh-my-zsh。我选择“crcandy”主题,并将脚本添加到文件 ~/.zshrc 的底部。
但它总是使用主题'crcandy'中定义的格式,只是在提示符中显示一个'*'。
Orion@Orions-machine-1 [10:25:57] [~/Source/MyProjects/deploy_tools] [master *]
文件 ~/.oh-my-zsh/themes/crcandy.zsh-theme 内容:
PROMPT=$'
%{$fg_bold[green]%}%n@%m %{$fg[blue]%}%D{[%I:%M:%S]} %{$reset_color%}%{$fg[white]%}[%~]%{$reset_color%} $(git_prompt_info)\
%{$fg[blue]%}->%{$fg_bold[blue]%} %#%{$reset_color%} '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}*%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
有人可以给我帮助,让他们一起工作吗?
最佳答案
I examined the git prompt plugin for
oh-my-zsh
, and it seems that the git prompt plugin setsRPROMPT
, presumably to avoid stepping on thePROMPT
variable set by the theme.I refactored a little bit, so in your
.zshrc
, you can easily get a posh git status indicator.. posh-git-sh/git-prompt.sh RPROMPT='$(__posh_git_echo)'
关于git - 如何在 oh-my-zsh 中使用 posh-git-bash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38136266/