I was looking for a script that would do the same on MacOS but didn't find a good answer so I just built it looking up zsh a little bit.
The other answers are right that you the answer is that you're using bash symbols instead of zsh symbols however below is a solution I made.
Add the following to your ~/.zshrc or ~/zprofile
###
# ADD GIT INFO TO PROMPT
###
parse_git_branch() {
local branch=""
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
local git_status=$(git status --porcelain 2>/dev/null)
local color=green
if echo "$git_status" | grep -q "^ M"; then
color=yellow
branch="${branch}*"
fi
if echo "$git_status" | grep -qE "^ A|^\?\?"; then
color=yellow
branch="${branch}+"
fi
if echo "$git_status" | grep -q "^ D"; then
color=yellow
branch="${branch}-"
fi
if [[ -n "$branch" ]]; then
branch=[%F{${color}}${branch}%F{reset}]
fi
echo "$branch"
}
update_prompt() {
PS1="%n %1~$(parse_git_branch) %#"
}
precmd_functions+=(update_prompt)
update_prompt
This will label your branch and give a little mark if there's changes.
If you don't need the mark, only keep the first line in parse_git_branch
If you need the computer name change %n
to %n@%m
.
Remember to re-open the terminal or run source ~/.zshrc
after you make your changes.
\u
has no special meaning in a PS1 for zsh. Therefore it is printed literally. The same applies for your other elements in the prompt string. – Eadwine