Created
January 17, 2018 16:20
-
-
Save Semmu/42e9f34ce29cdddbc853727ebe07ee49 to your computer and use it in GitHub Desktop.
Descriptive git bash 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
RESET='\[\033[0m\]' | |
RED='\[\033[00;31m\]' | |
GREEN='\[\033[00;32m\]' | |
YELLOW='\[\033[00;33m\]' | |
BLUE='\[\033[00;34m\]' | |
PURPLE='\[\033[00;35m\]' | |
CYAN='\[\033[00;36m\]' | |
LIGHTGRAY='\[\033[00;37m\]' | |
LRED='\[\033[01;31m\]' | |
LGREEN='\[\033[01;32m\]' | |
LYELLOW='\[\033[01;33m\]' | |
LBLUE='\[\033[01;34m\]' | |
LPURPLE='\[\033[01;35m\]' | |
LCYAN='\[\033[01;36m\]' | |
WHITE='\[\033[01;37m\]' | |
function is_in_git_repo { | |
git rev-parse --is-inside-work-tree 2>/dev/null 1>&2 && return 0 || return 1 | |
} | |
function print_git_branch { | |
git symbolic-ref --short -q HEAD | |
} | |
function print_git_describe { | |
git describe 2>/dev/null || echo "${RED}no tags${PURPLE}" | |
} | |
function print_git_status_symbols { | |
GIT_STATUS_PROCELAIN="$(git status --porcelain)" | |
GIT_UNTRACKED_LINECOUNT=$( echo "$GIT_STATUS_PROCELAIN" | grep "^??" | wc -l ) | |
GIT_MODIFIED_LINECOUNT=$( echo "$GIT_STATUS_PROCELAIN" | grep "^.M" | wc -l ) | |
GIT_STAGED_LINECOUNT=$( echo "$GIT_STATUS_PROCELAIN" | grep -E "^(A|M)" | wc -l ) | |
if [ $GIT_UNTRACKED_LINECOUNT -gt 0 ]; then | |
echo -n "${RED}U" | |
fi | |
if [ $GIT_MODIFIED_LINECOUNT -gt 0 ]; then | |
echo -n "${YELLOW}M" | |
fi | |
if [ $GIT_STAGED_LINECOUNT -gt 0 ]; then | |
echo -n "${GREEN}S" | |
fi | |
} | |
function print_git_details { | |
if is_in_git_repo; then | |
echo "$RESET$PURPLE$(print_git_branch) ($(print_git_describe)) [$RESET$(print_git_status_symbols)$RESET$PURPLE]" | |
fi | |
} | |
function custom_bash_prompt { | |
PS1="$RESET$RED\t ${BLUE}\h $YELLOW\u $GREEN\w $(print_git_details)\n$GREEN\$$RESET " | |
} | |
PROMPT_COMMAND=custom_bash_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment