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 Nov 1, 2024
1 parent 42333bb commit ecdb755
Show file tree
Hide file tree
Showing 4 changed files with 27 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(entry, is_link_target)
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(entry, is_link_target)
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(entry, is_link_target)
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(entry: oil.Entry, is_link_target: boolean): 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(entry: oil.Entry, is_link_target: boolean): string|nil Return a highlight group name for each entry

---@class (exact) oil.SortSpec
---@field [1] string
Expand Down
18 changes: 13 additions & 5 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,18 @@ 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 external_entry = {
id = entry[FIELD_ID],
name = name,
parsed_name = name,
type = entry_type,
meta = meta,
}
local highlight = config.view_options.highlight
if entry_type == "directory" then
table.insert(cols, { name .. "/", "OilDir" })
table.insert(cols, { name .. "/", highlight(external_entry, false) or "OilDir" })
elseif entry_type == "socket" then
table.insert(cols, { name, "OilSocket" })
table.insert(cols, { name, highlight(external_entry, false) or "OilSocket" })
elseif entry_type == "link" then
local link_text
if meta then
Expand All @@ -719,12 +727,12 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter)
end
end

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

0 comments on commit ecdb755

Please # to comment.