Created
October 1, 2020 11:01
-
-
Save bennyrw/76de609d986b3ac6cf6cc204b7f01536 to your computer and use it in GitHub Desktop.
Include Git branch in zsh 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
| # | |
| # Prompt customisation for Git branch | |
| # | |
| # Use colors module for simpler usage of colours in prompt | |
| autoload -U colors && colors | |
| # Use vcs_info module for getting Git info (see https://arjanvandergaag.nl/blog/customize-zsh-prompt-with-vcs-info.html) | |
| autoload -Uz vcs_info | |
| # Tell vcs_info to output the current branch, if on a Git repo | |
| zstyle ':vcs_info:git*' formats "%{$fg_bold[cyan]%}(%b)%{$reset_color%}" | |
| # Tell zsh to run vcs_info before every command to update the prompt | |
| precmd() { | |
| vcs_info | |
| } | |
| # Tell zsh to substitute variables in prompt | |
| setopt prompt_subst | |
| # Finally, update the prompt! %{...%} escape non-printable chars, otherwise line wrapping can mess up | |
| # (See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion) | |
| PROMPT='%{$fg[magenta]%}%n@%m%{$reset_color%} %{$fg[white]%}%1~%{$reset_color%} ${vcs_info_msg_0_} %# ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment