From 2571fc7f085db08a40c9740e74b8eb97eb6e424b Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Sun, 24 Feb 2013 23:24:07 +0400 Subject: [PATCH] Bash: simple Python server alias. --- includes/bash_functions.bash | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/bash_functions.bash b/includes/bash_functions.bash index da59f5c..e48aff1 100644 --- a/includes/bash_functions.bash +++ b/includes/bash_functions.bash @@ -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 doesn’t 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; }"