Skip to content

git diff

Zeioth edited this page Apr 3, 2024 · 9 revisions

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

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

You can see how this component look on the left of the next image: It displays the current changes of your git repository. screenshot_2024-02-23_18-01-20_442823667

If you click this area, it will display the git diff of every file. screenshot_2024-02-23_17-21-10_851445367

Available providers

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

added = { icon = { kind = "GitAdd", padding = { left = 1, right = 1 } } },       -- If set, displays icon+n of added lines.
changed = { icon = { kind = "GitChange", padding = { left = 1, right = 1 } }, }, -- If set, displays icon+n of changed lines.
removed = { icon = { kind = "GitDelete", padding = { left = 1, right = 1 } }, }, -- If set, displays icon+n of removed lines.
surround = {
  separator = "left",                                                        -- where to add the separator.
  color = "git_diff_bg",                                                     -- you can set a custom background color, for example "#444444".
  condition = require("heirline-components.all").condition.git_changed       -- a function that determines when to display the component.
},
hl = hl.get_attributes "git_diff",                                           -- 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 the provider git_add to disable its icon.

component.git_diff({ git_add = { icon = false } })

Or disable that provider entirely

component.git_diff({ git_add = false })

More info

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

Clone this wiki locally