From 6c9b6796b5891793825de48e3dea9ed44c3b1f24 Mon Sep 17 00:00:00 2001 From: w1_liamby <55990985+WilliamBy@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:26:23 +0800 Subject: [PATCH] feat(remote-development): added remote-sshfs plugin (#1180) * feat(remote-development): added remote-sshfs plugin * fix(remote-sshfs-nvim): fix plugin implementation --------- Co-authored-by: Micah Halter --- .../remote-sshfs-nvim/README.md | 11 ++++ .../remote-sshfs-nvim/init.lua | 56 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 lua/astrocommunity/remote-development/remote-sshfs-nvim/README.md create mode 100644 lua/astrocommunity/remote-development/remote-sshfs-nvim/init.lua diff --git a/lua/astrocommunity/remote-development/remote-sshfs-nvim/README.md b/lua/astrocommunity/remote-development/remote-sshfs-nvim/README.md new file mode 100644 index 000000000..c8e5dd339 --- /dev/null +++ b/lua/astrocommunity/remote-development/remote-sshfs-nvim/README.md @@ -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: + - `Re` edit ssh config file + - `Rc` select ssh target which is saved in your ssh config file + - `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 diff --git a/lua/astrocommunity/remote-development/remote-sshfs-nvim/init.lua b/lua/astrocommunity/remote-development/remote-sshfs-nvim/init.lua new file mode 100644 index 000000000..a666d768e --- /dev/null +++ b/lua/astrocommunity/remote-development/remote-sshfs-nvim/init.lua @@ -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["R"] = { desc = "Remote" } + map.n["Rc"] = { function() require("remote-sshfs.api").connect() end, desc = "Connect" } + map.n["Rd"] = { function() require("remote-sshfs.api").disconnect() end, desc = "Disconnect" } + map.n["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["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["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, + }, + }, +}