diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2026-06-27 22:48:15 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2026-06-27 22:48:15 -0300 |
| commit | a0bd84df02ce235123dfc939327e8bd33dffdd7e (patch) | |
| tree | 3a1f3095863502f01a112275a839d81ce832de1c /lua/config/worktree.lua | |
| parent | 2895ac732dce0eece5ab2586f5d4d76ee0fab710 (diff) | |
| download | nvim-conf-a0bd84df02ce235123dfc939327e8bd33dffdd7e.tar.gz nvim-conf-a0bd84df02ce235123dfc939327e8bd33dffdd7e.zip | |
Remplazando y eliminando plugins a favor de cosas nativas.
Diffstat (limited to 'lua/config/worktree.lua')
| -rw-r--r-- | lua/config/worktree.lua | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lua/config/worktree.lua b/lua/config/worktree.lua new file mode 100644 index 0000000..dd4e837 --- /dev/null +++ b/lua/config/worktree.lua @@ -0,0 +1,59 @@ +-- Git worktrees nativos vía `git` + vim.ui (reemplaza ThePrimeagen/git-worktree.nvim). +-- vim.ui.select/input los provee Snacks, así que se elimina además una dependencia de telescope. +local M = {} + +local function git(args) + local res = vim.system(vim.list_extend({ "git" }, args), { text = true }):wait() + return res.code == 0, vim.trim(res.stdout or ""), vim.trim(res.stderr or "") +end + +function M.switch() + local ok, out = git { "worktree", "list", "--porcelain" } + if not ok then + vim.notify("No es un repositorio git con worktrees", vim.log.levels.WARN) + return + end + local trees = {} + for path in out:gmatch "worktree (.-)\n" do + table.insert(trees, path) + end + -- el último no termina en \n + local last = out:match "worktree ([^\n]+)$" + if last then + table.insert(trees, last) + end + if #trees == 0 then + vim.notify("Sin worktrees", vim.log.levels.WARN) + return + end + vim.ui.select(trees, { prompt = "Cambiar a worktree" }, function(choice) + if not choice then + return + end + vim.cmd("cd " .. vim.fn.fnameescape(choice)) + vim.notify("Worktree: " .. choice) + end) +end + +function M.create() + vim.ui.input({ prompt = "Nueva rama/worktree: " }, function(name) + if not name or name == "" then + return + end + local ok, root = git { "rev-parse", "--show-toplevel" } + if not ok then + vim.notify("No es un repositorio git", vim.log.levels.WARN) + return + end + local path = vim.fn.fnamemodify(root, ":h") .. "/" .. name + local cok, _, cerr = git { "worktree", "add", path, "-b", name } + if not cok then + vim.notify("Error al crear worktree: " .. cerr, vim.log.levels.ERROR) + return + end + vim.cmd("cd " .. vim.fn.fnameescape(path)) + vim.notify("Worktree creado: " .. path) + end) +end + +return M |