Skip to content

Commit 7d499d3

Browse files
committed
refactor: nvchad status line integration
1 parent 4942b29 commit 7d499d3

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ The module returns an **empty string** when no host is mounted which makes it
184184
safe to drop into existing layouts.
185185

186186
<details>
187-
<summary><b>NvChad / Heirline (v2.*)</b></summary>
187+
<summary><b>NvChad (built-in statusline)</b></summary>
188188

189189
NvChad exposes its UI configuration through the return table of
190190
`lua/chadrc.lua`. The snippet below **extends** the default status-line instead
@@ -196,19 +196,23 @@ of replacing it.
196196
local M = {}
197197

198198
-- 1️⃣ Fetch the default lay-out that ships with NvChad
199-
local default = require "nvchad.statusline.default"
200-
201-
-- 2️⃣ Create the remote-sshfs component (shows: 󰀻 <hostname> while connected)
202-
local remote = require("remote-sshfs.statusline").nvchad_component {
203-
highlight = { fg = "green" }, -- (optional) colour override
199+
-- 1️⃣ Create a callable module for NvChad’s statusline
200+
local remote_module = require("remote-sshfs.statusline").nvchad_module {
201+
highlight = "St_gitIcons", -- highlight group (optional)
204202
}
205203

206-
-- 3️⃣ Inject it wherever you want. Here we append at the end.
207-
table.insert(default, remote)
208-
209-
-- 4️⃣ Expose the modified layout back to NvChad
204+
-- 2️⃣ Add it to `modules` *and* reference it in `order`
210205
M.ui = {
211-
statusline = default,
206+
statusline = {
207+
-- theme / separator_style as you already have…
208+
209+
-- insert the module name wherever you like
210+
order = { "mode", "f", "git", "%=", "remote", "%=", "lsp", "cwd" },
211+
212+
modules = {
213+
remote = remote_module,
214+
},
215+
},
212216
}
213217

214218
return M

lua/remote-sshfs/statusline.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@ function M.nvchad_component(opts)
6565
}
6666
end
6767

68+
-------------------------------------------------------------------------------
69+
-- NvChad (classic v3 statusline) module helper --------------------------------
70+
-------------------------------------------------------------------------------
71+
72+
-- NvChad’s in-house statusline (documented under `:h nvui.statusline`) expects
73+
-- plain strings or Lua callables in the `modules` table. This helper returns
74+
-- such a callable, so users can simply do
75+
--
76+
-- M.ui = {
77+
-- statusline = {
78+
-- modules = {
79+
-- remote = require("remote-sshfs.statusline").nvchad_module(),
80+
-- }
81+
-- }
82+
-- }
83+
--
84+
-- `opts.highlight` – optional highlight group name, e.g. "St_gitIcons".
85+
function M.nvchad_module(opts)
86+
opts = opts or {}
87+
local hl_begin = opts.highlight and ("%#" .. opts.highlight .. "#") or ""
88+
local hl_end = opts.highlight and "%*" or ""
89+
90+
return function()
91+
local s = M.status()
92+
if s == "" then
93+
return ""
94+
end
95+
return hl_begin .. s .. hl_end
96+
end
97+
end
98+
6899
-------------------------------------------------------------------------------
69100
-- Fall-back plain string for easy integration in classic statuslines ---------
70101
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)