-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivate.sh
More file actions
executable file
·45 lines (35 loc) · 1.19 KB
/
activate.sh
File metadata and controls
executable file
·45 lines (35 loc) · 1.19 KB
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
# Set up by sourcing in your .bash_profile or similar.
php-version() {
this_dir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
php_build_dir="$this_dir/php-build"
# Usage: php-version <version>
# This script assumes that the php version is already built in ./php-build/<version>
case "$1" in
list|ls|--list)
ls "$php_build_dir"
return 0
;;
*)
esac
if [ -z "$1" ]; then
php_executable_path="$(command -v php)"
echo "Active: $php_executable_path"
echo "Available:"
ls "$php_build_dir"
return 0
fi
version_id="$1"
version_dir="$php_build_dir/$version_id"
echo "Activating php living at $version_dir/"
bin_dir="$version_dir/bin"
if [ -x "$bin_dir/php" ]; then
PATH="$bin_dir:$PATH"
# Trim duplicate entries from PATH (see: https://sites.google.com/site/jdisnard/path-dupes)
PATH=`awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s:",$i); }}' <<< $PATH`
echo "PHP version $version_id is active."
else
echo " !! $bin_dir/php must exist and be executable !! "
return 1
fi
}