-
-
Save nemtsov/7713373 to your computer and use it in GitHub Desktop.
Recursive (1-level) git status and git pull
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function _git { | |
git --git-dir=$1/.git --work-tree=$1 $2 | |
} | |
function _git_pull { | |
_git $i fetch && \ | |
_git $i "merge origin/master" | grep -v "Already up-to-date." | |
} | |
function _git_info { | |
local git_pull=`_git_pull $i` | |
if [ -n "$git_pull" ]; then | |
local git_pull="\n$git_pull\n" | |
local status_icon='\n✗' | |
else | |
local status_icon=' ' | |
fi | |
printf "$status_icon $i\n" | |
} | |
for i in ./*; do _git_info $i; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function _git { | |
git --git-dir=$1/.git --work-tree=$1 $2 | |
} | |
function _git_status { | |
_git $i status | \ | |
grep -v "# On branch *" | \ | |
grep -v "nothing *" | |
} | |
function _repo_info { | |
local branches=`_num_branches $1` | |
local stashes=`_has_stash $1` | |
local out="$branches" | |
if [ -n "$branches" -a -n "$stashes" ]; then local out="$out | "; fi | |
local out="$out$stashes" | |
if [ -n "$out" ]; then local out="- ($out)"; fi | |
echo $out | |
} | |
function _num_branches { | |
local num_str=`_git $1 'for-each-ref refs/heads' | wc -l` | |
local num=`expr $num_str - 1` | |
if [ $num = 1 ]; then | |
echo "1 branch" | |
else | |
echo '' | |
fi | |
} | |
function _has_stash { | |
_git $i 'rev-parse --verify refs/stash' >/dev/null 2>&1 | |
if [ $? = 0 ]; then | |
echo 'stached changes' | |
else | |
echo '' | |
fi | |
} | |
function git_info { | |
local repo_info=`_repo_info $1` | |
local git_status=`_git_status $1` | |
if [ -n "$git_status" -o -n "$repo_info" ]; then | |
local status_icon='✗' | |
else | |
local status_icon=' ' | |
fi | |
if [ -n "$git_status" ]; then | |
local status_icon="\n$status_icon" | |
local git_status="\n$git_status\n" | |
fi | |
printf "$status_icon $i $repo_info $git_status\n" | |
} | |
for i in ./*; do git_info $i; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment