Last active
July 27, 2021 03:24
-
-
Save yuyosy/4527f4e1f7ceb53d579c1d517b405224 to your computer and use it in GitHub Desktop.
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
RED="\[\033[0;31m\]" | |
GREEN="\[\033[0;32m\]" | |
YELLOW="\[\033[0;33m\]" | |
BLUE="\[\033[0;34m\]" | |
PURPLE="\[\033[0;35m\]" | |
CYAN="\[\033[0;36m\]" | |
LIGHT_GRAY="\[\033[1;30m\]" | |
LIGHT_RED="\[\033[1;31m\]" | |
LIGHT_GREEN="\[\033[1;32m\]" | |
LIGHT_YELLOW="\[\033[1;33m\]" | |
LIGHT_BLUE="\[\033[1;34m\]" | |
LIGHT_PURPLE="\[\033[1;35m\]" | |
LIGHT_CYAN="\[\033[1;36m\]" | |
WHITE="\[\033[1;37m\]" | |
COLOR_NONE="\[\e[0m\]" | |
function git_directory() { | |
git_dir="$(git rev-parse --git-dir 2>/dev/null)" | |
} | |
function is_git_repository() { | |
git branch > /dev/null 2>&1 | |
} | |
function git_state_color() { | |
git_status="$(git status 2>/dev/null)" | |
if [[ ${git_status} =~ "nothing to commit, working tree clean" ]]; then | |
state_color="${COLOR_NONE}" | |
elif [[ ${git_status} =~ "Untracked files:" ]]; then | |
state_color="${LIGHT_RED}" | |
elif [[ ${git_status} =~ "Changes to be committed:" ]]; then | |
state_color="${GREEN}" | |
elif [[ ${git_status} =~ "Changes not staged for commit:" ]]; then | |
state_color="${YELLOW}" | |
else | |
state_color="${LIGHT_PURPLE}" | |
fi | |
} | |
function git_branch() { | |
branch="$(git branch --show-current 2>/dev/null)" | |
if [ "$branch" = "" ]; then | |
sha1="$(git rev-parse HEAD 2>/dev/null)" | |
id="$(git name-rev ${sha1} 2>/dev/null)" | |
git_branch_name="HEAD detached at ${id:0:7}" | |
else | |
git_branch_name=${branch} | |
fi | |
} | |
function bash_prompt() { | |
PS1='\[\033]0;$PWD\007\]' # set window title | |
PS1="${LIGHT_CYAN}$PS1"'\w' | |
if is_git_repository; then | |
if test -z "$WINELOADERNOEXEC"; then | |
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)" | |
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}" | |
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}" | |
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion" | |
if test -f "$COMPLETION_PATH/git-prompt.sh"; then | |
. "$COMPLETION_PATH/git-completion.bash" | |
# . "$COMPLETION_PATH/git-prompt.sh" | |
git_state_color | |
git_branch | |
PS1="$PS1"${state_color}' ('${git_branch_name}')' | |
fi | |
fi | |
fi | |
PS1="$PS1"${COLOR_NONE}'\n$' | |
} | |
PROMPT_COMMAND=bash_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment