Skip to content

Commit 3399fe0

Browse files
committed
Carpe Diem
0 parents  commit 3399fe0

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Enforce Unix newlines
2+
* text=lf
3+
4+
# Exclude unused files
5+
# see: https://redd.it/2jzp6k
6+
/.gitignore export-ignore
7+
/README.md export-ignore

.gitignore

Whitespace-only changes.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# PHP Switcher for Mac
2+
3+
===
4+
5+
## Pre requisits
6+
7+
- Homebrew
8+
- PHP installed through brew (7.1, 7.2 and 7.3)
9+
10+
```bash
11+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
12+
```
13+
14+
```bash
15+
brew install php@7.3
16+
brew install php@7.2
17+
brew install php@7.1
18+
```
19+
20+
Starth the services
21+
22+
```
23+
brew services start php
24+
brew services start php@7.2
25+
brew services start php@7.1
26+
```
27+
28+
## Instrunctions
29+
30+
- In your `.bash_profile` file create a variable called `PHP_HOME`
31+
- Export the path: `export PATH=$PHP_HOME/bin:$PATH`
32+
- Give the script execution permissions and then move it to you bin folther so you can execute it as a global command.
33+
34+
```bash
35+
chmod +x sphp.sh
36+
mv sphp.sh /usr/local/bin/sphp
37+
```
38+
39+
## Usage
40+
41+
```bash
42+
sphp 7.2
43+
```

src/sphp.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# @author adro
3+
echo "🍺 php switcher for Mac 🍺"
4+
version=$1
5+
if [[ "7.1" != $version && "7.2" != $version && "7.3" != $version && "0" != $version ]]
6+
then
7+
echo "You must specify php version (7.3, 7.2, 7.1, 7.0 or 5.6)"
8+
exit 1
9+
else
10+
if [[ "0" != $version ]]
11+
then
12+
echo "> Preparing to load php $version"
13+
fi
14+
fi
15+
function unload_php {
16+
echo "> Unloading current php version"
17+
brew unlink php@7.3 > /dev/null
18+
brew unlink php@7.2 > /dev/null
19+
brew unlink php@7.1 > /dev/null
20+
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php.plist 2> /dev/null
21+
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php@7.2.plist 2> /dev/null
22+
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php@7.1.plist 2> /dev/null
23+
}
24+
function load_php {
25+
echo "> Loading desired php version"
26+
brew link php@$1 --force > /dev/null
27+
if [[ "7.3" != $1 ]]
28+
then
29+
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php@$1.plist
30+
else
31+
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php.plist
32+
fi
33+
sed -i '' 's;^PHP_HOME=.*;PHP_HOME='"$(brew --prefix php@$1)/bin"';' ~/.bash_profile
34+
source ~/.bash_profile
35+
echo "> "`php -v | head -n 1`" Loaded"
36+
}
37+
unload_php
38+
if [[ "0" != $version ]]
39+
then
40+
load_php $version
41+
fi

0 commit comments

Comments
 (0)