This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dotfiles/bash/functions
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17 lines (15 sloc)
787 Bytes
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
# Start an HTTP server from a directory, optionally specifying the port | |
function pyserver() { | |
# Get port (if specified) | |
local port="${1:-8000}" | |
# Open in the browser | |
open "http://localhost:${port}/" | |
# Redefining the default content-type to text/plain instead of the default | |
# application/octet-stream allows "unknown" files to be viewable in-browser | |
# as text instead of being downloaded. | |
# | |
# Unfortunately, "python -m SimpleHTTPServer" doesn't allow you to redefine | |
# the default content-type, but the SimpleHTTPServer module can be executed | |
# manually with just a few lines of code. | |
python -c $'import SimpleHTTPServer;\nSimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map[""] = "text/plain";\nSimpleHTTPServer.test();' "$port" | |
} |