diff --git a/README.md b/README.md index a1b8ed2..94afd84 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" ## Options +`base_directory`: Allow's you to define a base path for the creation of new +worktrees. + `change_directory_command`: The vim command used to change to the new worktree directory. Set this to `tcd` if you want to only change the `pwd` for the current vim Tab. @@ -89,6 +92,7 @@ edit the wrong files. ```lua require("git-worktree").setup({ + base_directory = -- default: "./" change_directory_command = -- default: "cd", update_on_change = -- default: true, update_on_change_command = -- default: "e .", diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 0fb5295..618d182 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -535,6 +535,7 @@ end M.setup = function(config) config = config or {} M._config = vim.tbl_deep_extend("force", { + base_directory = './', change_directory_command = "cd", update_on_change = true, update_on_change_command = "e .", diff --git a/lua/telescope/_extensions/git_worktree.lua b/lua/telescope/_extensions/git_worktree.lua index 905a358..6155912 100644 --- a/lua/telescope/_extensions/git_worktree.lua +++ b/lua/telescope/_extensions/git_worktree.lua @@ -130,6 +130,12 @@ local create_worktree = function(opts) if name == "" then name = branch end + + if string.match(name, '/') == nil and + git_worktree._config.base_directory then + name = git_worktree._config.base_directory .. name + end + git_worktree.create_worktree(name, branch) end) end)