Last active
February 7, 2024 02:46
-
-
Save cristianobecker/d3c9de836864fa26cce4 to your computer and use it in GitHub Desktop.
Git PS1 with current branch and color highligth
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
RED=$(tput setaf 1) | |
GREEN=$(tput setaf 2) | |
YELLOW=$(tput setaf 3) | |
WHITE=$(tput setaf 7) | |
NORMAL=$(tput sgr0) | |
_git-branch() { | |
local branch="$(git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///')" | |
test "x$branch" != x && echo " ($branch)" | |
} | |
_git-color() { | |
local stat="$(git status 2> /dev/null)" | |
if test "x$stat" != x; then | |
local color=$RED | |
test "x$(echo $stat | grep 'working directory clean')" != x && color=$GREEN | |
test "x$(echo $stat | grep 'working tree clean')" != x && color=$GREEN | |
test "x$(echo $stat | grep 'branch is ahead')" != x && color=$YELLOW | |
test "x$(echo $stat | grep 'untracked files present')" != x && color=$RED | |
test "x$(echo $stat | grep 'not staged for commit')" != x && color=$RED | |
test "x$(echo $stat | grep 'to be committed')" != x && color=$RED | |
echo $color | |
fi | |
} | |
export PS1="\[\$WHITE\]\W\[\$(_git-color)\]\$(_git-branch)\[\$NORMAL\] $ " | |
export CLICOLOR=1 | |
export LSCOLORS=gxfxcxdxbxegedabagaced |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment