Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ OilFile *hl-OilFil
OilFileHidden *hl-OilFileHidden*
Hidden normal files in an oil buffer

OilExecutable *hl-OilExecutable*
Executable files in an oil buffer

OilCreate *hl-OilCreate*
Create action in the oil preview window

Expand Down
5 changes: 5 additions & 0 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ M._get_highlights = function()
link = "OilHidden",
desc = "Hidden normal files in an oil buffer",
},
{
name = "OilExecutable",
link = "DiagnosticOk",
desc = "Executable files in an oil buffer",
},
{
name = "OilCreate",
link = "DiagnosticInfo",
Expand Down
29 changes: 28 additions & 1 deletion lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ local function are_any_modified()
return false
end

local function is_unix_executable(entry)
if entry[FIELD_TYPE] == "directory" then return false end
local meta = entry[FIELD_META]
if not meta or not meta.stat then return false end
if meta.stat.type == "directory" then return false end

local S_IXUSR = 64
local S_IXGRP = 8
local S_IXOTH = 1
return bit.band(meta.stat.mode, bit.bor(S_IXUSR, S_IXGRP, S_IXOTH)) ~= 0
end

M.toggle_hidden = function()
local any_modified = are_any_modified()
if any_modified then
Expand Down Expand Up @@ -788,6 +800,15 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter, is_hidden
end
end

local highlight_as_executable = false
if entry_type ~= "directory" then
if name:sub(-4):lower() == ".exe" then
highlight_as_executable = true
elseif is_unix_executable(entry) then
highlight_as_executable = true
end
end

if entry_type == "directory" then
table.insert(cols, { name .. "/", "OilDir" .. hl_suffix })
elseif entry_type == "socket" then
Expand All @@ -798,7 +819,11 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter, is_hidden
end
local is_orphan = not (meta and meta.link_stat)
if not link_name_hl then
link_name_hl = (is_orphan and "OilOrphanLink" or "OilLink") .. hl_suffix
if highlight_as_executable then
link_name_hl = "OilExecutable" .. hl_suffix
else
link_name_hl = (is_orphan and "OilOrphanLink" or "OilLink") .. hl_suffix
end
end
table.insert(cols, { link_name, link_name_hl })

Expand All @@ -808,6 +833,8 @@ M.format_entry_cols = function(entry, column_defs, col_width, adapter, is_hidden
end
table.insert(cols, { link_target, link_target_hl })
end
elseif highlight_as_executable then
table.insert(cols, { name, "OilExecutable" .. hl_suffix })
else
table.insert(cols, { name, "OilFile" .. hl_suffix })
end
Expand Down