diff --git a/lazy-lock.json b/lazy-lock.json index ff419fc..2b6e7dd 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -8,6 +8,7 @@ "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "flash.nvim": { "branch": "main", "commit": "3c942666f115e2811e959eabbdd361a025db8b63" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "fzf-lua": { "branch": "main", "commit": "70cdea35ac8fe5e3a977616b883d780a842cc115" }, "gitsigns.nvim": { "branch": "main", "commit": "6e3c66548035e50db7bd8e360a29aec6620c3641" }, "kanagawa": { "branch": "master", "commit": "debe91547d7fb1eef34ce26a5106f277fbfdd109" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, diff --git a/lua/weeheavy/plugins/fzf.lua b/lua/weeheavy/plugins/fzf.lua new file mode 100644 index 0000000..4d170ca --- /dev/null +++ b/lua/weeheavy/plugins/fzf.lua @@ -0,0 +1,6 @@ +-- Fuzzy finder. Mainly used for oil.nvim SSH +return { + "ibhagwan/fzf-lua", + -- event = { "BufReadPre", "BufNewFile" }, + enabled = true, +} diff --git a/lua/weeheavy/remap.lua b/lua/weeheavy/remap.lua index 01a516c..7144f5d 100644 --- a/lua/weeheavy/remap.lua +++ b/lua/weeheavy/remap.lua @@ -121,3 +121,54 @@ vim.keymap.set("n", "p", ":TimerStart 30m", { desc = "Pomodoro" }) vim.keymap.set("n", "fc", function() require("treesitter-context").go_to_context(vim.v.count1) end, { silent = true }) + +-- Claude wrote this SSH clusterfuck +local function get_ssh_hosts() + local known_hosts_path = vim.fn.expand("~/.ssh/known_hosts") + local hosts = {} + + if vim.fn.filereadable(known_hosts_path) == 1 then + local file = io.open(known_hosts_path, "r") + if file then + for line in file:lines() do + -- Parse known_hosts format: hostname[,hostname] key-type key [comment] + local host = line:match("^([^%s,]+)") + if host and not host:match("^#") and not host:match("^%|") then + -- Remove bracketed IP addresses and ports + host = host:gsub("%[(.-)%].*", "%1") + host = host:gsub(":.*", "") + if host ~= "" and not vim.tbl_contains(hosts, host) then + table.insert(hosts, host) + end + end + end + file:close() + end + end + + return hosts +end + +vim.keymap.set("n", "ss", function() + local hosts = get_ssh_hosts() + + if #hosts == 0 then + vim.notify("No SSH hosts found in ~/.ssh/known_hosts", vim.log.levels.WARN) + return + end + + require("fzf-lua").fzf_exec(hosts, { + prompt = "SSH target: ", + actions = { + ["default"] = function(selected) + if selected and #selected > 0 then + local host = selected[1] + local ssh_url = "oil-ssh://" .. host .. "/" + require("oil").open(ssh_url) + end + end, + }, + -- winopts = { height = 0.2, width = 0.2, row = 0.5, border = "single", treesitter = true }, + winopts = { height = 0.2, width = 0.2, row = 0.5, title = "Where do you want to go today?", backdrop = 100 }, + }) +end, { desc = "SSH to host" })