Skip to content

Commit

Permalink
feat: config function to define which files are hidden (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Feb 23, 2023
1 parent f1ea6e0 commit e5acff1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
9 changes: 5 additions & 4 deletions lua/oil/mutator/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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+) (.+)$")
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e5acff1

Please sign in to comment.