Created
May 7, 2017 22:44
-
-
Save pringlized/767a031cadb3bb8b1da7cdaf9b1f0baa to your computer and use it in GitHub Desktop.
Displaying git info in base command prompt
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
function git_branch() { | |
git_branch=$(git branch --no-color 2>/dev/null | grep \* | sed 's/* //') | |
if [ $git_branch ] | |
then | |
white="\001\033[0;37m\002" | |
yellow="\001\033[0;33m\002" | |
blue="\001\033[0;34m\002" | |
red="\001\033[0;31m\002" | |
green="\001\033[0;32m\002" | |
check="\u2713" | |
x="\u2a2f" | |
git_status=$(git status --porcelain 2>/dev/null) | |
git_count_t=$(for i in "$git_status"; do echo "$i"; done | grep -v '^?? ' | sed '/^$/d' | wc -l | sed | |
"s/ //g") | |
git_count_ut=$(for i in "$git_status"; do echo "$i"; done | grep '^?? ' | sed '/^$/d' | wc -l | sed " | |
s/ //g") | |
if [[ "$git_count_t" == 0 ]]; then | |
tracked="$green$check$white" | |
else | |
tracked="$red$check$white" | |
fi | |
if [[ "$git_count_ut" == 0 ]]; then | |
untracked="$green$x$white" | |
else | |
untracked="$red$x$white" | |
fi | |
echo -e "$yellow${git_branch}$white ${tracked} ${untracked}" | |
fi | |
} | |
set_bash_prompt() { | |
white="\001\033[0;37m\002" | |
yellow="\001\033[0;33m\002" | |
blue="\001\033[0;34m\002" | |
red="\001\033[0;31m\002" | |
green="\001\033[0;32m\002" | |
if [ "${UID}" -eq 0 ]; then | |
#root | |
export PS1="╭─$red\u@\h $blue\w$white \$(git_branch) | |
╰─$blueλ$white " | |
else | |
#non-root | |
export PS1="╭─$green\u@\h $blue\w$white \$(git_branch) | |
╰─$blueλ$white " | |
fi | |
} | |
set_bash_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment