aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike McQuaid2015-12-25 22:42:32 +0000
committerMike McQuaid2016-01-17 19:48:02 +0000
commitb01ce411641c64d36688a58999c3644ab0daf4a7 (patch)
treeb7da3b93020168f2edee33d7bc63df211af9e702
parenteffca7d9c60495f7c5c21af637da4e0e2952f66e (diff)
downloadbrew-b01ce411641c64d36688a58999c3644ab0daf4a7.tar.bz2
bin/brew: allow writing Homebrew commands in Bash.
-rwxr-xr-xbin/brew35
1 files changed, 32 insertions, 3 deletions
diff --git a/bin/brew b/bin/brew
index 30d4f9c49..5a4aef5fb 100755
--- a/bin/brew
+++ b/bin/brew
@@ -1,7 +1,10 @@
-#!/bin/sh
+#!/bin/bash
chdir() {
- cd "$@" >/dev/null
+ cd "$@" >/dev/null || {
+ echo "Error: failed to cd to " "$@" "!" >&2
+ exit 1
+ }
}
# Force UTF-8 to avoid encoding issues for users with broken locale settings.
@@ -61,4 +64,30 @@ export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY
export HOMEBREW_CELLAR
-exec "$HOMEBREW_RUBY_PATH" -W0 "$BREW_LIBRARY_DIRECTORY/brew.rb" "$@"
+for i in "$@"
+do
+ if [[ "$1" = -v ]]
+ then
+ shift
+ set -- "$@" -v
+ fi
+ [[ "$i" =~ ^- ]] && continue
+ HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$i.sh"
+ break
+done
+
+if [ -n "$HOMEBREW_BASH_COMMAND" ] && [ -x "$HOMEBREW_BASH_COMMAND" ]
+then
+ # source rather than executing directly to ensure the entire file is read into
+ # memory before it is run. This makes running a Bash script behave more like
+ # a Ruby script and avoids hard-to-debug issues if the Bash script is updated
+ # at the same time as being run.
+ #
+ # Hide shellcheck complaint:
+ # shellcheck source=/dev/null
+ source "$HOMEBREW_BASH_COMMAND"
+ "$HOMEBREW_COMMAND" "$@"
+ exit $?
+else
+ exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/brew.rb" "$@"
+fi