forked from jschaedl/sphp-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphp
executable file
·55 lines (52 loc) · 1.33 KB
/
sphp
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
#!/bin/bash
# Creator: Phil Cook
# Email: [email protected]
# Twitter: @p_cook
brew_prefix=$(brew --prefix | sed 's#/#\\\/#g')
brew_array=("5.6","7.0","7.1","7.2","7.3")
php_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]" "[email protected]")
php_installed_array=()
php_version="php@$1"
php_opt_path="$brew_prefix\/opt\/"
# Has the user submitted a version required
if [[ -z "$1" ]]
then
echo "usage: sphp version"; echo;
echo " version one of:" ${brew_array[@]};
exit
fi
# What versions of php are installed via brew
for i in ${php_array[*]}
do
if [[ -n "$(brew ls --versions "$i")" ]]
then
php_installed_array+=("$i")
fi
done
# Check that the requested version is supported
if [[ " ${php_array[*]} " == *"$php_version"* ]]
then
# Check that the requested version is installed
if [[ " ${php_installed_array[*]} " == *"$php_version"* ]]
then
# Switch Shell
echo "Switching to $php_version"
echo "Switching your shell"
for i in ${php_installed_array[@]}
do
if [[ -n $(brew ls --versions $i) ]]
then
brew unlink $i
fi
done
brew link --force "$php_version"
echo ""
php -v
echo ""
echo "All done!"
else
echo "Sorry, but $php_version is not installed via brew. Install by running: brew install $php_version"
fi
else
echo "Unknown version of PHP. PHP Switcher can only handle arguments of:" ${brew_array[@]}
fi