Skip to content

Commit

Permalink
feat: highlight config
Browse files Browse the repository at this point in the history
Refs #402
  • Loading branch information
Foo-x committed Oct 30, 2024
1 parent 42333bb commit 542b6e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ require("oil").setup({
{ "type", "asc" },
{ "name", "asc" },
},
-- Return a highlight group name for each entry
highlight = function(name, type)
return nil
end,
},
-- Extra arguments to pass to SCP when moving/copying files over SSH
extra_scp_args = {},
Expand Down
4 changes: 4 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ CONFIG *oil-confi
{ "type", "asc" },
{ "name", "asc" },
},
-- Return a highlight group name for each entry
highlight = function(name, type)
return nil
end,
},
-- Extra arguments to pass to SCP when moving/copying files over SSH
extra_scp_args = {},
Expand Down
6 changes: 6 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ local default_config = {
{ "type", "asc" },
{ "name", "asc" },
},
-- Return a highlight group name for each entry
highlight = function(name, type)
return nil
end,
},
-- Extra arguments to pass to SCP when moving/copying files over SSH
extra_scp_args = {},
Expand Down Expand Up @@ -267,6 +271,7 @@ local M = {}
---@field natural_order boolean
---@field case_insensitive boolean
---@field sort oil.SortSpec[]
---@field highlight fun(name: string, type: string): string|nil

---@class (exact) oil.SetupViewOptions
---@field show_hidden? boolean Show files and directories that start with "."
Expand All @@ -275,6 +280,7 @@ local M = {}
---@field natural_order? boolean Sort file names in a more intuitive order for humans. Is less performant, so you may want to set to false if you work with large directories.
---@field case_insensitive? boolean Sort file and directory names case insensitive
---@field sort? oil.SortSpec[] Sort order for the file list
---@field highlight fun(name: string, type: string): string|nil Return a highlight group name for each entry

---@class (exact) oil.SortSpec
---@field [1] string
Expand Down
11 changes: 6 additions & 5 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,11 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter)
end
-- Always add the entry name at the end
local entry_type = entry[FIELD_TYPE]
local highlight = config.view_options.highlight
if entry_type == "directory" then
table.insert(cols, { name .. "/", "OilDir" })
table.insert(cols, { name .. "/", highlight(name, entry_type) or "OilDir" })
elseif entry_type == "socket" then
table.insert(cols, { name, "OilSocket" })
table.insert(cols, { name, highlight(name, entry_type) or "OilSocket" })
elseif entry_type == "link" then
local link_text
if meta then
Expand All @@ -719,12 +720,12 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter)
end
end

table.insert(cols, { name, "OilLink" })
table.insert(cols, { name, highlight(name, entry_type) or "OilLink" })
if link_text then
table.insert(cols, { link_text, "OilLinkTarget" })
table.insert(cols, { link_text, highlight(name, entry_type) or "OilLinkTarget" })
end
else
table.insert(cols, { name, "OilFile" })
table.insert(cols, { name, highlight(name, entry_type) or "OilFile" })
end
return cols
end
Expand Down

0 comments on commit 542b6e7

Please sign in to comment.