diff --git a/lsp/copilot.lua b/lsp/copilot.lua index a3eda87..31f8986 100644 --- a/lsp/copilot.lua +++ b/lsp/copilot.lua @@ -87,6 +87,8 @@ return { "swift", "kotlin", "zig", + + "make", }, root_markers = { ".git" }, init_options = { diff --git a/lua/kide/term.lua b/lua/kide/term.lua index aff6783..a4c4d20 100644 --- a/lua/kide/term.lua +++ b/lua/kide/term.lua @@ -12,6 +12,79 @@ local repls = { } local sid +local function is_fish_shell() + local shell = vim.o.shell or vim.env.SHELL or "" + return vim.endswith(shell, "fish") +end + +local function fish_complete(arglead, cmdline, cursorpos) + if not is_fish_shell() then + return vim.fn.getcompletion(arglead, "shellcmd") + end + + local line = cmdline or arglead or "" + if cursorpos and cursorpos > 0 then + line = line:sub(1, cursorpos) + end + + local ok, output = pcall(vim.fn.systemlist, { + vim.o.shell, + "-c", + "complete -C " .. vim.fn.shellescape(line), + }) + if not ok or vim.v.shell_error ~= 0 then + return {} + end + + local items = {} + for _, item in ipairs(output) do + local text = vim.split(item, "\t", { plain = true })[1] + if text and text ~= "" then + table.insert(items, text) + end + end + return items +end + +local function open_file_under_cursor() + local mode = vim.api.nvim_get_mode().mode + if mode == "t" then + vim.cmd("stopinsert") + end + + local file = vim.fn.expand("") + if file == nil or file == "" then + return + end + + local current_win = vim.api.nvim_get_current_win() + local fallback_win = nil + local file_path = vim.fn.fnamemodify(file, ":p") + + for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do + if win ~= current_win and vim.api.nvim_win_is_valid(win) then + local win_buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_is_valid(win_buf) and vim.api.nvim_buf_get_name(win_buf) == file_path then + vim.api.nvim_set_current_win(win) + return + end + + local cfg = vim.api.nvim_win_get_config(win) + if fallback_win == nil and cfg.relative == "" and vim.bo[win_buf].buftype == "" then + fallback_win = win + end + end + end + + if fallback_win ~= nil then + vim.api.nvim_set_current_win(fallback_win) + vim.cmd("edit " .. vim.fn.fnameescape(file)) + return + end + + vim.cmd("split " .. vim.fn.fnameescape(file)) +end + local function launch_term(cmd, opts) opts = opts or {} @@ -20,7 +93,10 @@ local function launch_term(cmd, opts) vim.cmd("belowright new") termwin = api.nvim_get_current_win() - require("kide").term_stl(vim.api.nvim_get_current_buf(), cmd) + local bufnr = vim.api.nvim_get_current_buf() + -- vim.wo.winfixbuf = true + require("kide").term_stl(bufnr, cmd) + vim.keymap.set({ "n" }, "", open_file_under_cursor, { silent = true, buffer = bufnr }) vim.bo.path = path vim.bo.buftype = "nofile" vim.bo.bufhidden = "wipe" @@ -99,14 +175,18 @@ function M.send_line(line) end M.last_input = nil -function M.input_run(last) - if last then - return M.toggle(M.last_input) - end - local ok, cmd = pcall(vim.fn.input, "CMD: ") +M.complete = fish_complete +_G.kide_term_run_complete = fish_complete + +function M.input_run() + local ok, cmd = pcall(vim.fn.input, { + prompt = "CMD: ", + default = M.last_input or "", + completion = "customlist,v:lua.kide_term_run_complete", + }) if ok then if cmd == "" then - M.toggle() + vim.notify("No command entered", vim.log.levels.WARN) else M.last_input = cmd M.toggle(cmd) diff --git a/lua/mappings.lua b/lua/mappings.lua index 7a987bb..b41dc04 100644 --- a/lua/mappings.lua +++ b/lua/mappings.lua @@ -156,13 +156,18 @@ end, { desc = "files", silent = true, noremap = true }) map("n", "o", "Outline", { desc = "Symbols Outline" }) -- task -command("TaskRun", function() - require("kide.term").input_run(false) -end, { desc = "Task Run" }) - -command("TaskRunLast", function() - require("kide.term").input_run(true) -end, { desc = "Restart Last Task" }) +command("Run", function(opt) + if opt.args ~= "" then + require("kide.term").last_input = opt.args + require("kide.term").toggle(opt.args) + return + end + require("kide.term").input_run() +end, { + desc = "Run Task", + nargs = "*", + complete = "customlist,v:lua.kide_term_run_complete", +}) map("n", "", function() require("conform").format({ lsp_fallback = true })