forked from matthewmcvickar/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
28 lines (25 loc) · 1.14 KB
/
.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$@"
}
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
sleep 1 && 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"
}
# Start a PHP server from a directory, optionally specifying the port
# (Requires PHP 5.4.0+.)
function phpserver() {
local port="${1:-4000}"
local ip=$(ipconfig getifaddr en1)
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}"
}
# cd into whatever is the forefront Finder window.
# By sindresorhus, https://github.com/paulirish/dotfiles/commit/e67d1bc03
function cdf() {
cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`"
}