-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathoil.lua
More file actions
77 lines (64 loc) · 2.24 KB
/
oil.lua
File metadata and controls
77 lines (64 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- remote-sshfs ⇄ oil.nvim integration
--
-- This helper adds visual cues inside Oil buffers when the user browses a
-- directory located on a remote-sshfs mount.
--
-- 1. Column – shows " <host>" in the root row
-- 2. Winbar – sets the same label in the local winbar for Oil buffers
local helper = require "remote-sshfs.integration"
local M = {}
-------------------------------------------------------------------------------
-- utils ----------------------------------------------------------------------
-------------------------------------------------------------------------------
local function host_label()
return helper.label()
end
-------------------------------------------------------------------------------
-- 1. Column ------------------------------------------------------------------
-------------------------------------------------------------------------------
---Create an Oil column module displaying the current host label.
---@param opts table|nil { hl = 'HighlightGroup' }
function M.column(opts)
opts = opts or {}
return function()
local label = host_label()
if not label then
return nil
end
local hl = opts.hl or "DiagnosticHint"
return {
---@param entry table Oil row entry
---@return string, string? text, highlight
get_text = function(entry)
if entry.name == "." then
return label, hl
end
return "", nil
end,
column_width = #label,
}
end
end
-------------------------------------------------------------------------------
-- 2. Winbar ------------------------------------------------------------------
-------------------------------------------------------------------------------
function M.attach_winbar(opts)
opts = opts or {}
vim.api.nvim_create_autocmd("FileType", {
pattern = "oil",
group = vim.api.nvim_create_augroup("RemoteSSHFSOilWinbar", { clear = true }),
callback = function()
local label = host_label()
if not label then
vim.opt_local.winbar = nil
return
end
local hl = opts.hl or "DiagnosticHint"
if hl and vim.fn.hlexists(hl) == 1 then
label = string.format("%%#%s#%s%%*", hl, label)
end
vim.opt_local.winbar = label
end,
})
end
return M