-
Notifications
You must be signed in to change notification settings - Fork 66
Description
Problem
Switching to a worktree directory currently requires a verbose subshell pattern:
cd "$(git gtr go feature/user-auth)"This is cumbersome for frequent use.
Proposal
Provide a built-in shell helper (e.g. a function or alias) that allows something like:
gtr cd feature/user-authWhy not git gtr cd?
Since git gtr runs as a subprocess, it cannot change the parent shell's working directory. A true cd command would need to be implemented as a shell function rather than a script command.
Possible approaches
-
Ship a shell function that users source in their shell profile (
.bashrc/.zshrc/config.fish), e.g.:gtr() { if [ "$1" = "cd" ]; then shift local dir dir="$(git gtr go "$@")" && cd "$dir" else command git gtr "$@" fi }
-
Add a
git gtr shell-helpercommand that prints the function definition so users can eval/source it:# In .bashrc/.zshrc: eval "$(git gtr shell-helper bash)"
Similar to how tools like
direnv,fnm, andzoxidehandle shell integration. -
Document a recommended alias in the README, e.g.:
alias gcd='cd "$(git gtr go"'
Option 2 feels most aligned with the project's existing patterns (similar to git gtr completion).