Created
February 19, 2024 19:09
-
-
Save cgimenes/6ebf89e4d323f95ab485a14f9acef942 to your computer and use it in GitHub Desktop.
Harpoon files in tabline through Lualine with colored text and switch on click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local colors = require("kanagawa.colors").setup() | |
local theme_colors = colors.theme | |
vim.api.nvim_set_hl(0, 'HarpoonActive', { ctermbg = 0, fg = theme_colors.syn.identifier, bg = theme_colors.ui.bg }) | |
vim.api.nvim_set_hl(0, 'HarpoonNumberActive', { ctermbg = 0, fg = theme_colors.syn.number, bg = theme_colors.ui.bg }) | |
vim.api.nvim_set_hl(0, 'HarpoonInactive', { ctermbg = 0, fg = theme_colors.syn.fg, bg = theme_colors.ui.bg_p1 }) | |
vim.api.nvim_set_hl(0, 'HarpoonNumberInactive', { ctermbg = 0, fg = theme_colors.syn.number, bg = theme_colors.ui.bg_p1 }) | |
local function harpoon_files() | |
local harpoon = require("harpoon") | |
local marks_length = harpoon:list():length() | |
local contents = {} | |
local current_file_path = vim.fn.fnamemodify(vim.fn.expand("%:p"), ":.") | |
for index = 1, marks_length do | |
local harpoon_file_path = harpoon:list():get(index).value | |
local file_name = harpoon_file_path == "" and "(empty)" or vim.fn.fnamemodify(harpoon_file_path, ':t') | |
if current_file_path == harpoon_file_path then | |
contents[index] = string.format("%%#HarpoonNumberActive# %s. %%#HarpoonActive#%s ", index, file_name) | |
else | |
contents[index] = string.format("%%#HarpoonNumberInactive# %s. %%#HarpoonInactive#%s ", index, file_name) | |
end | |
contents[index] = string.format('%%%s@LualineSwitchHarpoon@%s%%X', index, contents[index]) | |
end | |
return table.concat(contents) | |
end | |
vim.cmd([[ | |
function! LualineSwitchHarpoon(index, mouseclicks, mousebutton, modifiers) | |
execute ":lua require(\"harpoon\"):list():select(" .. a:index .. ")" | |
endfunction | |
]]) | |
require('lualine').setup { | |
tabline = { | |
lualine_a = { | |
{ harpoon_files } | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment