gitechozshterminal-color

Why the echo result of $vcs_info_msg_0_ contains strange characters in zsh?


This is my PROMPT configuration in zsh:

PROMPT=$'
%{$purple%}%n%{$reset_color%} at %{$orange%}%m%{$reset_color%} in %{$limegreen%}%~%{$reset_color%} $vcs_info_msg_0_
$ '

And this is how my zsh displays

shell screenshoot

At first I just want to get the master** string for other use, then I searched for how zsh got it, and found that the message was generated by zsh's vcs_info package, and was stored in $vcs_info_msg_0_, but as the screenshot shows, the echo result of that variable was very strange. Why did this happen, and how can I just get the git information (master** with color) of a repository folder?


Solution

  • That's because the variable is only to be used in prompts, nowhere else. The strange things you see are special control sequences that are interpreted by ZSH when rendering the prompt.