Skip to content

Commit

Permalink
feat(nvim): For special filenames like mod.rs or lib.rs always show p…
Browse files Browse the repository at this point in the history
…arent directory in winbar
  • Loading branch information
mrjones2014 committed Mar 25, 2024
1 parent a12f5ed commit ec7e02f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nvim/lua/my/configure/heirline/winbar.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local conditions = require('heirline.conditions')
local sep = require('my.configure.heirline.separators')

local special_filenames = { 'mod.rs', 'lib.rs' }

local function get_current_filenames()
local listed_buffers = vim
.iter(vim.api.nvim_list_bufs())
Expand Down Expand Up @@ -56,7 +58,20 @@ local function get_unique_filename(filename)
index = index + 1
end

return string.reverse(string.sub(filename, 1, index))
local result = string.reverse(string.sub(filename, 1, index))
-- for special filenames like `lib.rs`, `mod.rs`, `index.ts` etc.
-- always show at least one parent
if vim.iter(ipairs(special_filenames)):any(function(_, special)
return special == result
end) then
local parts = vim.split(string.reverse(filename), '/')
-- if parent is just `src` then show another parent
if parts[#parts - 1] == 'src' then
return table.concat({ parts[#parts - 2], parts[#parts - 1], parts[#parts] }, '/')
end
return table.concat({ parts[#parts - 1], parts[#parts] }, '/')
end
return result
end

local M = {}
Expand Down

0 comments on commit ec7e02f

Please sign in to comment.