diff --git a/README.md b/README.md index 37e6af4..6f564db 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,10 @@ sections = { color_modified = nil, -- changes diff's modified foreground color color_removed = nil, -- changes diff's removed foreground color symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols + source = nil, -- A function that works as a data source for diff. + -- it must return a table like + {added = add_count, modified = modified_count, removed = removed_count } + -- Or nil on failure. Count <= 0 won't be displayed. } } } diff --git a/doc/lualine.txt b/doc/lualine.txt index 0a51159..63e7933 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -276,6 +276,10 @@ Component specific local options~ color_modified = nil, -- changes diff's modified foreground color color_removed = nil, -- changes diff's removed foreground color symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols + source = nil, -- A function that works as a data source for diff. + -- it must return a table like + {added = add_count, modified = modified_count, removed = removed_count } + -- Or nil on failure. Count <= 0 won't be displayed. } } } diff --git a/lua/lualine/components/diff.lua b/lua/lualine/components/diff.lua index 9be96c2..91bb6b6 100644 --- a/lua/lualine/components/diff.lua +++ b/lua/lualine/components/diff.lua @@ -62,16 +62,23 @@ Diff.new = function(self, options, child) } end - vim.api.nvim_exec([[ - autocmd lualine BufEnter * lua require'lualine.components.diff'.update_git_diff_getter() - autocmd lualine BufWritePost * lua require'lualine.components.diff'.update_git_diff() - ]], false) + if type(new_instance.options.source) ~= 'function' then + -- setup internal source + vim.cmd [[ + autocmd lualine BufEnter * lua require'lualine.components.diff'.update_git_diff_getter() + autocmd lualine BufWritePost * lua require'lualine.components.diff'.update_git_diff() + ]] + end return new_instance end -- Function that runs everytime statusline is updated Diff.update_status = function(self) + if self.options.source then + Diff.git_diff = self.options.source() + end + if Diff.git_diff == nil then return '' end local colors = {}