简体   繁体   中英

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.

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

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. 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. I choose the 'crcandy' theme, and add the scripts to the bottom of file ~/.zshrc.

But it always uses the format defined in theme 'crcandy', just show a '*' in prompt.

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

The file ~/.oh-my-zsh/themes/crcandy.zsh-theme content:

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 :

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)' 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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