Skip to content

Instantly share code, notes, and snippets.

@rafaeldff
Last active December 26, 2015 13:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeldff/7158274 to your computer and use it in GitHub Desktop.
Save rafaeldff/7158274 to your computer and use it in GitHub Desktop.
Status overview for multiple git repositories
#! /bin/bash
normal=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)
lime_yellow=$(tput setaf 190)
REVERSE=$(tput smso)
function column-err {
#printf "${REVERSE}${red}%-8s${normal}" "$1"
printf "\033[41m%-10s\033[0m" "$1"
}
function column-ok {
printf "\033[32m%-10s\033[0m" "$1"
}
function column-heading {
printf "\e[48;5;237m%-19s\e[0m" "$1"
}
function proj_name() {
column-heading $(pwd | sed 's,^.*/,,')
}
function dirty_state() {
if ( ! git diff --no-ext-diff --quiet --exit-code ) ||
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
then
column-err "dirty"
else
column-ok "clean"
fi
}
function local_state() {
__git_ps1_show_upstream
case $p in
"<>" | ">")
column-err "To push"
;;
*)
column-ok "push ok"
;;
esac
}
function remote_state() {
__git_ps1_show_upstream
case $p in
"<>" | "<")
column-err "To pull"
;;
*)
column-ok "pull ok"
;;
esac
}
function project_status() {
pushd $1/.. > /dev/null
proj_name;
git fetch 1> /dev/null 2> /dev/null
dirty_state; local_state; remote_state;
echo
popd > /dev/null
}
export -f __git_ps1_show_upstream
export -f column-err
export -f column-ok
export -f column-heading
export -f proj_name
export -f dirty_state
export -f local_state
export -f remote_state
export -f project_status
function gallstatus() {
find . -type d -name '.git' -exec bash -c "project_status {}" \;
}
@rafaeldff
Copy link
Author

Needs git-prompt.sh to be sourced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment