Subject: bug#71235: Failing test on macOS: tramp-test17-dired-with-wildcards

From: Gerd Möllmann <[email-masked]>
Date: Sun, 02 Jun 2024 16:03:20 +0200

Stefan Kangas <[email-masked]> writes:

> Michael Albinus <[email-masked]> writes:
>
>>>     (executable-find "gls")
>>>     => "/opt/homebrew/bin/gls"
>>
>> Hmm. Should we add "/opt/homebrew/bin" to the default
>> tramp-remote-path? It looks very special, even on macOS.
>>
>> OTOH, we have directories like "/local/freeware/bin", "/local/gnu/bin",
>> "/usr/freeware/bin", "/usr/pkg/bin", "/usr/contrib/bin", "/opt/bin",
>> "/opt/sbin" and "/opt/local/bin" there, which are also special.
>
> AFAIK, this is the default location where Homebrew (https://brew.sh/)
> puts binaries, at least on new installations.  (The Homebrew directory
> structure has changed slightly over the years, but I don't know if this
> is one of them since I only noticed it those changes passing.)
>
> I think it might make sense to add it to `tramp-remote-path`, but I'm
> not familiar enough with Tramp to understand all the implications of
> doing so.  I'm copying in Mattias and Gerd, who I believe are using
> macOS, in case they have anything to add.

Homebrew uses different directories depending on if it's on a mac with
x64 or arm64. I have both, and find the easiest thing to do is to use
the brew shellenv command in my .zshenv to set up things. (I have a
common dotfles setup for my machines.)

  /Users/gerd % brew shellenv 
  export HOMEBREW_PREFIX="/opt/homebrew";
  export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
  export HOMEBREW_REPOSITORY="/opt/homebrew";
  export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
  export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
  export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";

Then, I'm using exec-path-from-shell in my init.el to get the shell
environment into Emacs, even when started from Emacs.app. Starting an
.app bundle doesn't involve the shell, so one has to do something.

Works like a charm with everything I use, including things like Magit
over tramp, and so on.

(If you are using zsh from Homebrew and not the one from macOS, you
might want to call connection-local-set-profile-variables or something
to get the right zsh.)