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
}
@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