Bash: simple Python server alias.

This commit is contained in:
Artem Sapegin 2013-02-24 23:24:07 +04:00
parent bbe34619e6
commit 2571fc7f08
1 changed files with 14 additions and 0 deletions

View File

@ -276,6 +276,20 @@ end tell
EOF
}
# Start an HTTP server from a directory, optionally specifying the port (default: 8000)
# Usage: server [port]
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesnt break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
function sayit() {
pbpaste | say
}
# Add special aliases that will copy result to clipboard (escape → escape+)
for cmd in password hex2hsl hex2rgb escape codepoint; do
eval "function $cmd+() { $cmd \$@ | c; }"