Created
April 30, 2021 01:46
-
-
Save jeffreyjs/5373fc44e6f83dc46ca383530c2adc48 to your computer and use it in GitHub Desktop.
Display git branch in zsh on MacOS
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
# set rc file | |
SHELL=$(echo ${SHELL}) | |
if [ ${SHELL} == "/bin/bash" ]; then | |
RC="/Users/${USER}/.bashrc" | |
elif [ ${SHELL} == "/bin/zsh" ]; then | |
RC="/Users/${USER}/.zshrc" | |
else | |
echo "${SHELL} not supported" | |
fi | |
read -r -d '' SHOW_GIT_BRANCH <<'EOF' | |
# Load version control information | |
autoload -Uz vcs_info | |
precmd() { vcs_info } | |
# Format the vcs_info_msg_0_ variable | |
zstyle ':vcs_info:git:*' formats 'on branch %b' | |
# Set up the prompt (with git branch name) | |
setopt PROMPT_SUBST | |
PROMPT='%n in ${PWD/#$HOME/~} ${vcs_info_msg_0_} > ' | |
EOF | |
GIT_BRANCH_SET=$(cat ${RC} | grep -q PROMPT=) | |
if [ ${?} == 1 ] && [ ${SHELL} == "/bin/zsh" ]; then | |
echo ${SHOW_GIT_BRANCH} >> ${RC} | |
else | |
echo "git shell settings already exist" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment