git-worktree-switcher icon indicating copy to clipboard operation
git-worktree-switcher copied to clipboard

Avoid creating a new shell instance when using wt

Open mateusauler opened this issue 1 year ago • 7 comments

This PR creates shell functions that invoke wt and cd into the given directory. This partially solves #11.

What changed:

  • When running wt and giving it a valid worktree name, it echo's out changedir:<path>.
  • Adds the init sub-command for generating the shell code of the function.
  • The installation now requires the addition of a line to the shell config that invokes wt and runs the generated code. This is reflected in the readme.

I believe some further changes would be nice, but might be outside the scope of this PR:

  • Add a -- prefix for the sub-commands, to avoid collisions with worktree names.
  • The new init operation could also generate the completion scripts to reduce installation complexity. (This could be implemented in this PR)
  • Shell completions could include the sub-commands.

Some notes:

  • This introduces breaking changes, because the installation changed.
  • Instead of the shell function invoking wt, the whole script could be inside the shell function, thus not needing the ugly echoing.
  • The error messages are not the best...
  • Maybe the whole thing should be refactored :)

mateusauler avatar Apr 24 '24 13:04 mateusauler