简体   繁体   English

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

[英]How to use posh-git-bash in oh-my-zsh?

I can use the posh-git-bash in normal bash shell, but I can't use it under oh-my-zsh. 我可以在普通的bash shell中使用posh-git-bash,但不能在oh-my-zsh下使用。

First of all, I follow github project posh-git-sh to create ~/git-prompt.sh, and add the following scripts to the bottom of file ~/.bashrc 首先,我遵循github项目posh-git-sh创建〜/ git-prompt.sh,并将以下脚本添加到文件〜/ .bashrc的底部

source ~/git-prompt.sh
PROMPT_COMMAND='__posh_git_ps1 "\u@\h:\w" "\\\$ ";'$PROMPT_COMMAND

reopen the terminal, and go to a git project folder, all the git prompts are correct and as I expected. 重新打开终端,并转到git project文件夹,所有git提示均正确,并符合我的预期。 eg 例如

Orion@Orions-machine-1:~/Source/MyProjects/deploy_tools [master ≡ +0 ~1 -0 | +1 ~0 -0]$

Then, I follow the github project oh-my-zsh to install zsh and oh-my-zsh. 然后,我遵循github项目oh-my-zsh来安装zsh和oh-my-zsh。 I choose the 'crcandy' theme, and add the scripts to the bottom of file ~/.zshrc. 我选择“ crcandy”主题,并将脚本添加到文件〜/ .zshrc的底部。

But it always uses the format defined in theme 'crcandy', just show a '*' in prompt. 但是它始终使用主题“ crcandy”中定义的格式,只是在提示中显示“ *”。

Orion@Orions-machine-1 [10:25:57] [~/Source/MyProjects/deploy_tools] [master *]

The file ~/.oh-my-zsh/themes/crcandy.zsh-theme content: 文件〜/ .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=""

Anybody could give me help, and make them work together? 有人可以给我帮助,让他们一起工作吗?

Issue #14 : 问题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. 我检查了git提示符插件中的oh-my-zsh ,看来git提示符插件设置了RPROMPT ,大概是为了避免踩到主题设置的PROMPT变量。

I refactored a little bit, so in your .zshrc , you can easily get a posh git status indicator. 我进行了一些重构,因此在您的.zshrc ,您可以轻松获得高级git status指示器。

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

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

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