Created
November 13, 2023 15:26
-
-
Save pesterhazy/9de3a019610e4cc4f151df263d35f5ef to your computer and use it in GitHub Desktop.
ZSH: show current git branch on enter
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
# 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