Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 1ff1033

Browse files
committed
cmd/bundle: add brew bundle sh and brew bundle env helper commands.
These are (mostly) shorthands for `brew bundle exec sh` and `brew bundle exec env` that provide `brew`-like shell and environment features on top of `brew bundle exec`.
1 parent f5acb38 commit 1ff1033

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

cmd/bundle.rb

+28-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class BundleCmd < AbstractCommand
5353
Run an external command in an isolated build environment based on the `Brewfile` dependencies.
5454
5555
This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn't specify in your `Brewfile` won't get picked up by commands like `bundle install`, `npm install`, etc. It will also add compiler flags which will help with finding keg-only dependencies like `openssl`, `icu4c`, etc.
56+
57+
`brew bundle sh`:
58+
Run your shell in a `brew bundle exec` environment.
59+
60+
`brew bundle env`:
61+
Print the environment variables that would be set in a `brew bundle exec` environment.
5662
EOS
5763
flag "--file=",
5864
description: "Read the `Brewfile` from this location. Use `--file=-` to pipe to stdin/stdout."
@@ -110,7 +116,7 @@ class BundleCmd < AbstractCommand
110116
conflicts "--all", "--no-vscode"
111117
conflicts "--vscode", "--no-vscode"
112118

113-
named_args %w[install dump cleanup check exec list]
119+
named_args %w[install dump cleanup check exec list sh env]
114120
end
115121

116122
sig { override.void }
@@ -178,8 +184,27 @@ def run
178184
Bundle::Commands::Cleanup.run(global:, file:, force:, zap:)
179185
when "check"
180186
Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
181-
when "exec"
182-
_subcommand, *named_args = args.named
187+
when "exec", "sh", "env"
188+
named_args = case subcommand
189+
when "exec"
190+
_subcommand, *named_args = args.named
191+
named_args
192+
when "sh"
193+
preferred_shell = Utils::Shell.preferred_path(default: "/bin/bash")
194+
subshell = case Utils::Shell.preferred
195+
when :zsh
196+
"PS1='brew bundle %B%F{green}%~%f%b$ ' #{preferred_shell} -d -f"
197+
when :bash
198+
"PS1=\"brew bundle \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell} --noprofile --norc"
199+
else
200+
"PS1=\"brew bundle \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell}"
201+
end
202+
$stdout.flush
203+
ENV["HOMEBREW_FORCE_API_AUTO_UPDATE"] = nil
204+
[subshell]
205+
when "env"
206+
["env"]
207+
end
183208
Bundle::Commands::Exec.run(*named_args, global:, file:)
184209
when "list"
185210
Bundle::Commands::List.run(

0 commit comments

Comments
 (0)