Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add base directory config #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

## Options<a name="options"></a>

`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.

Expand All @@ -89,6 +92,7 @@ edit the wrong files.

```lua
require("git-worktree").setup({
base_directory = <str> -- default: "./"
change_directory_command = <str> -- default: "cd",
update_on_change = <boolean> -- default: true,
update_on_change_command = <str> -- default: "e .",
Expand Down
1 change: 1 addition & 0 deletions lua/git-worktree/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
6 changes: 6 additions & 0 deletions lua/telescope/_extensions/git_worktree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down