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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,40 @@ and vanishes as soon as you disconnect.

</details>

### File-browser / tree integrations

<details>
<summary><b>Oil.nvim</b></summary>

`remote-sshfs.nvim` also provides convenience helpers for
[oil.nvim](https://github.com/stevearc/oil.nvim):

```lua
-- lua/plugins/oil.lua / wherever you configure oil.nvim

require("oil").setup {
columns = {
"icon",
require("remote-sshfs.filebrowser.oil").column { hl = "DiagnosticHint" },
"mtime",
},
}

-- Alternatively (or additionally) show the host in the win-bar of every Oil
-- buffer:
require("remote-sshfs.filebrowser.oil").attach_winbar { hl = "DiagnosticHint" }
```

Result (only while connected):

```
󰀻 myserver … <directory listing follows>
```

The helpers automatically hide themselves when you disconnect.

</details>

## 🤝 Contributing

If you find a bug or have a suggestion for how to improve remote-sshfs.nvim or additional functionality, please feel free to submit an issue or a pull request. We welcome contributions from the community and are committed to making remote-sshfs.nvim as useful as possible for everyone who uses it.
Expand Down
77 changes: 77 additions & 0 deletions lua/remote-sshfs/filebrowser/oil.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
44 changes: 44 additions & 0 deletions lua/remote-sshfs/integration.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Shared helper functions used by various optional UI integrations
-- (statusline, file browser columns, etc.). Keeping them here avoids code
-- duplication between individual adapters like *statusline.lua* or
-- *filebrowser/oil.lua*.

local M = {}

-------------------------------------------------------------------------------
-- Icon -----------------------------------------------------------------------
-------------------------------------------------------------------------------

M.icon = vim.g.remote_sshfs_status_icon or "󰀻" -- nf-mdi-server (similar to VSCode)

-------------------------------------------------------------------------------
-- Host info ------------------------------------------------------------------
-------------------------------------------------------------------------------

-- Returns current host table or nil
local function current_host()
local ok, conn = pcall(require, "remote-sshfs.connections")
if not ok or type(conn) ~= "table" then
return nil
end
if not conn.is_connected or not conn.is_connected() then
return nil
end
if not conn.get_current_host then
return nil
end
return conn.get_current_host()
end

-- Public helper: Returns nil when not connected, else "󰀻 hostname"
function M.label()
local host = current_host()
if not host then
return nil
end

local name = host.Name or host.Host or host.HostName or host.host or "remote"
return string.format("%s %s", M.icon, name)
end

return M
35 changes: 7 additions & 28 deletions lua/remote-sshfs/statusline.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
local M = {}

-- Default icon displayed when a connection is active. Nerd-font compatible.
-- Users can override this by setting `vim.g.remote_sshfs_status_icon` before
-- the plugin is loaded or by changing `M.icon` afterwards.
M.icon = vim.g.remote_sshfs_status_icon or "󰀻" -- nf-mdi-server
local helper = require "remote-sshfs.integration"

-- Return a short human-readable string that represents the current connection
-- state. If no connection is active an empty string is returned so that the
-- statusline stays unchanged.
--
-- Examples:
-- "" – when not connected
-- "󰀻 myserver" – when connected to host *myserver*
function M.status()
local ok, conn = pcall(require, "remote-sshfs.connections")
if not ok or type(conn) ~= "table" then
return ""
end
local M = {}

if not conn.is_connected or not conn.is_connected() then
return ""
end
-- Expose icon through the same table (backwards-compat).
M.icon = helper.icon

local host_tbl = conn.get_current_host and conn.get_current_host() or nil
local name = "remote"
if host_tbl and type(host_tbl) == "table" then
-- Prefer the explicit entries we create while parsing the ssh-config.
name = host_tbl.Name or host_tbl.Host or host_tbl.host or name
end
-- Delegated helpers ----------------------------------------------------------

return string.format("%s %s", M.icon, name)
function M.status()
return helper.label() or ""
end

-------------------------------------------------------------------------------
Expand Down