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.
- zsh
- bash
- fish
- starship
- tmux
precmd() {
local git=$(comb g git -f '{{ branch }}{{ "*" if dirty }}')
PS1="%F{blue}${git:+$git }%f%~ %# "
}
__comb_ps1() {
local git=$(comb g git -f '{{ branch }}{{ "*" if dirty }}')
PS1="${git:+$git }\w \$ "
}
PROMPT_COMMAND=__comb_ps1
function fish_prompt
set -l git (comb g git -f '{{ branch }}{{ "*" if dirty }}')
test -n "$git"; and echo -n "$git "
echo -n (prompt_pwd) '> '
end
[git_branch]
disabled = true
[git_status]
disabled = true
[custom.git]
command = '''comb g git -f '{{ branch }}{{ "*" if dirty }}' '''
when = '[ -n "$(comb g git.branch)" ]'
format = "[$output]($style) "
style = "bold blue"
set -g status-interval 5
set -g status-right '#(comb g git.branch "#{pane_current_path}") #(comb g battery.percent)%% '
tmux runs these for each pane's directory every five seconds, which is cheap because comb answers from memory.
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