5 # bash shim to invoke brew-cask-cmd.rb
26 message
="${message//\\t/$'\011'}"
27 message
="${message//\\n/$'\012'}"
28 message
="${message%"${message##*[![:space:]]}"}"
29 printf "%s\n" "$message" 1>&2
38 local resolved
="$(for dir; do cd "$dir"; done && /bin/pwd -P)"
39 if [[ -d "$resolved" ]]; then
40 printf "%s" "$resolved"
42 die
"cannot resolve: '$@'"
51 if [ "$#" -gt 0 ]; then
54 message
="brew-cask: no such directory: '$dir'"
56 if ! [[ -d "$dir" ]]; then
66 if [ "$#" -gt 0 ]; then
69 message
="brew-cask: no such file: '$file'"
71 if ! [[ -f "$file" ]]; then
76 ensure_executable
() {
81 if [ "$#" -gt 0 ]; then
84 message
="brew-cask: no such executable: '$executable'"
86 if ! [[ -f "$executable" ]] ||
! [[ -x "$executable" ]]; then
93 local favorite_ruby
="/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby"
96 if [[ -x "$favorite_ruby" ]]; then
97 printf "%s" "$favorite_ruby"
99 IFS
=$
'\n' rubies
=( $
(/usr
/bin
/type -aP ruby
) \
100 "/usr/local/bin/ruby" \
101 "$(brew --prefix 2>/dev/null)/bin/ruby" )
102 for ruby
in "${rubies[@]}"; do
103 version_str
="$("$ruby" --version 2>/dev/null)"
104 if [[ "$version_str" =~ ^ruby
.2 ]]; then
119 local symlink_target_dir
120 local brewcask_lib_dir
121 local brewcask_command
125 ruby_opts
=( "-W0" "-EUTF-8:UTF-8" )
127 script_dir
="$(resolve_dir "${0%/*}")"
128 ensure_dir
"$script_dir" \
129 "brew-cask: could not resolve script directory"
131 # return "." in case we are not a link
132 symlink_target
="$(/usr/bin/readlink "$0" || echo ".
")"
134 # redefine script_dir because we are likely to be a relative link
135 symlink_target_dir
="$(/usr/bin/dirname "$symlink_target")"
136 script_dir
="$(resolve_dir "$script_dir" "$symlink_target_dir")"
137 ensure_dir
"$script_dir" \
138 "brew-cask: could not resolve script directory"
140 # The Homebrew install process replaces the lib element below with rubylib
141 brewcask_lib_dir
="$(resolve_dir "$script_dir"/../lib)"
142 ensure_dir
"$brewcask_lib_dir" \
143 "brew-cask: could not resolve homebrew-cask library directory"
145 brewcask_command
="$brewcask_lib_dir/brew-cask-cmd.rb"
146 ensure_file
"$brewcask_command" \
147 "brew-cask: could not find brew-cask-cmd.rb in '$brewcask_lib_dir'"
149 interpreter
="$(find_ruby_2_plus)"
150 ensure_executable
"$interpreter" \
151 "brew-cask: could not find Ruby 2.0 or greater. Try 'brew install ruby'."
153 exec "$interpreter" "${ruby_opts[@]}" "$brewcask_command" "${@}"