Skip to main content

Add it to your prompt

Your prompt runs a little program every time you press Enter. If that program asks git for the branch, every prompt in every terminal pays for it. With comb, you ask comb instead: it works the answer out once and hands it to everyone.

Pick your setup and paste the snippet in. Each one shows the git branch, with a * when there are uncommitted changes, and shows nothing outside a repository.

~/.zshrc
precmd() {
local git=$(comb g git -f '{{ branch }}{{ "*" if dirty }}')
PS1="%F{blue}${git:+$git }%f%~ %# "
}

Open a new terminal in a git repository, and the branch is there.

comb g is short for comb get. git is a group of values comb knows about a repository; the -f part is a small template that picks out branch and dirty and arranges them. You'll learn to write these in How comb works.

More tools, and fuller setups for each of these, are in Integrations: neovim, oh-my-zsh, powerlevel10k, oh-my-posh, waybar, polybar and sketchybar.

Next: See it working