Problem: the permissions column rendered as a monolithic unstyled string, making it hard to scan `rwx` bits at a glance. Solution: add per-character highlight groups for permission characters following the `eza`/`lsd` convention. All groups link to standard Neovim highlights so every colorscheme works out of the box.
This commit is contained in:
parent
7b16324c5a
commit
bf461f6844
6 changed files with 81 additions and 3 deletions
|
|
@ -100,7 +100,8 @@ if not fs.is_windows then
|
|||
if not stat then
|
||||
return columns.EMPTY
|
||||
end
|
||||
return permissions.mode_to_str(stat.mode)
|
||||
local str = permissions.mode_to_str(stat.mode)
|
||||
return { str, permissions.mode_to_highlights(str) }
|
||||
end,
|
||||
|
||||
parse = function(line, conf)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,31 @@ M.mode_to_str = function(mode)
|
|||
.. perm_to_str(bit.band(extra, 1) ~= 0 and 't', mode)
|
||||
end
|
||||
|
||||
local char_hl = {
|
||||
r = 'OilPermissionRead',
|
||||
w = 'OilPermissionWrite',
|
||||
x = 'OilPermissionExec',
|
||||
s = 'OilPermissionSetuid',
|
||||
S = 'OilPermissionSetuid',
|
||||
t = 'OilPermissionSticky',
|
||||
T = 'OilPermissionSticky',
|
||||
['-'] = 'OilPermissionNone',
|
||||
}
|
||||
|
||||
---@param str string
|
||||
---@return table[]
|
||||
M.mode_to_highlights = function(str)
|
||||
local highlights = {}
|
||||
for i = 1, #str do
|
||||
local c = str:sub(i, i)
|
||||
local hl = char_hl[c]
|
||||
if hl then
|
||||
table.insert(highlights, { hl, i - 1, i })
|
||||
end
|
||||
end
|
||||
return highlights
|
||||
end
|
||||
|
||||
---@param mode integer
|
||||
---@return string
|
||||
M.mode_to_octal_str = function(mode)
|
||||
|
|
|
|||
|
|
@ -118,7 +118,11 @@ local ssh_columns = {}
|
|||
ssh_columns.permissions = {
|
||||
render = function(entry, conf)
|
||||
local meta = entry[FIELD_META]
|
||||
return meta and permissions.mode_to_str(meta.mode)
|
||||
if not meta then
|
||||
return
|
||||
end
|
||||
local str = permissions.mode_to_str(meta.mode)
|
||||
return { str, permissions.mode_to_highlights(str) }
|
||||
end,
|
||||
|
||||
parse = function(line, conf)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue