【问题标题】:How to use posh-git-bash in oh-my-zsh?如何在 oh-my-zsh 中使用 posh-git-bash?
【发布时间】:2016-07-01 02:50:48
【问题描述】:

我可以在普通的 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=""

谁能帮我,让他们一起工作?

【问题讨论】:

    标签: git bash shell


    【解决方案1】:

    Issue #14:

    I examined the git prompt plugin for oh-my-zsh, and it seems that the git prompt plugin sets RPROMPT, 大概是为了避免踩到由设置的PROMPT 变量 主题。

    我稍微重构了一下,所以在你的.zshrc,你可以很容易地得到一个 豪华的 git 状态指示器。

    . posh-git-sh/git-prompt.sh
    RPROMPT='$(__posh_git_echo)'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 2018-04-11
      相关资源
      最近更新 更多