Skip to content

Instantly share code, notes, and snippets.

@getsetbro
Forked from njgibbon/minimal_zshrc_0.sh
Last active December 13, 2020 03:36
Show Gist options
  • Save getsetbro/9fc105941061fd19756e7d0363f32544 to your computer and use it in GitHub Desktop.
Save getsetbro/9fc105941061fd19756e7d0363f32544 to your computer and use it in GitHub Desktop.
Minimal .zshrc to output git branch name in prompt.
# ~/.zshrc
# 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.
prompt='%2/$(git_branch_name)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment