oil: don't show git ignored files and folders

This commit is contained in:
Vladan Popovic 2024-07-20 02:55:46 +02:00
parent 2efe116082
commit 9a29f15556
1 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,27 @@
local git_ignored = setmetatable({}, {
__index = function(self, key)
local proc = vim.system(
{ "git", "ls-files", "--ignored", "--exclude-standard", "--others", "--directory" },
{
cwd = key,
text = true,
}
)
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("/$", "")
table.insert(ret, line)
end
end
rawset(self, key, ret)
return ret
end,
})
require('oil').setup({
default_file_explorer = true,
-- Id is automatically added at the beginning, and name at the end
@ -61,8 +85,16 @@ require('oil').setup({
-- Show files and directories that start with "."
show_hidden = false,
-- This function defines what is considered a "hidden" file
is_hidden_file = function(name, bufnr)
return vim.startswith(name, ".")
is_hidden_file = function(name, _)
if vim.startswith(name, ".") then
return true
end
local dir = require("oil").get_current_dir()
-- if no local directory (e.g. for ssh connections), always show
if not dir then
return false
end
return vim.list_contains(git_ignored[dir], name)
end,
-- This function defines what will never be shown, even when `show_hidden` is set
is_always_hidden = function(name, bufnr)