Skip to content

Shell integration

A binary cannot change its parent shell’s directory, so twig ships a tiny shell function instead (the direnv/zoxide trick):

~/.zshrc
eval "$(twig shell-init zsh)"

Now:

Terminal window
tw matsumoto # cd's this shell into the worktree, then runs `twig enter`
tw # inside a repo: pick a worktree, then cd
tw -r fix-login # flags pass through to resolution (remote pickup here)

The function is three lines:

Terminal window
tw() {
local dir
dir="$(twig cd "$@")" || return $?
cd "$dir" || return $?
twig enter
}

twig cd prints only the path on stdout; prompts, pickers, and errors go to the terminal directly. That’s what makes the command substitution safe. twig enter then applies the same trust-gated setup as every other arrival path.

Supported shells: zsh, bash, fish. Rename the function with --cmd:

Terminal window
eval "$(twig shell-init zsh --cmd j)"
You doWhat happens
twig foonew terminal window (plus other openers), setup inside it
tw foocurrent shell cd’s there, setup runs right here
cd ... by hand, then twig entersame setup logic, fully manual

setup.auto = false in config makes all of them skip setup unless you pass --setup.