oil: don't show git ignored files and folders
This commit is contained in:
parent
2efe116082
commit
9a29f15556
1 changed files with 34 additions and 2 deletions
|
@ -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({
|
require('oil').setup({
|
||||||
default_file_explorer = true,
|
default_file_explorer = true,
|
||||||
-- Id is automatically added at the beginning, and name at the end
|
-- 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 files and directories that start with "."
|
||||||
show_hidden = false,
|
show_hidden = false,
|
||||||
-- This function defines what is considered a "hidden" file
|
-- This function defines what is considered a "hidden" file
|
||||||
is_hidden_file = function(name, bufnr)
|
is_hidden_file = function(name, _)
|
||||||
return vim.startswith(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,
|
end,
|
||||||
-- This function defines what will never be shown, even when `show_hidden` is set
|
-- This function defines what will never be shown, even when `show_hidden` is set
|
||||||
is_always_hidden = function(name, bufnr)
|
is_always_hidden = function(name, bufnr)
|
||||||
|
|
Loading…
Reference in a new issue