Last active
December 16, 2015 22:49
-
-
Save rygood/5510237 to your computer and use it in GitHub Desktop.
PHP & Nginx function wrappers for simple start, stop, restart. PHP assumes it was installed with brew.NEW: Added sudo support for nginxIMPROVED: Better argument passthroughExamples:php startphp restartphp stopnginx startnginx restartnginx stopnginx edit # opens nginx.conf for editting with Sublime Text 2nginx edit vim # opens nginx.conf for edit…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Path | |
PATH=/usr/local/bin:/usr/local/sbin:$PATH | |
# Wrapper for simple PHP start, stop, & restart | |
function php { | |
if [[ $1 == 'start' ]]; then | |
if [[ $2 == 'php54' ]]; then | |
launchctl unload -w `brew --prefix php55`/homebrew.mxcl.php55.plist | |
formulaeArr=(`brew list | grep php54`) | |
brew unlink php55 | |
# for formulae in ${formulaeArr[*]}; do | |
# echo -e "$formulae" | |
# brew link --overwrite $formulae | |
# done | |
brew link --overwrite php54 | |
launchctl load -w `brew --prefix php54`/homebrew.mxcl.php54.plist | |
elif [[ $2 == 'php55' ]]; then | |
launchctl unload -w `brew --prefix php54`/homebrew.mxcl.php54.plist | |
brew unlink php54 | |
formulaeArr=(`brew list | grep php55`) | |
# for formulae in ${formulaeArr[*]}; do | |
# echo -e "$formulae" | |
# brew link --overwrite $formulae | |
# done | |
brew link --overwrite php55 | |
launchctl load -w `brew --prefix php55`/homebrew.mxcl.php55.plist | |
else | |
echo -e "Invalid argument - '${2}'" | |
echo -e "Please pass either 'php54' or 'php55' as your second argument" | |
fi | |
elif [[ $1 == 'stop' ]]; then | |
if [[ $2 == 'php54' ]]; then | |
launchctl unload -w `brew --prefix php54`/homebrew.mxcl.php54.plist | |
formulaeArr=(`brew list | grep php54`) | |
# for formulae in ${formulaeArr[*]}; do | |
# echo -e "$formulae" | |
# brew unlink --overwrite $formulae | |
# done | |
elif [[ $2 == 'php55' ]]; then | |
launchctl unload -w `brew --prefix php55`/homebrew.mxcl.php55.plist | |
formulaeArr=(`brew list | grep php55`) | |
# for formulae in ${formulaeArr[*]}; do | |
# echo -e "$formulae" | |
# brew unlink --overwrite $formulae | |
# done | |
else | |
echo -e "Invalid argument - '${2}'" | |
echo -e "Please pass either 'php54' or 'php55' as your second argument" | |
fi | |
elif [[ $1 == 'restart' ]]; then | |
php stop && php start | |
else | |
`which php` ${@:1} | |
fi | |
} | |
# Wrapper for simple Nginx start, stop, & restart | |
# Edit assumes you Sublime Text 2 'subl' command installed | |
function nginx { | |
if [[ $1 == 'start' ]]; then | |
`which nginx` | |
elif [[ $1 == 'stop' ]]; then | |
`which nginx` -s stop | |
elif [[ $1 == 'restart' ]]; then | |
`which nginx` -s reload | |
elif [[ $1 == 'edit' ]]; then | |
if [[ $2 == 'vim' ]]; then | |
`which vim` `brew --prefix`/etc/nginx/nginx.conf | |
elif [[ $2 == 'emacs' ]]; then | |
`which emacs` `brew --prefix`/etc/nginx/nginx.conf | |
else | |
subl `brew --prefix`/etc/nginx/nginx.conf | |
fi | |
else | |
`which nginx` ${@:1} | |
fi | |
} | |
# Sudo Version | |
# Wrapper for simple Nginx start, stop, & restart | |
function sudo { | |
if [[ ($1 == 'nginx') && ($2 == 'stop') ]]; then | |
`which sudo` `which nginx` -s stop | |
elif [[ ($1 == 'nginx') && ($2 == 'restart') ]]; then | |
`which sudo` `which nginx` -s reload | |
elif [[ ($1 == 'nginx') && ($# -eq 1) ]]; then | |
`which sudo` `which nginx` | |
else | |
`which sudo` ${@:1} | |
fi | |
} | |
# simple edit command | |
# Currently only support the .bash_profile | |
# Edit assumes you Sublime Text 2 'subl' command installed | |
function edit { | |
if [[ $1 == 'profile' ]]; then | |
if [[ $2 == 'vim' ]]; then | |
`which vim` ~/.bash_profile | |
elif [[ $2 == 'emacs' ]]; then | |
`which emacs` ~/.bash_profile | |
else | |
subl ~/.bash_profile | |
fi | |
else | |
echo -e "Invalid argument - '${1}'" | |
echo -e "Please pass 'profile' as your first argument" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment