Skip to content

Instantly share code, notes, and snippets.

@gnuwilliam
Created October 31, 2014 19:10
Show Gist options
  • Save gnuwilliam/5d3f4b3d371cad7a79d7 to your computer and use it in GitHub Desktop.
Save gnuwilliam/5d3f4b3d371cad7a79d7 to your computer and use it in GitHub Desktop.
Get git branch info - shell
function parse_git_deleted {
[[ $(git status --ignore-submodules 2> /dev/null | grep deleted:) != "" ]] && echo "-"
}
function parse_git_added {
[[ $(git status --ignore-submodules 2> /dev/null | grep "Untracked files:") != "" ]] && echo '+'
}
function parse_git_modified {
[[ $(git status --ignore-submodules 2> /dev/null | grep modified:) != "" ]] && echo "*"
}
function parse_git_dirty {
echo "$(parse_git_added)$(parse_git_modified)$(parse_git_deleted)"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1$(parse_git_dirty))/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment