forked from postmodern/chruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchruby-exec
executable file
·45 lines (35 loc) · 868 Bytes
/
chruby-exec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
chruby_sh="${0%/*}/../share/chruby/chruby.sh"
source "$chruby_sh"
case "$1" in
-h|--help)
echo "usage: chruby-exec RUBY [RUBYOPTS] -- COMMAND [ARGS...]"
exit
;;
-V|--version)
echo "chruby version $CHRUBY_VERSION"
exit
;;
esac
if (( $# == 0 )); then
echo "chruby-exec: RUBY and COMMAND required" >&2
exit 1
fi
argv=()
for arg in "$@"; do
shift
if [[ "$arg" == "--" ]]; then break
else argv+=($arg)
fi
done
if (( $# == 0 )); then
echo "chruby-exec: COMMAND required" >&2
exit 1
fi
shell_opts=("-l")
[[ -t 0 ]] && shell_opts+=("-i")
source_command="command -v chruby >/dev/null || source $chruby_sh"
chruby_command="chruby $(printf "%q " "${argv[@]}")"
sub_command="$(printf "%q " "$@")"
command="$source_command; $chruby_command && $sub_command"
exec "$SHELL" "${shell_opts[@]}" -c "$command"