Last active
December 22, 2021 11:28
-
-
Save CDRussell/47030b4eb1a5b90ef8ef01685c852b25 to your computer and use it in GitHub Desktop.
This file contains 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
# Git branch in command prompts | |
autoload -Uz vcs_info | |
precmd() {vcs_info} | |
setopt PROMPT_SUBST | |
# the last part of this command dictates what is shown for git info, referenced later by the prompt command. | |
# here, showing branch name %b in color 38 (blue) and the repo name %r in color 226 (yellow) | |
zstyle ':vcs_info:git:*' formats '%F{38}%b%f %F{226}(%r)%f' | |
# can set both the left (PROMPT) and right (RPROMPT) prompts | |
# %1~ means show the current directory, and go back only 1 level. ie, show the current folder name only. ~ used to represent directories in the current user directory with a ~ shorthand instead of the full /Users/X/ style | |
# %F means to start formatting the text, with color 40 (green). Normally you'd have to close off this formatting with a corresponding %f, but we want the command we type in to have this color meaning we can't close it off yet. We lean on preexec () to reset the text color for us (see below) | |
PROMPT='%1~ %# %F{40}' | |
# optional, if in a git dir, show git info as defined above | |
RPROMPT=\$vcs_info_msg_0_ | |
# the next command is run before any other commands, so we can use this hook to reset the color back to the default | |
preexec () { echo -ne "\e[0m" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment