@@ -59,15 +59,6 @@ def run(*args, global: false, file: nil, subcommand: "")
59
59
60
60
command = args . first
61
61
62
- # For commands which aren't either absolute or relative
63
- if command . exclude? "/"
64
- # Save the command path, since this will be blown away by superenv
65
- command_path = which ( command )
66
- raise "command was not found in your PATH: #{ command } " if command_path . blank?
67
-
68
- command_path = command_path . dirname . to_s
69
- end
70
-
71
62
@dsl = Brewfile . read ( global :, file :)
72
63
73
64
require "formula"
@@ -111,8 +102,11 @@ def run(*args, global: false, file: nil, subcommand: "")
111
102
end
112
103
# rubocop:enable Homebrew/MoveToExtendOS
113
104
114
- # Ensure the Ruby path we saved goes before anything else, if the command was in the PATH
115
- ENV . prepend_path "PATH" , command_path if command_path . present?
105
+ # For commands which aren't either absolute or relative
106
+ # Add the command directory to PATH, since it may get blown away by superenv
107
+ if command . exclude? ( "/" ) && ( which_command = which ( command ) ) . present?
108
+ ENV . prepend_path "PATH" , which_command . dirname . to_s
109
+ end
116
110
117
111
# Replace the formula versions from the environment variables
118
112
formula_versions = { }
@@ -155,6 +149,9 @@ def run(*args, global: false, file: nil, subcommand: "")
155
149
ENV . append_path "PATH" , homebrew_path
156
150
end
157
151
152
+ # For commands which aren't either absolute or relative
153
+ raise "command was not found in your PATH: #{ command } " if command . exclude? ( "/" ) && which ( command ) . nil?
154
+
158
155
if subcommand == "env"
159
156
ENV . each do |key , value |
160
157
puts "export #{ key } =\" #{ value } \" "
0 commit comments