Skip to content

Commit 8cf5b3e

Browse files
committed
update PS1
1 parent f26c87e commit 8cf5b3e

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

roles/env/files/git_bash_ps1.sh

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,54 @@ PathFull="\w"
9292
NewLine="\n"
9393
Jobs="\j"
9494

95+
# Function to get the current git branch
96+
get_git_branch() {
97+
# Check if we're inside a git repository
98+
if git rev-parse --is-inside-work-tree &>/dev/null; then
99+
# If yes, return the branch name
100+
echo "($(git rev-parse --abbrev-ref HEAD))"
101+
fi
102+
}
103+
104+
# Color options (can be customized)
105+
COLOR_USER="\[\033[1;36m\]" # Cyan for username
106+
COLOR_AT="\[\033[1;33m\]" # Yellow for @ symbol
107+
COLOR_HOST="\[\033[1;35m\]" # Magenta for hostname
108+
COLOR_GIT_BRANCH="\[\033[0;31m\]" # White (or grey) for git branch
109+
COLOR_DIR="\[\033[1;32m\]" # Green for the current directory
110+
COLOR_RESET="\[\033[0m\]" # Reset color
111+
112+
Yellow226="\[\033[01;38;5;226m\]"
113+
LightPink207="\[\033[01;38;5;207m\]"
114+
Blue027="\[\033[01;38;5;027m\]"
115+
116+
# Custom PS1 prompt with color
117+
PS1="${COLOR_USER}${USER}${COLOR_AT}@${COLOR_HOST}${HOSTNAME}\$ ${Yellow226}\$(get_git_branch)${COLOR_RESET} : ${COLOR_DIR}\w${COLOR_RESET} $ "
118+
95119
# This PS1 snippet was adopted from code for MAC/BSD I saw from: http://allancraig.net/index.php?option=com_content&view=article&id=108:ps1-export-command-for-git&catid=45:general&Itemid=96
96120
# I tweaked it to work on UBUNTU 11.04 & 11.10 plus made it mo' better
97121

98-
MyPS1=$Blue027$Username$IPurple@$IGreen$ShortHost$Color_Off'$(git branch &>/dev/null;\
99-
if [ $? -eq 0 ]; then \
100-
echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \
101-
HEADREV=$(git log --pretty=%h -n 1 2>/dev/null || echo "no-commits")
102-
103-
echo "'$BWhite'|$HEADREV" | tr -d "\n"; \
104-
if [ "$?" -eq "0" ]; then \
105-
# @4 - Clean repository - nothing to commit
106-
echo "|'$BGreen'"$(__git_ps1 "(%s)"); \
107-
else \
108-
# @5 - Changes to working tree
109-
echo "|'$BIRed'"$(__git_ps1 "{%s}"); \
110-
fi)'$BWhite'|'$IYellow$PathFull$Color_Off'"; \
111-
else \
112-
# @2 - Prompt when not in GIT repo
113-
echo "|'$Yellow226$PathFull$Color_Off'"; \
114-
fi)'
115-
116-
export PS1="$IPurple[$Color_Off $MyPS1 \$ $IPurple]$Color_Off "
122+
# MyPS1="$Blue027$Username$IPurple@$IGreen$ShortHost$Color_Off$(
123+
# git branch &>/dev/null
124+
# if [ $? -eq 0 ]; then
125+
# HEADREV=$(git log --pretty=%h -n 1 2>/dev/null || echo "no-commits")
126+
# if git status | grep -q "nothing to commit"; then
127+
# # @4 - Clean repository - nothing to commit
128+
# echo "'$BWhite'|$HEADREV|$BGreen$(__git_ps1 "(%s)")$Color_Off"
129+
# else
130+
# # @5 - Changes to working tree
131+
# echo "'$BWhite'|$HEADREV|$BIRed$(__git_ps1 "{%s}")$Color_Off"
132+
# fi
133+
# else
134+
# # @2 - Prompt when not in GIT repo
135+
# echo "'$Yellow226$PathFull$Color_Off'"
136+
# fi
137+
# )"
138+
139+
# export PS1="${IPurple}[${Color_Off} ${MyPS1} \$ ${IPurple}]${Color_Off} "
140+
# # without bracket
141+
# export PS1="${MyPS1} \$ "
142+
143+
# export PS1="$IPurple[$Color_Off $MyPS1 \$ $IPurple]$Color_Off "
117144
# without bracket
118-
export PS1="$MyPS1 \$ "
145+
# export PS1="$MyPS1 \$ "

0 commit comments

Comments
 (0)