feat: config function to define which files are hidden (#58)
This commit is contained in:
parent
f1ea6e0ad0
commit
e5acff1b77
3 changed files with 13 additions and 10 deletions
|
|
@ -52,6 +52,10 @@ local default_config = {
|
||||||
view_options = {
|
view_options = {
|
||||||
-- 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
|
||||||
|
is_hidden_file = function(name, bufnr)
|
||||||
|
return vim.startswith(name, ".")
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
-- Configuration for the floating window in oil.open_float
|
-- Configuration for the floating window in oil.open_float
|
||||||
float = {
|
float = {
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ end
|
||||||
---@param adapter oil.Adapter
|
---@param adapter oil.Adapter
|
||||||
---@param line string
|
---@param line string
|
||||||
---@param column_defs oil.ColumnSpec[]
|
---@param column_defs oil.ColumnSpec[]
|
||||||
---@return table
|
---@return nil|table Parsed entry data
|
||||||
---@return nil|oil.InternalEntry
|
---@return nil|oil.InternalEntry If the entry already exists
|
||||||
|
---@return nil|string Error message
|
||||||
M.parse_line = function(adapter, line, column_defs)
|
M.parse_line = function(adapter, line, column_defs)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
local value, rem = line:match("^/(%d+) (.+)$")
|
local value, rem = line:match("^/(%d+) (.+)$")
|
||||||
|
|
@ -118,7 +119,7 @@ M.parse = function(bufnr)
|
||||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
||||||
local original_entries = {}
|
local original_entries = {}
|
||||||
for _, child in pairs(children) do
|
for _, child in pairs(children) do
|
||||||
if view.should_display(child) then
|
if view.should_display(child, bufnr) then
|
||||||
original_entries[child[FIELD.name]] = child[FIELD.id]
|
original_entries[child[FIELD.name]] = child[FIELD.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -137,7 +138,7 @@ M.parse = function(bufnr)
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
if line:match("^/%d+") then
|
if line:match("^/%d+") then
|
||||||
local parsed_entry, entry, err = M.parse_line(adapter, line, column_defs)
|
local parsed_entry, entry, err = M.parse_line(adapter, line, column_defs)
|
||||||
if err then
|
if not parsed_entry then
|
||||||
table.insert(errors, {
|
table.insert(errors, {
|
||||||
message = err,
|
message = err,
|
||||||
lnum = i - 1,
|
lnum = i - 1,
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,11 @@ local M = {}
|
||||||
local last_cursor_entry = {}
|
local last_cursor_entry = {}
|
||||||
|
|
||||||
---@param entry oil.InternalEntry
|
---@param entry oil.InternalEntry
|
||||||
|
---@param bufnr integer
|
||||||
---@return boolean
|
---@return boolean
|
||||||
M.should_display = function(entry)
|
M.should_display = function(entry, bufnr)
|
||||||
local name = entry[FIELD.name]
|
local name = entry[FIELD.name]
|
||||||
if not config.view_options.show_hidden and vim.startswith(name, ".") then
|
return config.view_options.show_hidden or not config.view_options.is_hidden_file(name, bufnr)
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufname string
|
---@param bufname string
|
||||||
|
|
@ -318,7 +316,7 @@ local function render_buffer(bufnr, opts)
|
||||||
end
|
end
|
||||||
local virt_text = {}
|
local virt_text = {}
|
||||||
for _, entry in ipairs(entry_list) do
|
for _, entry in ipairs(entry_list) do
|
||||||
if not M.should_display(entry) then
|
if not M.should_display(entry, bufnr) then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
|
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue