Last active
August 29, 2015 14:19
-
-
Save adriancmiranda/d51f0f7ef18ddec24fcc to your computer and use it in GitHub Desktop.
launcher
This file contains hidden or 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
| alias iplocal="echo $(ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1' | sed "1 d" | head -n1)"; | |
| function localhost() { | |
| local WORKSPACE=$HOME/Sites; | |
| local LOCALHOST="$(iplocal)"; | |
| local DIRECTORY=$(pwd); | |
| local PORT='^[0-9]+$'; | |
| if [[ -z $LOCALHOST ]]; then | |
| LOCALHOST='localhost'; | |
| fi | |
| LOCALHOST="http://$LOCALHOST/~$USER"; | |
| if [[ $1 =~ $PORT ]]; then | |
| # Launch a local web server from specific port | |
| open "http://localhost:$1/~$USER"; | |
| elif [ `echo "$DIRECTORY" | grep -o "$WORKSPACE.*"` ]; then | |
| # Launch a local web server from workspace | |
| AMBIENT=`echo "$DIRECTORY" | sed 's,'"$WORKSPACE"','"$LOCALHOST"','`; | |
| open "$AMBIENT/$1"; | |
| else | |
| # Launch a local web server from a directory if isn't workspace folder | |
| python -m SimpleHTTPServer 8080 &> /dev/null & | |
| open http://localhost:8080/; | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment