20 lines
757 B
Bash
20 lines
757 B
Bash
#!/usr/bin/env bash
|
|
|
|
COLOR_GIT_CLEAN='\001\033[38;5;107m\002'
|
|
COLOR_GIT_MODIFIED='\001\033[38;5;180m\002'
|
|
COLOR_GIT_STAGED='\001\033[38;5;223m\002'
|
|
COLOR_RESET='\001\033[0m\002'
|
|
|
|
function git_prompt() {
|
|
if git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
local branch_name
|
|
branch_name=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
|
|
if git diff --quiet --ignore-submodules HEAD 2>/dev/null; then
|
|
echo -ne " ${COLOR_GIT_CLEAN}${branch_name}${COLOR_RESET}"
|
|
elif ! git diff --cached --quiet --ignore-submodules HEAD 2>/dev/null; then
|
|
echo -ne " ${COLOR_GIT_STAGED}${branch_name}${COLOR_RESET}"
|
|
else
|
|
echo -ne " ${COLOR_GIT_MODIFIED}${branch_name}*${COLOR_RESET}"
|
|
fi
|
|
fi
|
|
}
|