mirror of
https://github.com/ThePrimeagen/harpoon
synced 2024-09-16 13:34:03 +02:00
Merge pull request #287 from otavioschwanck/feat/add-tabline
Tabline with harpoon items
This commit is contained in:
commit
8cb54c4003
3 changed files with 120 additions and 0 deletions
28
README.md
28
README.md
|
@ -149,6 +149,11 @@ global_settings = {
|
|||
|
||||
-- set marks specific to each git branch inside git repository
|
||||
mark_branch = false,
|
||||
|
||||
-- enable tabline with harpoon marks
|
||||
tabline = false,
|
||||
tabline_prefix = " ",
|
||||
tabline_suffix = " ",
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -208,6 +213,29 @@ require("harpoon").setup({
|
|||
})
|
||||
```
|
||||
|
||||
|
||||
#### Tabline
|
||||
|
||||
By default, the tabline will use the default theme of your theme. You can customize by editing the following highlights:
|
||||
|
||||
* HarpoonInactive
|
||||
* HarpoonActive
|
||||
* HarpoonNumberActive
|
||||
* HarpoonNumberInactive
|
||||
|
||||
Example to make it cleaner:
|
||||
|
||||
```lua
|
||||
vim.cmd('highlight! HarpoonInactive guibg=NONE guifg=#63698c')
|
||||
vim.cmd('highlight! HarpoonActive guibg=NONE guifg=white')
|
||||
vim.cmd('highlight! HarpoonNumberActive guibg=NONE guifg=#7aa2f7')
|
||||
vim.cmd('highlight! HarpoonNumberInactive guibg=NONE guifg=#7aa2f7')
|
||||
vim.cmd('highlight! TabLineFill guibg=NONE guifg=white')
|
||||
```
|
||||
|
||||
Result:
|
||||
![tabline](https://i.imgur.com/8i8mKJD.png)
|
||||
|
||||
## ⇁ Social
|
||||
For questions about Harpoon, there's a #harpoon channel on [the Primagen's Discord](https://discord.gg/theprimeagen) server.
|
||||
* [Discord](https://discord.gg/theprimeagen)
|
||||
|
|
|
@ -210,6 +210,9 @@ function M.setup(config)
|
|||
["tmux_autoclose_windows"] = false,
|
||||
["excluded_filetypes"] = { "harpoon" },
|
||||
["mark_branch"] = false,
|
||||
["tabline"] = false,
|
||||
["tabline_suffix"] = " ",
|
||||
["tabline_prefix"] = " ",
|
||||
},
|
||||
}, expand_dir(c_config), expand_dir(u_config), expand_dir(config))
|
||||
|
||||
|
@ -217,7 +220,12 @@ function M.setup(config)
|
|||
-- an object for vim.loop.cwd()
|
||||
ensure_correct_config(complete_config)
|
||||
|
||||
if complete_config.tabline then
|
||||
require("harpoon.tabline").setup(complete_config)
|
||||
end
|
||||
|
||||
HarpoonConfig = complete_config
|
||||
|
||||
log.debug("setup(): Complete config", HarpoonConfig)
|
||||
log.trace("setup(): log_key", Dev.get_log_key())
|
||||
end
|
||||
|
|
84
lua/harpoon/tabline.lua
Normal file
84
lua/harpoon/tabline.lua
Normal file
|
@ -0,0 +1,84 @@
|
|||
local Dev = require("harpoon.dev")
|
||||
local log = Dev.log
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_color(group, attr)
|
||||
return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(group)), attr)
|
||||
end
|
||||
|
||||
|
||||
local function shorten_filenames(filenames)
|
||||
local shortened = {}
|
||||
|
||||
local counts = {}
|
||||
for _, file in ipairs(filenames) do
|
||||
local name = vim.fn.fnamemodify(file.filename, ":t")
|
||||
counts[name] = (counts[name] or 0) + 1
|
||||
end
|
||||
|
||||
for _, file in ipairs(filenames) do
|
||||
local name = vim.fn.fnamemodify(file.filename, ":t")
|
||||
|
||||
if counts[name] == 1 then
|
||||
table.insert(shortened, { filename = vim.fn.fnamemodify(name, ":t") })
|
||||
else
|
||||
table.insert(shortened, { filename = file.filename })
|
||||
end
|
||||
end
|
||||
|
||||
return shortened
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
function _G.tabline()
|
||||
local original_tabs = require('harpoon').get_mark_config().marks
|
||||
local tabs = shorten_filenames(original_tabs)
|
||||
local tabline = ''
|
||||
|
||||
for i, tab in ipairs(original_tabs) do
|
||||
local is_current = string.match(vim.fn.bufname(), tab.filename) or vim.fn.bufname() == tab.filename
|
||||
|
||||
local label = tabs[i].filename
|
||||
|
||||
|
||||
if is_current then
|
||||
tabline = tabline ..
|
||||
'%#HarpoonNumberActive#' .. (opts.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonActive#'
|
||||
else
|
||||
tabline = tabline ..
|
||||
'%#HarpoonNumberInactive#' .. (opts.tabline_prefix or ' ') .. i .. ' %*' .. '%#HarpoonInactive#'
|
||||
end
|
||||
|
||||
tabline = tabline .. label .. (opts.tabline_suffix or ' ') .. '%*'
|
||||
if i < #tabs then
|
||||
tabline = tabline .. '%T'
|
||||
end
|
||||
end
|
||||
|
||||
return tabline
|
||||
end
|
||||
|
||||
vim.opt.showtabline = 2
|
||||
|
||||
vim.o.tabline = '%!v:lua.tabline()'
|
||||
|
||||
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||
group = vim.api.nvim_create_augroup("harpoon", { clear = true }),
|
||||
pattern = { "*" },
|
||||
callback = function()
|
||||
local color = get_color('HarpoonActive', 'bg#')
|
||||
|
||||
if (color == "" or color == nil) then
|
||||
vim.api.nvim_set_hl(0, "HarpoonInactive", { link = "Tabline" })
|
||||
vim.api.nvim_set_hl(0, "HarpoonActive", { link = "TablineSel" })
|
||||
vim.api.nvim_set_hl(0, "HarpoonNumberActive", { link = "TablineSel" })
|
||||
vim.api.nvim_set_hl(0, "HarpoonNumberInactive", { link = "Tabline" })
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
log.debug("setup(): Tabline Setup", opts)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Reference in a new issue