Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created November 13, 2023 15:26
Show Gist options
  • Save pesterhazy/9de3a019610e4cc4f151df263d35f5ef to your computer and use it in GitHub Desktop.
Save pesterhazy/9de3a019610e4cc4f151df263d35f5ef to your computer and use it in GitHub Desktop.
ZSH: show current git branch on enter
# This prints the current git branch when you submit an empty
# line (i.e. press enter) in zsh
#
# Less distracting than adding it to your prompt, but still
# very easy to run.
git-status-on-enter () {
if [ ${#${(z)BUFFER}} -eq 0 ]; then
if git rev-parse --git-dir > /dev/null 2>&1 ; then
echo
printf "%s" "$(git -c color.status=always status -sb)"
fi
fi
zle accept-line
}
zle -N git-status-on-enter
bindkey '^M' git-status-on-enter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment