Skip to content
Newer
Older
100644 99 lines (79 sloc) 2.87 KB
7d02270 @mathiasbynens Initial commit.
mathiasbynens authored
1 # Create a new directory and enter it
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
mathiasbynens authored
2 function md() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
mathiasbynens authored
3 mkdir -p "$@" && cd "$@"
7d02270 @mathiasbynens Initial commit.
mathiasbynens authored
4 }
5
d38534f @paulirish f find shorthand
authored
6
7 # find shorthand
8 function f() {
a0d5fb5 @paulirish add gz() function for gzipped size
authored
9 find . -name "$1"
d38534f @paulirish f find shorthand
authored
10 }
11
12
2df7609 bringing in my aliases/function to these dotfiles.
Paul Irish authored
13 # lets toss an image onto my server and pbcopy that bitch.
14 function scpp() {
15 scp "$1" aurgasm@aurgasm.us:~/paulirish.com/i;
16 echo "http://paulirish.com/i/$1" | pbcopy;
17 echo "Copied to clipboard: http://paulirish.com/i/$1"
18 }
19
958517d @mathiasbynens Replace the `server` alias with a function that optionally takes an a…
mathiasbynens authored
20 # Start an HTTP server from a directory, optionally specifying the port
21 function server() {
42d5c26 @mathiasbynens `server`: Use parameter expansion instead of a fake ternary
mathiasbynens authored
22 local port="${1:-8000}"
c1c05cb @mathiasbynens `server` function: Set the default Content-Type to `text/plain` inste…
mathiasbynens authored
23 open "http://localhost:${port}/"
24 # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
27c2285 @mathiasbynens `server` function: Serve everything as UTF-8
mathiasbynens authored
25 # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
26 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"
958517d @mathiasbynens Replace the `server` alias with a function that optionally takes an a…
mathiasbynens authored
27 }
28
9263775 @paulirish git log with per-commit cmd-clickable GitHub URLs via @cowboy
authored
29 # git log with per-commit cmd-clickable GitHub URLs (iTerm)
30 function gf() {
31 local remote="$(git remote -v | awk '/^origin.*\(push\)$/ {print $2}')"
32 [[ "$remote" ]] || return
33 local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')"
34 git log $* --name-status --color | awk "$(cat <<AWK
35 /^.*commit [0-9a-f]{40}/ {sha=substr(\$2,1,7)}
36 /^[MA]\t/ {printf "%s\thttps://github.com/$user_repo/blob/%s/%s\n", \$1, sha, \$2; next}
37 /.*/ {print \$0}
38 AWK
39 )" | less -F
40 }
41
42
06d129c @paulirish hot copy w/ progress from gf3.
authored
43 # Copy w/ progress
44 cp_p () {
45 rsync -WavP --human-readable --progress $1 $2
46 }
47
48
7d02270 @mathiasbynens Initial commit.
mathiasbynens authored
49 # Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.
50 # Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!)
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
mathiasbynens authored
51 function httpcompression() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
mathiasbynens authored
52 encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding"
7d02270 @mathiasbynens Initial commit.
mathiasbynens authored
53 }
54
9b0af44 @mathiasbynens Allow piping to the `json` function
mathiasbynens authored
55 # Syntax-highlight JSON strings or files
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
mathiasbynens authored
56 function json() {
9b0af44 @mathiasbynens Allow piping to the `json` function
mathiasbynens authored
57 if [ -p /dev/stdin ]; then
58 # piping, e.g. `echo '{"foo":42}' | json`
307c425 @mathiasbynens Better `json` function
mathiasbynens authored
59 python -mjson.tool | pygmentize -l javascript
9b0af44 @mathiasbynens Allow piping to the `json` function
mathiasbynens authored
60 else
61 # e.g. `json '{"foo":42}'`
62 python -mjson.tool <<< "$*" | pygmentize -l javascript
63 fi
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
mathiasbynens authored
64 }
65
a0d5fb5 @paulirish add gz() function for gzipped size
authored
66
f189fa7 @paulirish gitexport function for clean folder copy.
authored
67 # take this repo and copy it to somewhere else minus the .git stuff.
68 function gitexport(){
16fe2a7 @paulirish start up rvm
authored
69 mkdir -p "$1"
f189fa7 @paulirish gitexport function for clean folder copy.
authored
70 git archive master | tar -x -C "$1"
71 }
72
73
74
a0d5fb5 @paulirish add gz() function for gzipped size
authored
75 # get gzipped size
76 function gz() {
77 echo "orig size (bytes): "
78 cat "$1" | wc -c
79 echo "gzipped size (bytes): "
80 gzip -c "$1" | wc -c
81 }
82
7d02270 @mathiasbynens Initial commit.
mathiasbynens authored
83 # All the dig info
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
mathiasbynens authored
84 function digga() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
mathiasbynens authored
85 dig +nocmd "$1" any +multiline +noall +answer
e3c4b0e @mathiasbynens Add `escape` function which escapes UTF-8 characters into their 3-byt…
mathiasbynens authored
86 }
87
88 # Escape UTF-8 characters into their 3-byte format
89 function escape() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
mathiasbynens authored
90 printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u)
91 echo # newline
fad9536 @mathiasbynens Add `unidecode` function
mathiasbynens authored
92 }
93
94 # Decode \x{ABCD}-style Unicode escape sequences
95 function unidecode() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
mathiasbynens authored
96 perl -e "binmode(STDOUT, ':utf8'); print \"$@\""
97 echo # newline
a0d5fb5 @paulirish add gz() function for gzipped size
authored
98 }
Something went wrong with that request. Please try again.