Skip to content
13 changes: 12 additions & 1 deletion lua/remote-sshfs/connections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local sshfs_args = {}
local sshfs_job_id = nil
local mount_point = nil
local current_host = nil
local original_dir = nil

local M = {}

Expand Down Expand Up @@ -53,6 +54,8 @@ M.reload = function()
end

M.connect = function(host)
-- Store original directory
original_dir = vim.fn.getcwd()
-- Initialize host variables
local remote_host = host["Name"]
if config.ui.confirm.connect then
Expand Down Expand Up @@ -296,11 +299,19 @@ M.unmount_host = function()
-- Fallback to generic umount
vim.fn.system { "umount", target }
end
-- restore original directory
if original_dir and vim.fn.isdirectory(original_dir) then
utils.change_directory(original_dir)
end
sshfs_job_id = nil
mount_point = nil
current_host = nil
original_dir = nil
-- Clear Telescope extension cache for remote-find commands
pcall(require, "telescope._extensions.remote-sshfs").clear_cache()
local ok, ext = pcall(require, "telescope._extensions.remote-sshfs")
if ok and ext.clear_cache then
ext.clear_cache()
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/remote-sshfs/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function M.status()
return ""
end

local host_tbl = conn.get_current_host and conn.get_current_host() or nil
local host_tbl = conn.get_current_host and conn.get_current_host()
local name = "remote"
if host_tbl and type(host_tbl) == "table" then
-- Prefer the explicit entries we create while parsing the ssh-config.
Expand Down
12 changes: 9 additions & 3 deletions lua/remote-sshfs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ M.parse_host_from_command = function(command)
return host
end

--- Change the working directory of the Vim instance
--- @param path string
M.change_directory = function(path)
-- Change the working directory of the Vim instance
vim.fn.execute("cd " .. path)
vim.notify("Directory changed to " .. path)
local ok, err = pcall(vim.api.nvim_set_current_dir, path)
if not ok then
vim.notify("Failed to change directory: " .. tostring(err), vim.log.levels.ERROR)
else
vim.cmd "edit ."
vim.notify("Directory changed to " .. path)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this notify does not show when disconnecting. It happens as far as I can tell, but disconnecting from the host overwrites it very quickly.

end
end

-- CallbackList class
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/_extensions/remote-sshfs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local ns_previewer = vim.api.nvim_create_namespace "telescope.previewers"

-- Build virtualized host file from parsed hosts from plugin
local function build_host_preview(hosts, name)
if name == "" or nil then
if not name and name == "" then
return {}
end

Expand Down