Skip to content

git branch

Zeioth edited this page Apr 3, 2024 · 14 revisions

You can add this component to the statusline section of heirline opts.

require("heirline-components.all").component.git_branch()

You can see how this component look on the left of the next image: It displays the current branch of your git repository. screenshot_2024-02-21_22-19-52_734842388 If you click this area, it will display the git log of every branch. screenshot_2024-02-23_15-03-33_861494417

Available providers

These are the available providers for this component and its options.

git_branch = { icon = { kind = "GitBranch", padding = { right = 1 } } }      -- if set, it displays a icon in front of the branch. 
surround = {
  separator = "left",                                                        -- where to add the separator.
  color = "git_branch_bg",                                                   -- you can set a custom background color, for example "#444444".
  condition = require("heirline-components.all").condition.is_git_repo       -- a function that determines when to display the component.
},
hl = hl.get_attributes "git_branch",                                         -- you can specify your own highlight group here.
on_click = { name = "<your_event_name", callback = function() end }          -- what happens when you click the component.
update = { "User", pattern = "GitSignsUpdate" },                             -- events that make the component refresh.
init = require("heirline-components.all").init.update_events({ "BufEnter" }), -- what happens when the component starts.

For example you could explicitly pass a provider to the component to customize its icon.

component.git_branch({ git_branch = { icon = { kind = "SomeOtherIcon" } } })

More info

This component won't display if you don't have the plugin gitsigns.

Clone this wiki locally