Last active
May 17, 2018 11:14
-
-
Save courtney-miles/940e0b63dab8264bdd75908008c48568 to your computer and use it in GitHub Desktop.
Git Status for Forks
This file contains hidden or 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 | |
set -o errexit | |
set -o nounset | |
repl() { printf "$1"'%.s' $(eval "echo {1.."$(($2))"}"); } | |
get_ahead() { | |
git rev-list --count $1..$2 | |
} | |
get_behind() { | |
get_ahead $2 $1 | |
} | |
echo_ahead() { | |
if [ $1 -gt 0 ]; then | |
echo "[ahead \033[32m$1\033[00m] " | |
fi | |
} | |
echo_behind() { | |
if [ $1 -gt 0 ]; then | |
echo "[behind \033[31m$1\033[00m] " | |
fi | |
} | |
remote_branch_line() { | |
branch="$2" | |
remote_branch="${1}/${branch}" | |
if git branch -a | grep -q "${remote_branch}" ; then | |
ahead=$(get_ahead ${remote_branch} ${branch}) | |
behind=$(get_behind ${remote_branch} ${branch}) | |
echo "$(repl ' ' ${#branch}+1)\033[31m${remote_branch}\033[00m $(echo_ahead ${ahead})$(echo_behind ${behind})" | |
fi | |
} | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
origin_remote="$(git remote | sed -n 1p)" | |
upstream_remote="$(git remote | sed -n 2p)" | |
echo -e " $(remote_branch_line ${origin_remote} ${current_branch})" | |
echo -e " $(repl ' ' ${#current_branch})/" | |
echo -e " \033[32m${current_branch}\033[00m" | |
echo -e " $(repl ' ' ${#current_branch})\\" | |
echo -e " $(remote_branch_line ${upstream_remote} ${current_branch})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output...
