fix: harpoon now works in oil buffers
This commit is contained in:
parent
944ae1aef2
commit
cdf35d8502
2 changed files with 28 additions and 27 deletions
|
|
@ -73,10 +73,38 @@ return {
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>a', function()
|
vim.keymap.set('n', '<leader>a', function()
|
||||||
|
local harpoon = require('harpoon')
|
||||||
|
|
||||||
|
-- Check if we're in an oil buffer
|
||||||
if vim.fn.expand('%:p'):sub(1, 6) == 'oil://' then
|
if vim.fn.expand('%:p'):sub(1, 6) == 'oil://' then
|
||||||
|
local ok_oil, oil = pcall(require, 'oil')
|
||||||
|
if not ok_oil then
|
||||||
|
vim.notify('Oil not found', vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local entry = oil.get_cursor_entry()
|
||||||
|
if not entry or not entry.name then
|
||||||
|
vim.notify('No valid entry selected in Oil', vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local full_path = oil.get_current_dir() .. entry.name
|
||||||
|
local stat = vim.loop.fs_stat(full_path)
|
||||||
|
if not stat or stat.type ~= 'file' then
|
||||||
|
vim.notify('Selected entry is not a file: ' .. full_path, vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
harpoon:list():add({
|
||||||
|
value = entry.name,
|
||||||
|
context = { filename = entry.name, cwd = oil.get_current_dir() or 'global' },
|
||||||
|
})
|
||||||
|
vim.notify('Added ' .. entry.name .. ' to harpoon', vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Regular file buffer
|
||||||
harpoon:list():add()
|
harpoon:list():add()
|
||||||
end, { desc = 'Harpoon: Add file to list (if not already present)' })
|
end, { desc = 'Harpoon: Add file to list (if not already present)' })
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,32 +62,5 @@ return {
|
||||||
pattern = 'background',
|
pattern = 'background',
|
||||||
callback = set_oil_highlights,
|
callback = set_oil_highlights,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Add selected file in oil.nvim to Harpoon (only when in oil buffer)
|
|
||||||
vim.keymap.set('n', '<leader>a', function()
|
|
||||||
local ok_harpoon, harpoon = pcall(require, 'harpoon')
|
|
||||||
if not ok_harpoon then
|
|
||||||
vim.notify('Harpoon not found', vim.log.levels.WARN)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local entry = oil.get_cursor_entry()
|
|
||||||
if not entry or not entry.name then
|
|
||||||
vim.notify('No valid entry selected in Oil', vim.log.levels.INFO)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local full_path = oil.get_current_dir() .. entry.name
|
|
||||||
local stat = vim.loop.fs_stat(full_path)
|
|
||||||
if not stat or stat.type ~= 'file' then
|
|
||||||
vim.notify('Selected entry is not a file: ' .. full_path, vim.log.levels.INFO)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
harpoon:list():add({
|
|
||||||
value = entry.name,
|
|
||||||
context = { filename = entry.name, cwd = oil.get_current_dir() or 'global' },
|
|
||||||
})
|
|
||||||
end, { desc = 'Add selected file in oil.nvim to Harpoon' })
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue