From a367e40cf362cb40bf58bccc32fa53f2755024b7 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Wed, 24 Feb 2021 16:21:08 +0100 Subject: [PATCH] Add git-auto-status zsh plugin --- .config/zsh/.zshrc | 1 + .../git-auto-status.plugin.zsh | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .config/zsh/custom/plugins/git-auto-status/git-auto-status.plugin.zsh diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 381368a..147ec78 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -85,6 +85,7 @@ plugins=( encode64 extract git + git-auto-status jump kubectl safe-paste diff --git a/.config/zsh/custom/plugins/git-auto-status/git-auto-status.plugin.zsh b/.config/zsh/custom/plugins/git-auto-status/git-auto-status.plugin.zsh new file mode 100644 index 0000000..318262e --- /dev/null +++ b/.config/zsh/custom/plugins/git-auto-status/git-auto-status.plugin.zsh @@ -0,0 +1,31 @@ +# +# 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' + '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 +}