function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
setopt PROMPT_SUBST
export PROMPT='%{%F{245}%}%n %{%F{normal}%}%2~ %{%F{green}%}$(parse_git_branch) %{%F{normal}%}$%{%f%} '
reference: link
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
setopt PROMPT_SUBST
export PROMPT='%{%F{245}%}%n %{%F{normal}%}%2~ %{%F{green}%}$(parse_git_branch) %{%F{normal}%}$%{%f%} '
reference: link
Thanks @neiloler - This fix was very helpful and the tips re color was a good add-on. It's easy to choose colors of choice for username, directory path, git branch etc in that order
'${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
Thanks for your feedback! @neiloler
I applied your feedback.
Thank you so much! @neiloler
Thank you!
Thank you for this!
Thank you so much!
Thank you!! @neiloler . I got inspired by your post and tweaked it a bit.
https://gist.github.com/jsohndata/7d5a252de861c2fe3c1eb4c4143be02d
Some how I missed all the notifications for the kind thanks here, thanks! 🙂
Also, for the sake of demonstrating the history:
You'll run into weird issues of lines wrapping and messing up unexpectedly.
This is a fix for that:
Note the use of
%{...%}
to make sure that formatting characters aren't being counted in the character count of the line. If someone comes across this and finds a better way to do it, please definitely improve this.I found this stackover flow helpful to start to see what was up: https://stackoverflow.com/questions/689765/how-can-i-change-the-color-of-my-prompt-in-zsh-different-from-normal-text