Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 146 lines (131 sloc) 3.985 kB
7d02270 @mathiasbynens Initial commit.
authored
1 # Create a new directory and enter it
3bf5166 @vaxXxa .functions: Rename `md` to `mkd` now that OS X 10.8 has an utility na…
vaxXxa authored
2 function mkd() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
authored
3 mkdir -p "$@" && cd "$@"
7d02270 @mathiasbynens Initial commit.
authored
4 }
5
1b7314b @porada .functions: Add `fs`
porada authored
6 # Determine size of a file or total size of a directory
7 function fs() {
0e6b837 @porada .functions: Tweak `fs`
porada authored
8 if du -b /dev/null > /dev/null 2>&1; then
1b7314b @porada .functions: Add `fs`
porada authored
9 local arg=-sbh
10 else
0e6b837 @porada .functions: Tweak `fs`
porada authored
11 local arg=-sh
1b7314b @porada .functions: Add `fs`
porada authored
12 fi
13 if [[ -n "$@" ]]; then
14 du $arg -- "$@"
15 else
16 du $arg .[^.]* *
17 fi
18 }
19
c93d113 @mathiasbynens .functions: Alias `diff` to `git diff` when available
authored
20 # Use Git’s colored diff when available
21 hash git &>/dev/null
22 if [ $? -eq 0 ]; then
23 function diff() {
24 git diff --no-index --color-words "$@"
25 }
26 fi
27
5d76fc2 @alrra .functions: Make `dataurl` more generic
alrra authored
28 # Create a data URL from a file
29 function dataurl() {
acfad0c @mathiasbynens .functions: Optimize `dataurl`
authored
30 local mimeType=$(file -b --mime-type "$1")
5d76fc2 @alrra .functions: Make `dataurl` more generic
alrra authored
31 if [[ $mimeType == text/* ]]; then
32 mimeType="${mimeType};charset=utf-8"
33 fi
34 echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"
36666d6 @mathiasbynens .functions: Add `dataurl` function
authored
35 }
36
958517d @mathiasbynens Replace the `server` alias with a function that optionally takes an a…
authored
37 # Start an HTTP server from a directory, optionally specifying the port
38 function server() {
42d5c26 @mathiasbynens `server`: Use parameter expansion instead of a fake ternary
authored
39 local port="${1:-8000}"
c03c541 @mathiasbynens .functions: Attempt to make `server` open the browser *after* the ser…
authored
40 sleep 1 && open "http://localhost:${port}/" &
c1c05cb @mathiasbynens `server` function: Set the default Content-Type to `text/plain` inste…
authored
41 # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
27c2285 @mathiasbynens `server` function: Serve everything as UTF-8
authored
42 # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
43 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…
authored
44 }
45
378fa5b @sindresorhus .functions: Add `phpserver`
sindresorhus authored
46 # Start a PHP server from a directory, optionally specifying the port
47 # (Requires PHP 5.4.0+.)
48 function phpserver() {
49 local port="${1:-4000}"
50 local ip=$(ipconfig getifaddr en1)
aff769f @nvartolomei .bash_profile: Update `killall` Tab completion for OS X 10.8
nvartolomei authored
51 sleep 1 && open "http://${ip}:${port}/" &
378fa5b @sindresorhus .functions: Add `phpserver`
sindresorhus authored
52 php -S "${ip}:${port}"
53 }
54
a9942ac @paulirish .functions: Add `gz` function to get gzipped file size
paulirish authored
55 # Get gzipped file size
56 function gz() {
57 echo "orig size (bytes): "
58 cat "$1" | wc -c
59 echo "gzipped size (bytes): "
60 gzip -c "$1" | wc -c
61 }
62
7d02270 @mathiasbynens Initial commit.
authored
63 # Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.
64 # 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…
authored
65 function httpcompression() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
authored
66 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.
authored
67 }
68
9b0af44 @mathiasbynens Allow piping to the `json` function
authored
69 # Syntax-highlight JSON strings or files
8ed0257 @sindresorhus .functions: Add `note` and `remind`
sindresorhus authored
70 # Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
authored
71 function json() {
8ed0257 @sindresorhus .functions: Add `note` and `remind`
sindresorhus authored
72 if [ -t 0 ]; then # argument
9b0af44 @mathiasbynens Allow piping to the `json` function
authored
73 python -mjson.tool <<< "$*" | pygmentize -l javascript
8ed0257 @sindresorhus .functions: Add `note` and `remind`
sindresorhus authored
74 else # pipe
75 python -mjson.tool | pygmentize -l javascript
9b0af44 @mathiasbynens Allow piping to the `json` function
authored
76 fi
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
authored
77 }
78
7d02270 @mathiasbynens Initial commit.
authored
79 # All the dig info
6117c55 @mathiasbynens Add `json` function. Example usage: `json http://fronteers.nl/congres…
authored
80 function digga() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
authored
81 dig +nocmd "$1" any +multiline +noall +answer
e3c4b0e @mathiasbynens Add `escape` function which escapes UTF-8 characters into their 3-byt…
authored
82 }
83
84 # Escape UTF-8 characters into their 3-byte format
85 function escape() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
authored
86 printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u)
87 echo # newline
fad9536 @mathiasbynens Add `unidecode` function
authored
88 }
89
90 # Decode \x{ABCD}-style Unicode escape sequences
91 function unidecode() {
6b75bfc @mathiasbynens Use tabs instead of double-space indents
authored
92 perl -e "binmode(STDOUT, ':utf8'); print \"$@\""
93 echo # newline
b705157 @pkruithof Added codepoint function
pkruithof authored
94 }
95
2a7a7c0 @mathiasbynens .functions: Minor comment tweaks
authored
96 # Get a character’s Unicode code point
b705157 @pkruithof Added codepoint function
pkruithof authored
97 function codepoint() {
a514cb3 @pkruithof Added newline after codepoint
pkruithof authored
98 perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))"
99 echo # newline
3d918ef @mathiasbynens .functions: Add `unquarantine` which force-removes a downloaded app o…
authored
100 }
101
8ed0257 @sindresorhus .functions: Add `note` and `remind`
sindresorhus authored
102 # Add note to Notes.app (OS X 10.8)
103 # Usage: `note 'foo'` or `echo 'foo' | note`
104 function note() {
105 local text
106 if [ -t 0 ]; then # argument
107 text="$1"
108 else # pipe
109 text=$(cat)
110 fi
111 body=$(echo "$text" | sed -E 's|$|<br>|g')
112 osascript >/dev/null <<EOF
113 tell application "Notes"
114 tell account "iCloud"
115 tell folder "Notes"
116 make new note with properties {name:"$text", body:"$body"}
117 end tell
118 end tell
119 end tell
120 EOF
121 }
122
123 # Add reminder to Reminders.app (OS X 10.8)
124 # Usage: `remind 'foo'` or `echo 'foo' | remind`
125 function remind() {
126 local text
127 if [ -t 0 ]; then
128 text="$1" # argument
129 else
130 text=$(cat) # pipe
131 fi
132 osascript >/dev/null <<EOF
133 tell application "Reminders"
134 tell the default list
135 make new reminder with properties {name:"$text"}
136 end tell
137 end tell
138 EOF
139 }
140
3d918ef @mathiasbynens .functions: Add `unquarantine` which force-removes a downloaded app o…
authored
141 # Manually remove a downloaded app or file from the quarantine
142 function unquarantine() {
143 for attribute in com.apple.metadata:kMDItemDownloadedDate com.apple.metadata:kMDItemWhereFroms com.apple.quarantine; do
144 xattr -r -d "$attribute" "$@"
145 done
df229c4 @mathiasbynens Whitespace cleanup.
authored
146 }
Something went wrong with that request. Please try again.