Created
September 21, 2015 06:16
-
-
Save adamheins/ea63e197bef97091c535 to your computer and use it in GitHub Desktop.
Get the current branch for your git repo in bash.
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
#/bin/bash | |
# If the cwd is a git repo, display the branch name in the tmux status bar. | |
get_git_branch() { | |
if [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then | |
local branch short_branch | |
branch=$(git symbolic-ref -q HEAD) | |
branch=${branch##refs/heads/} | |
branch=${branch:-HEAD} | |
short_branch=$(echo "$branch" | cut -c1-20) | |
if [ ${#branch} -gt ${#short_branch} ]; then | |
short_branch=${short_branch}... | |
fi | |
GIT_BRANCH=$short_branch | |
else | |
GIT_BRANCH= | |
fi | |
} | |
PROMPT_COMMAND="get_git_branch; $PROMPT_COMMAND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment