Created
October 16, 2012 14:42
-
-
Save joyrexus/3899714 to your computer and use it in GitHub Desktop.
Shell function for managing a simple HTTP server
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
# Manage a simple HTTP server | |
# | |
# Usage: | |
# http start|stop|restart [port] | |
# | |
# Notes: | |
# Add to .bashrc and resource (source ~/.bashrc) | |
http () { | |
local port="${2:-8000}" | |
case $1 in | |
"start") | |
echo "starting http server" | |
nohup python -m SimpleHTTPServer >| /tmp/nohup.out & | |
open "http://localhost:${port}/" | |
;; | |
"stop") | |
echo "stopping http server" | |
kill $(ps aux | grep "python -m SimpleHTTPServer" \ | |
| grep -v grep \ | |
| awk '{print $2}') > /dev/null | |
;; | |
"restart") | |
echo "restarting http server" | |
kill $(ps aux | grep "python -m SimpleHTTPServer" \ | |
| grep -v grep | awk '{print $2}') > /dev/null | |
nohup python -m SimpleHTTPServer >| /tmp/nohup.out & | |
;; | |
*) | |
echo "need start|stop|restart" | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you