Skip to content

Commit

Permalink
feat(remote-development): added remote-sshfs plugin (#1180)
Browse files Browse the repository at this point in the history
* feat(remote-development): added remote-sshfs plugin

* fix(remote-sshfs-nvim): fix plugin implementation

---------

Co-authored-by: Micah Halter <[email protected]>
  • Loading branch information
WilliamBy and mehalter committed Sep 3, 2024
1 parent cd45acc commit 6c9b679
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/astrocommunity/remote-development/remote-sshfs-nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# remote-sshfs

- Add plugin [remote-sshfs.nvim](https://github.com/nosduco/remote-sshfs.nvim)
- Require `sshfs` & `ssh`
- Bind keymap for convenience:
- `<leader>Re` edit ssh config file
- `<leader>Rc` select ssh target which is saved in your ssh config file
- `<leader>Rd` disconnect (this will unmount sshfs)
- Override telescope find_files and live_grep to make dynamic based on if connected to host
- Need `fd` and `ripgrep` be installed on server machine
- Check plugin README for more information
56 changes: 56 additions & 0 deletions lua/astrocommunity/remote-development/remote-sshfs-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---@type LazySpec
return {
"nosduco/remote-sshfs.nvim",
cmd = {
"RemoteSSHFSConnect",
"RemoteSSHFSDisconnect",
"RemoteSSHFSEdit",
"RemoteSSHFSFindFiles",
"RemoteSSHFSLiveGrep",
},
opts = {},
dependencies = {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope.nvim", opts = function() require("telescope").load_extension "remote-sshfs" end },
},
specs = {
{
"AstroNvim/astrocore",
optional = true,
opts = function(_, opts)
local map = opts.mappings
map.n["<Leader>R"] = { desc = "Remote" }
map.n["<Leader>Rc"] = { function() require("remote-sshfs.api").connect() end, desc = "Connect" }
map.n["<Leader>Rd"] = { function() require("remote-sshfs.api").disconnect() end, desc = "Disconnect" }
map.n["<Leader>Re"] = { function() require("remote-sshfs.api").edit() end, desc = "Edit" }
-- Override telescope find_files and live_grep to make dynamic based on if connected to host
local find_files = map.n["<Leader>ff"]
if type(find_files) == "table" then
local orig_find_files = find_files[1]
find_files[1] = function()
if require("remote-sshfs.connections").is_connected then
require("remote-sshfs.api").find_files()
elseif type(orig_find_files) == "function" then
orig_find_files()
elseif type(orig_find_files) == "string" then
vim.cmd(orig_find_files)
end
end
end
local live_grep = map.n["<Leader>fw"]
if type(live_grep) == "table" then
local orig_live_grep = live_grep[1]
live_grep[1] = function()
if require("remote-sshfs.connections").is_connected then
require("remote-sshfs.api").live_grep()
elseif type(orig_live_grep) == "function" then
orig_live_grep()
elseif type(orig_live_grep) == "string" then
vim.cmd(orig_live_grep)
end
end
end
end,
},
},
}

0 comments on commit 6c9b679

Please sign in to comment.