utilyre / barbecue.nvim

Visual Studio Code inspired breadcrumbs plugin for the Neovim editor
MIT License
776 stars 31 forks source link

[FEAT]: Allow customizable override for detecting `modified` #68

Closed dhruvasagar closed 1 year ago

dhruvasagar commented 1 year ago

Requirements

Problem

While highlighting modified based on whether the buffer has been modified is useful, I find it more useful to know if the buffer has been modified in source control (git). There are likely other ways like git-gutter that people find useful, but I don't really like that and find them noisy, I just want to see in a glance if the file has been modified and I can review the changes separately.

I am aware of the custom_section property and had been using it but I like this instead since it's more noticeable

Solution Suggestion

The following works for me, I can create a PR if you think it's useful :

diff --git a/lua/barbecue/config/template.lua b/lua/barbecue/config/template.lua
index 76d23c5..b04d2d8 100644
--- a/lua/barbecue/config/template.lua
+++ b/lua/barbecue/config/template.lua
@@ -38,6 +38,8 @@ local M = {
   ---@type boolean
   show_modified = false,

+  modified = function(bufnr) return vim.bo[bufnr].modified end,
+
   ---whether to show/use navic in the winbar
   ---@type boolean
   show_navic = true,
diff --git a/lua/barbecue/ui/components.lua b/lua/barbecue/ui/components.lua
index 70b9364..601fad7 100644
--- a/lua/barbecue/ui/components.lua
+++ b/lua/barbecue/ui/components.lua
@@ -72,7 +72,7 @@ function M.basename(winnr, bufnr)
     vim.fn.fnamemodify(filename, config.user.modifiers.basename .. ":t")

   local icon
-  if vim.bo[bufnr].modified and config.user.show_modified then
+  if config.user.modified(bufnr) and config.user.show_modified then
     icon = {
       config.user.symbols.modified,
       highlight = theme.highlights.modified,

This allows me to override this with something like this in my configs :

require('barbecue').setup({
  modified = function()
    return vim.fn["StatusLineGitFlag"]() ~= ""
  end
})

Workaround

No response

utilyre commented 1 year ago

Seems great! I have some suggestions I'll tell you once you opened the PR.