git - 如何在 oh-my-zsh 中使用 posh-git-bash?

标签 git bash shell

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

有人可以给我帮助,让他们一起工作吗?

最佳答案

Issue #14 :

I examined the git prompt plugin for oh-my-zsh, and it seems that the git prompt plugin sets RPROMPT, presumably to avoid stepping on the PROMPT 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/

相关文章:

git - 当我将其代码上传到 github 时,如何 stash 我的 discord 机器人 token ?

macos - RAM 中的音频文件并播放 - Bash 4.3.42

bash - error= 和 error ='' 的区别

bash - Shell 条件错误 - Bash 语法无法识别

linux - 如何在Linux中使用printf解决此问题?

git - Redmine 使用 gitolite 对 git 仓库的权限

git - 致命的 : remote origin already exists - GitHub

linux - 命令行调用将目录中的文件根据文件大小分为三个子目录,分别命名为小、中和大

linux - 在 Azure 中执行 git 命令并发布

bash - PostgreSQL - pg_config -bash : pg_config: command not found