Last active
October 3, 2016 13:51
-
-
Save rk295/0679c2ed2ae9346856fb98da9dbb2176 to your computer and use it in GitHub Desktop.
This is a new command for [gg-core](https://github.com/fidian/gg-core), the tech behind [gg](https://github.com/fidian/gg). This adds the ability to print the current branch for all 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
#!/usr/bin/env bash | |
commandAdd branch cmdBranch | |
cmdBranchHelp() { | |
cat <<EOF | |
branch Shows which branch each repository is on. | |
EOF | |
} | |
# Get the current branch of the project. | |
cmdBranch() { | |
projectForEach cmdBranchEach | |
} | |
# Called for each project. Shows which branch each repository is on. | |
# | |
# $1 - Project identifier. | |
# | |
# Always returns true. Can never fail. | |
cmdBranchEach() { | |
local path branchResult | |
path="$(getProjectConfig "$1" path)" | |
if [[ -z "$path" ]]; then | |
status "$1: No path set." | |
return 0 | |
fi | |
if [[ ! -d "$path" ]]; then | |
status "$1: Not checked out." | |
return 0 | |
fi | |
branchResult=$(cd "$path" ; git branch | grep \* | cut -d ' ' -f2) | |
if echo "$branchResult" | grep -q "^nothing to commit, working directory clean$"; then | |
status "$1: clean" | |
else | |
status "$1: dirty" | |
echo "$branchResult" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment