-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc_include
85 lines (73 loc) · 3.27 KB
/
.bashrc_include
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# borrowed from https://github.com/mathiasbynens/dotfiles
alias ll="ls -al"
# Enable aliases to be sudo’ed
alias sudo='sudo '
# Trim new lines and copy to clipboard
alias c="tr -d '\n' | pbcopy"
# Recursively delete `.DS_Store` files
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en0 || ipconfig getifaddr en1" # fixme
alias lip='localip'
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# prints path to app
function whichapp() {
local appNameOrBundleId=$1 isAppName=0 bundleId
[[ $appNameOrBundleId =~ \.[aA][pP][pP]$ || $appNameOrBundleId =~ ^[^.]+$ ]] && isAppName=1
if (( isAppName )); then
bundleId=$(osascript -e "id of application \"$appNameOrBundleId\"" 2>/dev/null) ||
{ echo "$FUNCNAME: ERROR: Application with specified name not found: $appNameOrBundleId" 1>&2; return 1; }
else
bundleId=$appNameOrBundleId
fi
osascript -e "tell application \"Finder\" to POSIX path of (get application file id \"$bundleId\" as alias)" 2>/dev/null ||
{ echo "$FUNCNAME: ERROR: Application with specified bundle ID not found: $bundleId" 1>&2; return 1; }
}
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# Change working directory to the top-most Finder window location
function cdf() { # short for `cdfinder`
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# 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";
# `python3 -m http.server $port` does not support `host` binding and keeps prompting in MacOS
# so use `python3 http_server.py -b localhost` instead
# python3 -m http.server $port
# python3 "$FRITXBASH_PATH/http_server.py" $port -b localhost
# python3 "$FRITXBASH_PATH/http_server_with_symlinks.py" $port # wip...
# defaults: port=3000, hostname=localhost
# https://github.com/vercel/serve
local port="${1:-3000}";
(sleep 1 && open "http://localhost:${port}/") &
serve -p $port --symlinks
}
# `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.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}