Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save adriancmiranda/d51f0f7ef18ddec24fcc to your computer and use it in GitHub Desktop.

Select an option

Save adriancmiranda/d51f0f7ef18ddec24fcc to your computer and use it in GitHub Desktop.
launcher
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