diff options
| author | Simen A. W. Olsen <hello@simenandre.no> | 2024-12-27 15:33:47 +0100 |
|---|---|---|
| committer | Simen A. W. Olsen <hello@simenandre.no> | 2024-12-27 15:33:47 +0100 |
| commit | 62df997a42e292c22ee4ce6a5414735cd2e37699 (patch) | |
| tree | f677b40b7d9b070f5df1f10701f9f8c0af06085d /lua/simenandre/plugins/oil.lua | |
| parent | 9155cf33ed7533122666e193dad3f76e8a2b890f (diff) | |
| download | config.nvim-62df997a42e292c22ee4ce6a5414735cd2e37699.tar.gz config.nvim-62df997a42e292c22ee4ce6a5414735cd2e37699.zip | |
split plugins into each file
Diffstat (limited to 'lua/simenandre/plugins/oil.lua')
| -rw-r--r-- | lua/simenandre/plugins/oil.lua | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/lua/simenandre/plugins/oil.lua b/lua/simenandre/plugins/oil.lua index 37e8f94..dff5e1e 100644 --- a/lua/simenandre/plugins/oil.lua +++ b/lua/simenandre/plugins/oil.lua @@ -1,3 +1,52 @@ +-- 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() + +-- 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 + return { "stevearc/oil.nvim", opts = {}, @@ -10,9 +59,24 @@ return { ["<C-h>"] = false, ["<M-h>"] = "actions.select_split", }, + watch_for_changes = true, view_options = { - show_hidden = true, + is_hidden_file = function(name, bufnr) + 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] + else + -- Check if file is gitignored + return git_status[dir].ignored[name] + end + end, }, }) |
