-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
51 lines (45 loc) · 1.8 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# vim: set ft=sh:
#
# Shell Aliases
#
tinit() {
terraform init -upgrade=true
}
# Check if we forget the colon on scp
scp() {
if [[ "$@" =~ : ]]; then
/usr/bin/scp $@;
else
2>&1 echo "ERROR: scp: missing colon";
fi
}
# Build a gitignore file for project
# See https://www.gitignore.io/
gitignore() {
curl --location --show-error --silent "https://www.gitignore.io/api/$@";
}
# Create a data URL from a file
# Adapted from https://github.com/mathiasbynens/dotfiles/blob/master/.functions
dataurl() {
local mimeType=$(file -b --mime-type "$1");
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8";
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
}
# Start an HTTP server from a directory, optionally specifying the port
# Adapted from https://github.com/mathiasbynens/dotfiles/blob/master/.functions
server() {
local port="${1:-8000}";
# 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";
}
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
# Adapted from https://github.com/mathiasbynens/dotfiles/blob/master/.functions
tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}