Skip to content

Commit 69c7a20

Browse files
committed
Fix brew edit with environment filtering.
For many people `brew edit` makes use of the `EDITOR` variable to pick a sensible editor. With environment filtering enabled unless this editor is found in the default system PATH it'll fall back to e.g. `vim`. Instead, ensure that we export the original, pre-filtering `PATH` as `HOMEBREW_PATH` and use that internally to locate the editor. In future this same approach will likely be used for requirements to be able to find tools, too, and for other variables which we want to expose to Homebrew itself but not other build tools. Note that `HOMEBREW_PATH` is the same as `PATH` when build filtering hasn't been enabled.
1 parent 6e1faf5 commit 69c7a20

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Library/Homebrew/test/utils_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ def esc(code)
189189

190190
specify "#which_editor" do
191191
ENV["HOMEBREW_EDITOR"] = "vemate"
192-
expect(which_editor).to eq("vemate")
192+
ENV["HOMEBREW_PATH"] = dir
193+
194+
editor = dir/"vemate"
195+
FileUtils.touch editor
196+
FileUtils.chmod 0755, editor
197+
198+
expect(which_editor).to eql editor
193199
end
194200

195201
specify "#gzip" do

Library/Homebrew/utils.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def which_all(cmd, path = ENV["PATH"])
320320
end
321321

322322
def which_editor
323-
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL", "EDITOR").compact.first
324-
return editor unless editor.nil?
323+
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.first
324+
return which(editor, ENV["HOMEBREW_PATH"]) unless editor.nil?
325325

326326
# Find Textmate
327327
editor = "mate" if which "mate"
@@ -334,7 +334,7 @@ def which_editor
334334

335335
opoo <<-EOS.undent
336336
Using #{editor} because no editor was set in the environment.
337-
This may change in the future, so we recommend setting EDITOR, VISUAL,
337+
This may change in the future, so we recommend setting EDITOR,
338338
or HOMEBREW_EDITOR to your preferred text editor.
339339
EOS
340340

bin/brew

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ fi
4444

4545
HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
4646

47+
for VAR in EDITOR PATH
48+
do
49+
VAR_NEW="HOMEBREW_${VAR}"
50+
# TODO: find a better solution than this.
51+
env | grep -q "$VAR_NEW" && continue
52+
export "$VAR_NEW"="${!VAR}"
53+
done
54+
4755
if [[ -n "$HOMEBREW_ENV_FILTERING" ]]
4856
then
4957
PATH="/usr/bin:/bin:/usr/sbin:/sbin"

0 commit comments

Comments
 (0)