Created
April 26, 2011 04:30
-
-
Save whazzmaster/941791 to your computer and use it in GitHub Desktop.
Shell function that shows a summary of all your current projects
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
function minutes_since_last_commit { | |
now=`date +%s` | |
last_commit=`git log --pretty=format:'%at' -1` | |
seconds_since_last_commit=$((now-last_commit)) | |
minutes_since_last_commit=$((seconds_since_last_commit/60)) | |
echo $minutes_since_last_commit | |
} | |
function has_modified_files { | |
status=`git status` | |
if [[ "$status" =~ "working directory clean" ]]; then | |
echo '' | |
else | |
echo 1 | |
fi | |
} | |
function cps() { | |
echo "" | |
echo "======================================" | |
echo " Cross-Project Status " | |
echo "======================================" | |
echo "" | |
echo "Getting status for all projects in ${MY_PROJECT_DIR}" | |
echo "" | |
local origdir=`pwd` | |
#for dir in "${projdir}" | |
for dir in ${MY_PROJECT_DIR} | |
do | |
cd $dir | |
if [ -f .cps-ignore ]; then | |
# Skip any directory where we created a .cps-ignore file | |
continue | |
fi | |
if [ -n "$(__gitdir)" ]; then | |
local shortdir=`basename $(pwd)` | |
echo "$shortdir: $(grb_git_prompt)" | |
if [ -n "$(has_modified_files)" ]; then | |
git status 2>&1 | sed 's/^/ /' | |
fi | |
fi | |
done | |
cd $origdir | |
echo "" | |
} | |
function grb_git_prompt() { | |
local g="$(__gitdir)" | |
if [ -n "$g" ]; then | |
if [ -n "$(has_modified_files)" ]; then | |
local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit` | |
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then | |
local COLOR=${RED} | |
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then | |
local COLOR=${YELLOW} | |
else | |
local COLOR=${GREEN} | |
fi | |
local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${NORMAL}" | |
# The __git_ps1 function inserts the current git branch where %s is | |
local GIT_PROMPT=`__git_ps1 "(%s|${SINCE_LAST_COMMIT})"` | |
echo ${GIT_PROMPT} | |
else | |
local COLOR=${GREEN} | |
local NO_CHANGES="${COLOR}clean${NORMAL}" | |
local GIT_PROMPT=`__git_ps1 "(%s|${NO_CHANGES})"` | |
echo ${GIT_PROMPT} | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment