Skip to content

gtr binary and shell function conflict with coreutils (GNU tr) #124

Description

@fmal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions