Merge pull request #8482 from maxim-belkin/non-interactive-sh

dev-cmd/sh.rb: non-interactive mode
This commit is contained in:
Mike McQuaid 2020-08-28 09:37:37 +01:00 committed by GitHub
commit fcacd46a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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>] [<file>]
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,12 +40,19 @@ 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
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.first)
else
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
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
@ -56,4 +64,5 @@ module Homebrew
$stdout.flush
safe_system subshell
end
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`*] [*`file`*]
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] [\fIfile\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\.
.