summaryrefslogtreecommitdiffstats
path: root/lua/conf/plugins/oil.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/conf/plugins/oil.lua110
1 files changed, 92 insertions, 18 deletions
diff --git a/lua/conf/plugins/oil.lua b/lua/conf/plugins/oil.lua
index 5eeac4d..d985105 100644
--- a/lua/conf/plugins/oil.lua
+++ b/lua/conf/plugins/oil.lua
@@ -1,16 +1,85 @@
-local misc = require('core.misc')
+local misc = require("core.misc")
local map = misc.map
+-- helper function to parse output
+local function parse_output(proc)
+ local result = proc:wait()
+ local ret = {}
+ if result.code == 0 then
+ for line in vim.gsplit(result.stdout, "\n", { plain = true, trimempty = true }) do
+ -- Remove trailing slash
+ line = line:gsub("/$", "")
+ ret[line] = true
+ end
+ end
+ return ret
+end
+
+-- build git status cache
+local function new_git_status()
+ return setmetatable({}, {
+ __index = function(self, key)
+ local ignore_proc = vim.system(
+ { "git", "ls-files", "--ignored", "--exclude-standard", "--others", "--directory" },
+ {
+ cwd = key,
+ text = true,
+ }
+ )
+ local tracked_proc = vim.system({ "git", "ls-tree", "HEAD", "--name-only" }, {
+ cwd = key,
+ text = true,
+ })
+ local ret = {
+ ignored = parse_output(ignore_proc),
+ tracked = parse_output(tracked_proc),
+ }
+
+ rawset(self, key, ret)
+ return ret
+ end,
+ })
+end
+local git_status = new_git_status()
+
local permission_hlgroups = {
- ['-'] = 'NonText',
- ['r'] = 'DiagnosticSignWarn',
- ['w'] = 'DiagnosticSignHint',
- ['x'] = 'DiagnosticSignOk',
+ ["-"] = "NonText",
+ ["r"] = "DiagnosticSignWarn",
+ ["w"] = "DiagnosticSignHint",
+ ["x"] = "DiagnosticSignOk",
}
-return { 'stevearc/oil.nvim',
+return { "stevearc/oil.nvim",
disable = not vim.fn.has("nvim-0.8.0"),
+ deps = {
+ { "refractalize/oil-git-status.nvim",
+ function()
+ require("oil-git-status").setup {
+ symbols = { -- customize the symbols that appear in the git status columns
+ index = {
+ ["A"] = "+",
+ ["D"] = "-",
+ ["M"] = "~",
+ },
+ working_tree = {
+ ["A"] = "+",
+ ["D"] = "-",
+ ["M"] = "~",
+ }
+ }
+ }
+ end
+ }
+ },
function()
+ -- Clear git status cache on refresh
+ local refresh = require("oil.actions").refresh
+ local orig_refresh = refresh.callback
+ refresh.callback = function(...)
+ git_status = new_git_status()
+ orig_refresh(...)
+ end
+
require("oil").setup {
-- ID is automatically added at the beginning, and name at the end
-- See :help oil-columns
@@ -26,7 +95,7 @@ return { 'stevearc/oil.nvim',
return hls
end,
},
- { "size", highlight = '@number' }
+ { "size", highlight = "@number" }
},
-- Window-local options to use for oil buffers
@@ -34,7 +103,7 @@ return { 'stevearc/oil.nvim',
number = false,
relativenumber = false,
wrap = false,
- signcolumn = "no",
+ signcolumn = "yes:2",
cursorcolumn = false,
foldcolumn = "0",
spell = false,
@@ -100,11 +169,16 @@ return { 'stevearc/oil.nvim',
-- This function defines what is considered a "hidden" file
is_hidden_file = function(name, bufnr)
- if name == ".." then -- show previous directory
- return false
+ local dir = require("oil").get_current_dir(bufnr)
+ local is_dotfile = vim.startswith(name, ".") and name ~= ".."
+ -- if no local directory (e.g. for ssh connections), just hide dotfiles
+ if not dir then
+ return is_dotfile
+ end
+ -- dotfiles are considered hidden unless tracked
+ if is_dotfile then
+ return not git_status[dir].tracked[name]
end
- local m = name:match("^%.")
- return m ~= nil
end,
-- This function defines what will never be shown, even when `show_hidden` is set
@@ -134,27 +208,27 @@ return { 'stevearc/oil.nvim',
-- Configuration for the floating window in oil.open_float
float = {
- border = "solid"
+ border = vim.g.border_style
},
-- Configuration for the floating action confirmation window
confirmation = {
- border = "solid"
+ border = vim.g.border_style
},
-- Configuration for the floating progress window
progress = {
- border = "solid"
+ border = vim.g.border_style
},
-- Configuration for the floating SSH window
ssh = {
- border = "solid"
+ border = vim.g.border_style
},
-- Configuration for the floating keymaps help window
keymaps_help = {
- border = "solid"
+ border = vim.g.border_style
}
}
- map('n', '-', '<cmd>Oil<CR>')
+ map("n", "-", "<cmd>Oil<CR>")
end
}