1
0

Add recursive git function for bash and zsh

This commit is contained in:
Noah 2016-06-16 11:24:19 -07:00
parent 440792005d
commit 86e2c8944c
3 changed files with 53 additions and 0 deletions

View File

@ -197,3 +197,9 @@ fi
if [ -f ~/.localbashrc ]; then
. ~/.localbashrc
fi
###
# Import common functions (bash/zsh)
###
. ~/.common.sh

41
home/.common.sh Normal file
View File

@ -0,0 +1,41 @@
###
# Common shell functions/aliases between bash and zsh.
###
################################################################################
## Functions
################################################################################
# Recursively traverse directory tree for git repositories, run git command
# e.g.
# rgit status
# rgit diff
#
# Credit:
# http://chr4.org/blog/2014/09/10/gittree-bash-slash-zsh-function-to-run-git-commands-recursively/
rgit() {
if [ $# -lt 1 ]; then
echo "Usage: rgit <command>"
return 1
fi
for gitdir in $(find . -type d -name .git); do
# Display repository name in bold orange text.
repo=$(dirname $gitdir)
echo -e "\e[1;38;5;208m$repo\e[0m"
# Run git command in the repository's directory
cd $repo && git $@
ret=$?
# Return to calling directory (ignore output)
cd - >/dev/null
# Abort if cd or git command fails
if [ $ret -ne 0 ]; then
return 1
fi
echo
done
}

View File

@ -192,3 +192,9 @@ ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=fg=27
# Finalize and export the prompt
export PROMPT=$base_prompt
###
# Import common functions (bash/zsh)
###
. ~/.common.sh