feat: config function to define which files are hidden (#58)

This commit is contained in:
Steven Arcangeli 2023-02-22 21:05:41 -08:00
parent f1ea6e0ad0
commit e5acff1b77
3 changed files with 13 additions and 10 deletions

View file

@ -52,6 +52,10 @@ local default_config = {
view_options = {
-- 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, ".")
end,
},
-- Configuration for the floating window in oil.open_float
float = {

View file

@ -42,8 +42,9 @@ end
---@param adapter oil.Adapter
---@param line string
---@param column_defs oil.ColumnSpec[]
---@return table
---@return nil|oil.InternalEntry
---@return nil|table Parsed entry data
---@return nil|oil.InternalEntry If the entry already exists
---@return nil|string Error message
M.parse_line = function(adapter, line, column_defs)
local ret = {}
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 original_entries = {}
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]
end
end
@ -137,7 +138,7 @@ M.parse = function(bufnr)
for i, line in ipairs(lines) do
if line:match("^/%d+") then
local parsed_entry, entry, err = M.parse_line(adapter, line, column_defs)
if err then
if not parsed_entry then
table.insert(errors, {
message = err,
lnum = i - 1,

View file

@ -11,13 +11,11 @@ local M = {}
local last_cursor_entry = {}
---@param entry oil.InternalEntry
---@param bufnr integer
---@return boolean
M.should_display = function(entry)
M.should_display = function(entry, bufnr)
local name = entry[FIELD.name]
if not config.view_options.show_hidden and vim.startswith(name, ".") then
return false
end
return true
return config.view_options.show_hidden or not config.view_options.is_hidden_file(name, bufnr)
end
---@param bufname string
@ -318,7 +316,7 @@ local function render_buffer(bufnr, opts)
end
local virt_text = {}
for _, entry in ipairs(entry_list) do
if not M.should_display(entry) then
if not M.should_display(entry, bufnr) then
goto continue
end
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)