7

Actually Im using a slightly modified version of the oh my zsh theme blinks. It show a SSH statement just for optical difference to my local terminal. Also it show the branch and a little star if there are uncommitted changes in the branch.

Is it possible to show that there are unpushed commitments? Maybe also with a little indicator.

# https://github.com/blinks zsh theme

function _prompt_char() {
  if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
    echo "%{%F{blue}%}±%{%f%k%b%}"
  else
    echo ' '
  fi
}

case ${SOLARIZED_THEME:-dark} in
    light) bkg=white;;
    *)     bkg=black;;
esac

ZSH_THEME_GIT_PROMPT_PREFIX=" [%{%B%F{blue}%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{%f%k%b%K{${bkg}}%B%F{green}%}]"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{%F{red}%}*%{%f%k%b%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""

PROMPT='%{%f%k%b%}

%{%K{black}%B%F{green}%}%n%{%B%F{blue}%}@%{%B%F{cyan}%}%m%{%B%F{green}%} %{%B%F{red}%}!!SSH!! %{%b%F{yellow}%K{black}%}%~%{%B%F{green}%}$(git_prompt_info)%E%{%f%k%b%}
%{%K{black}%}$(_prompt_char)%{%K{black}%} %#%{%f%k%b%} '

RPROMPT='!%{%B%F{cyan}%}%!%{%f%k%b%}'

thanks in advance denym

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Denny Mueller
  • 3,505
  • 5
  • 36
  • 67
  • 2
    Can you determine if you have unpushed commits without a network round-trip? In not then you don't want it in your prompt... – Douglas Leeder May 02 '13 at 14:37

4 Answers4

3

Just set ZSH_THEME="mortalscumbag" in your ~/.zshrc... It supports the "unpushed" state...

1 file changed, 1 insertion(+), 1 deletion(-)

(ssh) mdesales@pppdc9prd08i ‹ master ↑ › : ~/.oh-my-zsh

The "up arrow" shows that there are unpushed commits...

853102c dosdok
(END)
Marcello DeSales
  • 21,361
  • 14
  • 77
  • 80
1

I really like explicit answers so I just looked into the theme provided by Marcello de Sales (depending on your install you should be able to find your themes in the ~/.oh-my-zsh/themes/ directory).

Simply use the ZSH_THEME_GIT_PROMPT_AHEAD global variable.

Here's an example showing a cyan arrow to the right:

ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_no_bold[cyan]%}->"

Additionally, here's a great post which goes into a lot of detail explaining how to customize your zsh theme.

Keith
  • 154
  • 1
  • 8
0

Just test output from the commands in this answer. That'll output your HEAD state against your local reference to origin/master, which is about as good as you can get without doing something against the remote, which as Douglas notes in his comment is an ill-fated idea.

Community
  • 1
  • 1
Christopher
  • 42,720
  • 11
  • 81
  • 99
0

You should use vcs_info module come with zsh.

There is a very detail tutorial shows you how to do it: http://arjanvandergaag.nl/blog/customize-zsh-prompt-with-vcs-info.html

Normally you only need to have ${vcs_info_msg_0_} in your $PROMPT variable after you properly load the vcs_info module, but you can customized the prompt format if you don't like the default one.

BTW, vcs_info, as the name has suggested, also support other VCSs, e.g. svn, hg, cvs, etc.

number5
  • 15,913
  • 3
  • 54
  • 51
  • 3
    So, how does one go about configuring `vcs_info` to display information about unpushed commits (i.e., commits that do not exist in the branch being tracked)? This answer is incomplete, at best. – chepner May 04 '13 at 15:49
  • @chepner If you have some time to read the article I linked in above answer, you might already know how to. fyi, copied from the article > %u Show unstaged changes in the repository > %c Show staged changes in the repository > > zstyle ':vcs_info:git*' formats "%s %r/%S %b (%a) %m%u%c " – number5 May 06 '13 at 06:29
  • thanks for sharing this interesting article, it's hard to find stuff about this topic. However, staged changes (%c) and unstaged changes (%u) are not the same thing as unpushed commits – Pierre-Adrien Jun 11 '22 at 11:20