dev-cmd/sh.rb: non-interactive mode

This commit is contained in:
Maxim Belkin 2020-08-25 14:45:09 +00:00
parent ff8d30df74
commit 28c43f1afc
3 changed files with 41 additions and 26 deletions

View File

@ -10,18 +10,19 @@ module Homebrew
def sh_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`sh` [<options>]
`sh` [<options>] [<commands>]
Start a Homebrew build environment shell. Uses our years-battle-hardened
Homebrew build logic to help your `./configure && make && make install`
or even your `gem install` succeed. Especially handy if you run Homebrew
Homebrew build environment that uses years-battle-hardened
build logic to help your `./configure && make && make install`
and even your `gem install` succeed. Especially handy if you run Homebrew
in an Xcode-only configuration since it adds tools like `make` to your `PATH`
which build systems would not find otherwise.
EOS
flag "--env=",
description: "Use the standard `PATH` instead of superenv's when `std` is passed."
max_named 0
flag "-c=", "--cmd=",
description: "Execute commands in a non-interactive shell."
max_named 1
end
end
@ -39,21 +40,29 @@ module Homebrew
# superenv stopped adding brew's bin but generally users will want it
ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin")
end
subshell = if ENV["SHELL"].include?("zsh")
"PS1='brew %B%F{green}%~%f%b$ ' #{ENV["SHELL"]} -d"
ENV["VERBOSE"] = "1" if args.verbose?
if args.cmd.present?
safe_system(ENV["SHELL"], "-c", args.cmd)
elsif args.named.present?
safe_system(ENV["SHELL"], args.named[0])
else
"PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]}"
subshell = if ENV["SHELL"].include?("zsh")
"PS1='brew %B%F{green}%~%f%b$ ' #{ENV["SHELL"]} -d"
else
"PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]}"
end
puts <<~EOS
Your shell has been configured to use Homebrew's build environment;
this should help you build stuff. Notably though, the system versions of
gem and pip will ignore our configuration and insist on using the
environment they were built under (mostly). Sadly, scons will also
ignore our configuration.
When done, type `exit`.
EOS
$stdout.flush
safe_system subshell
end
ENV["VERBOSE"] = "1"
puts <<~EOS
Your shell has been configured to use Homebrew's build environment;
this should help you build stuff. Notably though, the system versions of
gem and pip will ignore our configuration and insist on using the
environment they were built under (mostly). Sadly, scons will also
ignore our configuration.
When done, type `exit`.
EOS
$stdout.flush
safe_system subshell
end
end

View File

@ -1106,16 +1106,18 @@ Run a Ruby instance with Homebrew's libraries loaded, e.g.
* `-e`:
Execute the given text string as a script.
### `sh` [*`options`*]
### `sh` [*`options`*] [*`commands`*]
Start a Homebrew build environment shell. Uses our years-battle-hardened
Homebrew build logic to help your `./configure && make && make install`
or even your `gem install` succeed. Especially handy if you run Homebrew
Homebrew build environment that uses years-battle-hardened
build logic to help your `./configure && make && make install`
and even your `gem install` succeed. Especially handy if you run Homebrew
in an Xcode-only configuration since it adds tools like `make` to your `PATH`
which build systems would not find otherwise.
* `--env`:
Use the standard `PATH` instead of superenv's when `std` is passed.
* `-c`, `--cmd`:
Execute commands in a non-interactive shell.
### `sponsors`

View File

@ -1522,13 +1522,17 @@ Load a library using \fBrequire\fR\.
\fB\-e\fR
Execute the given text string as a script\.
.
.SS "\fBsh\fR [\fIoptions\fR]"
Start a Homebrew build environment shell\. Uses our years\-battle\-hardened Homebrew build logic to help your \fB\./configure && make && make install\fR or even your \fBgem install\fR succeed\. Especially handy if you run Homebrew in an Xcode\-only configuration since it adds tools like \fBmake\fR to your \fBPATH\fR which build systems would not find otherwise\.
.SS "\fBsh\fR [\fIoptions\fR] [\fIcommands\fR]"
Homebrew build environment that uses years\-battle\-hardened build logic to help your \fB\./configure && make && make install\fR and even your \fBgem install\fR succeed\. Especially handy if you run Homebrew in an Xcode\-only configuration since it adds tools like \fBmake\fR to your \fBPATH\fR which build systems would not find otherwise\.
.
.TP
\fB\-\-env\fR
Use the standard \fBPATH\fR instead of superenv\'s when \fBstd\fR is passed\.
.
.TP
\fB\-c\fR, \fB\-\-cmd\fR
Execute commands in a non\-interactive shell\.
.
.SS "\fBsponsors\fR"
Print a Markdown summary of Homebrew\'s GitHub Sponsors, suitable for pasting into a README\.
.