Skip to content

Instantly share code, notes, and snippets.

@mc-cat-tty
Forked from AMoreaux/robbyrussell.zsh-theme
Last active March 22, 2021 10:25
Show Gist options
  • Save mc-cat-tty/ec92e7eaf4cc9969aa5063d8f65af5d5 to your computer and use it in GitHub Desktop.
Save mc-cat-tty/ec92e7eaf4cc9969aa5063d8f65af5d5 to your computer and use it in GitHub Desktop.
Override oh-my-zsh robbyrussell theme with number of unpushed commits. It now works also inside subdirectories

robbyrussel with unpushed commits counter - ZSH theme

This is a fork of https://gist.github.com/AMoreaux/fb8df10b0de1d89fea45d8da5e467a86

Compared to his parent, this version adds the support for subdirectories inside the folder of a repo, which otherwise would not be recognized

Features

This configuration file override oh-my-zsh robbyrussel theme adding the number of unpushed commits; the counter is placed at the righmost position of the prompt

get_git_status() {
inside_git_repo="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
if [ "$inside_git_repo" ]; then;
upstream=`git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)`
if [ -z "$upstream" ]; then;
echo "%{$fg_bold[red]%}(No upstream)%{$reset_color%} "
else
count=`git log --oneline @{u}.. | wc -l | awk '{ print $1 }'`
if [ $count -gt 0 ]; then
echo "%{$fg_bold[red]%}($count)%{$reset_color%} "
fi
fi
fi
}
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)$(get_git_status)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment