forked from phpbrew/phpbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpbrew.sh
92 lines (84 loc) · 1.92 KB
/
phpbrew.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
[[ -z "$PHPBREW_ROOT" ]] && export PHPBREW_ROOT="$HOME/.phpbrew"
[[ -z "$PHPBREW_HOME" ]] && export PHPBREW_HOME="$HOME/.phpbrew"
if [[ ! -n "$PHPBREW_SKIP_INIT" ]]; then
if [[ -f "$PHPBREW_HOME/init" ]]; then
. "$PHPBREW_HOME/init"
fi
fi
function phpbrew () {
BIN='scripts/phpbrew.php'
local exit_status
local short_option
export SHELL
if [[ `echo $1 | awk 'BEGIN{FS=""}{print $1}'` = '-' ]]
then
short_option=$1
shift
else
short_option=""
fi
case $1 in
(use) if [[ -z "$2" ]]
then
if [[ -z "$PHPBREW_PHP" ]]
then
echo "Currently using system perl"
else
echo "Currently using $PHPBREW_PHP"
fi
else
code=$(command $BIN env $2)
if [ -z "$code" ]
then
exit_status=1
else
eval $code
__phpbrew_set_path
fi
fi ;;
(switch)
if [[ -z "$2" ]]
then
command $BIN switch
else
$BIN use $2
__phpbrew_reinit $2
fi ;;
(off)
unset PHPBREW_PHP
eval `$BIN env`
__phpbrew_set_path
echo "phpbrew is turned off." ;;
(switch-off)
unset PHPBREW_PHP
__phpbrew_reinit
echo "phpbrew is switched off." ;;
(*) command $BIN $short_option "$@"
exit_status=$? ;;
esac
hash -r
return ${exit_status:-0}
}
function __phpbrew_set_path () {
[[ -n $(alias perl 2>/dev/null) ]] && unalias perl 2> /dev/null
if [[ -n $PHPBREW_ROOT ]] ; then
export PATH_WITHOUT_PHPBREW=$(perl -e 'print join ":", grep { index($_,$ENV{PHPBREW_ROOT}) } split/:/,$ENV{PATH};')
fi
if [[ -z "$PHPBREW_PATH" ]]
then
export PHPBREW_PATH="$PHPBREW_ROOT/bin"
fi
export PATH=$PHPBREW_PATH:$PATH_WITHOUT_PHPBREW
# echo "PATH => $PATH"
}
function __phpbrew_reinit () {
if [[ ! -d "$PHPBREW_HOME" ]]
then
mkdir -p -p "$PHPBREW_HOME"
fi
echo '# DO NOT EDIT THIS FILE' >| "$PHPBREW_HOME/init"
command $BIN env $1 >> "$PHPBREW_HOME/init"
. "$PHPBREW_HOME/init"
__phpbrew_set_path
}