oil and domain config

This commit is contained in:
Harivansh Rathi 2026-03-30 23:51:45 -04:00
parent 30ac6bc674
commit 15d0faef95
4 changed files with 152 additions and 147 deletions

View file

@ -1,92 +1,84 @@
vim.pack.add({
"https://github.com/barrettruth/canola.nvim",
"https://github.com/barrettruth/canola-collection",
}, { load = function() end })
return {
{
"barrettruth/canola.nvim",
cmd = "Canola",
before = function()
vim.g.canola = {
columns = { "icon" },
delete = { wipe = false, recursive = true },
hidden = { enabled = false },
keymaps = {
["g?"] = { callback = "actions.show_help", mode = "n" },
["<CR>"] = "actions.select",
["<C-v>"] = { callback = "actions.select", opts = { vertical = true } },
["<C-x>"] = { callback = "actions.select", opts = { horizontal = true } },
["<C-p>"] = "actions.preview",
["<C-c>"] = { callback = "actions.close", mode = "n" },
["-"] = { callback = "actions.parent", mode = "n" },
["g."] = { callback = "actions.toggle_hidden", mode = "n" },
["<C-t>"] = false,
},
}
end,
after = function()
vim.cmd.packadd "canola-collection"
local ns = vim.api.nvim_create_namespace "canola_git_trailing"
local symbols = {
M = { "M", "DiagnosticWarn" },
A = { "A", "DiagnosticOk" },
D = { "D", "DiagnosticError" },
R = { "R", "DiagnosticWarn" },
["?"] = { "?", "DiagnosticInfo" },
["!"] = { "!", "Comment" },
}
local function apply_git_status(buf)
if not vim.api.nvim_buf_is_valid(buf) then return end
vim.api.nvim_buf_clear_namespace(buf, ns, 0, -1)
local ok, canola = pcall(require, "canola")
if not ok then return end
local dir = canola.get_current_dir(buf)
if not dir then return end
local git_ok, git = pcall(require, "canola-git")
if not git_ok then return end
local dir_cache = git._cache[dir]
if not dir_cache or not dir_cache.status then return end
local lines = vim.api.nvim_buf_line_count(buf)
for lnum = 0, lines - 1 do
local entry = canola.get_entry_on_line(buf, lnum + 1)
if entry then
local status = dir_cache.status[entry.name]
if status then
local ch = status:sub(1, 1)
if ch == " " then ch = status:sub(2, 2) end
local sym = symbols[ch]
if sym then
vim.api.nvim_buf_set_extmark(buf, ns, lnum, 0, {
virt_text = { { " " .. sym[1], sym[2] } },
virt_text_pos = "eol",
invalidate = true,
})
end
end
end
end
end
vim.api.nvim_create_autocmd("User", {
pattern = "CanolaReadPost",
callback = function(args)
local buf = args.buf
apply_git_status(buf)
vim.defer_fn(function() apply_git_status(buf) end, 500)
end,
})
end,
keys = {
{ "-", "<cmd>Canola<cr>" },
{ "<leader>e", "<cmd>Canola<cr>" },
},
vim.g.canola = {
columns = { "icon" },
delete = { wipe = false, recursive = true },
hidden = { enabled = false },
keymaps = {
["g?"] = { callback = "actions.show_help", mode = "n" },
["<CR>"] = "actions.select",
["<C-v>"] = { callback = "actions.select", opts = { vertical = true } },
["<C-x>"] = { callback = "actions.select", opts = { horizontal = true } },
["<C-p>"] = "actions.preview",
["<C-c>"] = { callback = "actions.close", mode = "n" },
["-"] = { callback = "actions.parent", mode = "n" },
["g."] = { callback = "actions.toggle_hidden", mode = "n" },
["<C-t>"] = false,
},
}
vim.pack.add {
"https://github.com/barrettruth/canola.nvim",
"https://github.com/barrettruth/canola-collection",
}
vim.cmd.packadd "canola-collection"
map("n", "-", "<cmd>Canola<cr>")
map("n", "<leader>e", "<cmd>Canola<cr>")
local ns = vim.api.nvim_create_namespace "canola_git_trailing"
local symbols = {
M = { "M", "DiagnosticWarn" },
A = { "A", "DiagnosticOk" },
D = { "D", "DiagnosticError" },
R = { "R", "DiagnosticWarn" },
["?"] = { "?", "DiagnosticInfo" },
["!"] = { "!", "Comment" },
}
local function apply_git_status(buf)
if not vim.api.nvim_buf_is_valid(buf) then return end
vim.api.nvim_buf_clear_namespace(buf, ns, 0, -1)
local ok, canola = pcall(require, "canola")
if not ok then return end
local dir = canola.get_current_dir(buf)
if not dir then return end
local git_ok, git = pcall(require, "canola-git")
if not git_ok then return end
local dir_cache = git._cache[dir]
if not dir_cache or not dir_cache.status then return end
local lines = vim.api.nvim_buf_line_count(buf)
for lnum = 0, lines - 1 do
local entry = canola.get_entry_on_line(buf, lnum + 1)
if entry then
local status = dir_cache.status[entry.name]
if status then
local ch = status:sub(1, 1)
if ch == " " then ch = status:sub(2, 2) end
local sym = symbols[ch]
if sym then
vim.api.nvim_buf_set_extmark(buf, ns, lnum, 0, {
virt_text = { { " " .. sym[1], sym[2] } },
virt_text_pos = "eol",
invalidate = true,
})
end
end
end
end
end
vim.api.nvim_create_autocmd("User", {
pattern = "CanolaReadPost",
callback = function(args)
local buf = args.buf
apply_git_status(buf)
vim.defer_fn(function() apply_git_status(buf) end, 500)
end,
})
return { "barrettruth/canola.nvim" }

View file

@ -1,13 +1,6 @@
local api = vim.api
local augroup = api.nvim_create_augroup("UserAutocmds", { clear = true })
local function maybe_load_canola(bufnr)
local name = api.nvim_buf_get_name(bufnr)
if name == "" or vim.fn.isdirectory(name) == 0 then return end
pcall(vim.cmd, "silent keepalt Canola " .. vim.fn.fnameescape(name))
end
api.nvim_create_autocmd("TextYankPost", {
group = augroup,
callback = function() vim.highlight.on_yank { higroup = "Visual", timeout = 200 } end,
@ -22,20 +15,6 @@ api.nvim_create_autocmd("BufReadPost", {
end,
})
api.nvim_create_autocmd("BufEnter", {
group = augroup,
nested = true,
callback = function(args)
if vim.v.vim_did_enter == 1 then maybe_load_canola(args.buf) end
end,
})
api.nvim_create_autocmd("VimEnter", {
group = augroup,
nested = true,
callback = function() maybe_load_canola(0) end,
})
api.nvim_create_autocmd("VimResized", {
group = augroup,
callback = function()