Summary
Two related issues when using git-gtr on a system with GNU coreutils installed via Homebrew.
Issues
1. gtr binary conflicts with coreutils
brew install coreutils provides /opt/homebrew/bin/gtr (GNU tr). Installing git-gtr via Homebrew fails to link because of this conflict:
$ brew link git-gtr
Error: Could not symlink bin/gtr
Target /opt/homebrew/bin/gtr
is a symlink belonging to coreutils.
This causes brew link to fail entirely, which also prevents the zsh/bash/fish completion files from being symlinked.
2. git gtr init zsh shadows coreutils gtr
Even without the binary conflict, eval "$(git gtr init zsh)" defines a gtr() shell function that shadows the coreutils gtr command. Additionally, gtr cd <tab> doesn't complete worktree names since cd is not listed in the completion file.
Workaround
My current workaround is to skip git gtr init zsh and define a custom function with completions (which gtr cd is currently missing):
if command -v git-gtr &> /dev/null; then
function gcd {
local dir
dir="$(git gtr go "$@")" && cd "$dir"
}
function _gcd {
local -a worktrees
worktrees=("1" ${(f)"$(git gtr list --porcelain 2>/dev/null | cut -f2)"})
_describe 'worktrees' worktrees
}
compdef _gcd gcd
fi
Suggested fixes
- Consider removing the
gtr shorthand binary — git gtr already works as a git subcommand, and the shorthand conflicts with coreutils. The shell init could alias it for users who want it.
- Consider adding
cd to the completion file, and using git gtr list --porcelain instead of git branch for worktree name completions
Environment
- macOS (Apple Silicon)
- Homebrew, with
coreutils installed
- git-gtr 2.3.0
Summary
Two related issues when using
git-gtron a system with GNU coreutils installed via Homebrew.Issues
1.
gtrbinary conflicts with coreutilsbrew install coreutilsprovides/opt/homebrew/bin/gtr(GNUtr). Installinggit-gtrvia Homebrew fails to link because of this conflict:This causes
brew linkto fail entirely, which also prevents the zsh/bash/fish completion files from being symlinked.2.
git gtr init zshshadows coreutilsgtrEven without the binary conflict,
eval "$(git gtr init zsh)"defines agtr()shell function that shadows the coreutilsgtrcommand. Additionally,gtr cd <tab>doesn't complete worktree names sincecdis not listed in the completion file.Workaround
My current workaround is to skip
git gtr init zshand define a custom function with completions (whichgtr cdis currently missing):Suggested fixes
gtrshorthand binary —git gtralready works as a git subcommand, and the shorthand conflicts with coreutils. The shell init could alias it for users who want it.cdto the completion file, and usinggit gtr list --porcelaininstead ofgit branchfor worktree name completionsEnvironment
coreutilsinstalled