Created
April 17, 2025 16:36
-
-
Save milnak/fcd06e14adda3da030eea3e243c53a1a to your computer and use it in GitHub Desktop.
Bash Git Prompt
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
#!/bin/bash | |
PROMPT_DIRTRIM=2 | |
# RED="\[\033[0;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[0;32m\]" | |
# BLUE="\[\033[0;34m\]" | |
# LIGHT_BLUE="\[\033[1;34m\]" | |
LIGHT_RED="\[\033[1;31m\]" | |
LIGHT_GREEN="\[\033[1;32m\]" | |
WHITE="\[\033[1;37m\]" | |
# DARK_GRAY="\[\033[1;30m\]" | |
# LIGHT_GRAY="\[\033[0;37m\]" | |
# LIGHT_CYAN="\[\033[1;36m\]" | |
# CYAN="\[\033[0;36m\]" | |
# PURPLE="\[\033[0;35m\]" | |
# BROWN="\[\033[0;33m\]" | |
#LIGHT_PURPLE="\[\033[1;35m\]" | |
# BLACK="\[\033[0;30m\]" | |
COLOR_NONE="\[\033[0m\]" | |
function set_git_branch() { | |
this_branch="$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')" | |
if test -z "$this_branch"; then | |
PROMPT_BRANCH="" | |
else | |
PROMPT_BRANCH="${YELLOW}${this_branch}${COLOR_NONE} " | |
fi | |
} | |
function set_prompt_symbol() { | |
if test "$1" -eq 0; then | |
PROMPT_SYMBOL="${LIGHT_GREEN}\$${COLOR_NONE} " | |
else | |
PROMPT_SYMBOL="${LIGHT_RED}\$${COLOR_NONE} " | |
fi | |
} | |
function set_user_line() { | |
PROMPT_USER_LINE="$(date '+%T') ${GREEN}\u${COLOR_NONE} " | |
} | |
function set_bash_prompt() { | |
set_prompt_symbol $? | |
set_user_line | |
set_git_branch | |
PS1="${PROMPT_USER_LINE}${WHITE}\w${COLOR_NONE} ${PROMPT_BRANCH}${PROMPT_SYMBOL}" | |
} | |
PROMPT_COMMAND=set_bash_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment