diff --git a/plugins/git-auto-status/README.md b/plugins/git-auto-status/README.md new file mode 100644 index 000000000..1157f3c46 --- /dev/null +++ b/plugins/git-auto-status/README.md @@ -0,0 +1,26 @@ +# 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. + +### Tuning + +The default list of command that git status is automatically running after is +next: + +```bash +gitPreAutoStatusCommands=( + 'add' + 'rm' + 'reset' + 'commit' + 'checkout' +) +``` + +You can adjust this list by setting this var in your **.zshrc** after +`plugins=(...)` initialization. + +### Maintainers + +[@oshybystyi](https://github.com/oshybystyi/) diff --git a/plugins/git-auto-status/git-auto-status.plugin.zsh b/plugins/git-auto-status/git-auto-status.plugin.zsh new file mode 100644 index 000000000..e328d122a --- /dev/null +++ b/plugins/git-auto-status/git-auto-status.plugin.zsh @@ -0,0 +1,29 @@ +# +# Run git status after specified set of command +# +# @author Oleksandr Shybystyi oleksandr.shybystyi@gmail.com +# + +# default list of git commands `git status` is running after +gitPreAutoStatusCommands=( + 'add' + 'rm' + 'reset' + 'commit' + 'checkout' +) + +# 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 +}