Last active
March 25, 2021 22:01
-
-
Save MiguelERuiz/6d92eb86fce6b6bbeba0082bc28768c5 to your computer and use it in GitHub Desktop.
git branch into the `prompt` variable in ZSH (Mac Terminal)
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
# inspired by: | |
# https://medium.com/pareture/simplest-zsh-prompt-configs-for-git-branch-name-3d01602a6f33 | |
# https://medium.com/dev-genius/customize-the-macos-terminal-zsh-4cb387e4f447 | |
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion | |
# Find and set branch name var if in git repository. | |
function git_branch_name() | |
{ | |
branch=$(git symbolic-ref HEAD 2> /dev/null | awk 'BEGIN{FS="/"} {print $NF}') | |
if [[ $branch == "" ]]; | |
then | |
: | |
else | |
echo ' - ('$branch')' | |
fi | |
} | |
# Enable substitution in the prompt. | |
setopt prompt_subst | |
# Config for prompt. PS1 synonym. | |
# miguel@~/repo - (master) > | |
prompt='%F{red}%n%f@%F{green}%~%f%F{magenta}$(git_branch_name)%f > ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment