Skip to content

Instantly share code, notes, and snippets.

@oshybystyi
Created June 10, 2015 10:28
Show Gist options
  • Save oshybystyi/475ee7768efc03727f21 to your computer and use it in GitHub Desktop.
Save oshybystyi/475ee7768efc03727f21 to your computer and use it in GitHub Desktop.
OhMyZsh plugin to display git status after a bunch of predefined git commands
#
# Run git status after specified set of command
#
# @author Oleksandr Shybystyi [email protected]
#
# default list of git commands `git status` is running after
gitPreAutoStatusCommands=(
'add'
'rm'
'reset'
'commit'
'checkout'
'mv'
'init'
)
# taken from http://stackoverflow.com/a/8574392/4647743
function elementInArray() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
function git() {
command git $@
if (elementInArray $1 $gitPreAutoStatusCommands); then
command git status
fi
}
@oshybystyi
Copy link
Author

Git auto status

If you found yourself constantly typing git status after bunch of commands like
git commit and you want to avoid that, than this plugin is for you.

This plugin is a nice addition to git_prompt_status.

Installation

You should read next wiki.

So you should put this file into ~/zsh_custom/plugins/git-auto-status and
modify plugins variable of your .zshrc so it contains
git_auto_status.

Note: It was necessary for me to put ZSH_CUSTOM=$HOME/zsh_custom at the
top of my .zshrc.

Tuning

The default list of command that git status is automatically running after is
next:

gitPreAutoStatusCommands=(
    'add'
    'rm'
    'reset'
    'commit'
    'checkout'
    'mv'
    'init'
)

You can adjust this list by setting this var in your .zshrc after
plugins=(...) initialization.

About git_prompt_status

There is not much information about what it is, but you will probably
understand it from next pr.

For example, I have next line for standard robbyrussel theme in my .zshrc:

PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)$(git_prompt_status)$(hg_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'

ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}%{$fg_bold[blue]%}) "
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_CLEAN=""

ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
ZSH_THEME_GIT_PROMPT_MODIFIED="*"
ZSH_THEME_GIT_PROMPT_ADDED="+"

Maintainer - @oshybystyi

@a-x-
Copy link

a-x- commented Jul 28, 2015

pull request: add mergetool

@OldskoolOrion
Copy link

being lazy : I like it 👍

@vunhan
Copy link

vunhan commented Jun 7, 2017

I loved it! This plugin is very fit my habbit.

@usmanajmal
Copy link

@oshybystyi
I added this file to ~/.oh-my-zsh/custom/plugins/git-auto-status/git-auto-status.plugin.zsh. Made it executable using chmod +x git-auto-status.plugin.zsh. And finally restarted my terminal but I don't see the plugin in action. Have I missed some step here?

@yokots
Copy link

yokots commented Oct 17, 2017

@tohuw
Copy link

tohuw commented May 6, 2018

@usmanajmal and @yokots:

...and modify plugins variable of your .zshrc so it contains git_auto_status

@Minimuino
Copy link

Really handy plugin! Thanks! :)

For me it was necessary to update plugins variable of my .zshrc so it contains git-auto-status (with hyphen). I tried first with git_auto_status (with underscore) as it is said in the description, but it didn't work. Don't know why, but I guess the name of the plugin directory and the name on .zshrc must be the same.

@piotr-szewczuk
Copy link

Hi,
I have a problem with it. When I am in repo it works like a charm :) but when I am not every action in terminal returns:

VCS_INFO_git_getbranch:44: no such file or directory: /HEAD
fatal: not a git repository (or any of the parent directories): .git 

Someone now how to fix it?

@c0d3z3r0
Copy link

c0d3z3r0 commented Jun 5, 2020

Just in case someone is looking for this in bash:

gitPreAutoStatusCommands=(
  'add'
  'rm'
  'mv'
  'checkout'
  'rebase'
)

function git() {
  command git "${@}"

  if [[ " ${gitPreAutoStatusCommands[@]} " =~ " ${1} " ]]; then
    echo  # empty line
    command git status
  fi  
}

@FdelMazo
Copy link

Automatically clone it in the correct ohmyzsh dir:

git clone https://gist.github.com/475ee7768efc03727f21.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-auto-status

@tiagobalsas
Copy link

Did not work in my macOS terminal!

@JasonLandbridge
Copy link

@oshybystyi Please update the description where it says

So you should put this file into ~/zsh_custom/plugins/git-auto-status and
modify plugins variable of your .zshrc so it contains
git_auto_status.

with "git-auto-status" instead of "git_auto_status"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment