-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
99 lines (70 loc) · 1.7 KB
/
functions.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
prohibit-subshells
include() {
# Source the file, if it exists
test -f "$1" && source "$1" || true
}
include-all() {
# Source all files in a directory
# shopt -s nullglob
for f in "$1"/*; do source "$f"; done
}
exists() {
# Check if the command(s) exist(s)
type "$@" >/dev/null 2>&1
}
maybe() {
# Execute the command, if it exists.
exists "$1" && "$@"
}
try() {
# Execute the command without erroring.
"$@" || true
}
take() {
# mkdir, then cd into it. Surprisingly useful.
mkdir -p "$1"
cd "$1"
}
tktemp() {
# Create a tempdir, then cd into it.
name="${1:-temp}"
now="$(date -u +%FT%TZ)"
cd "$(mktemp -d "$name-$now-XXX")"
}
-() {
# cd to previous directory
cd -
}
# Make the `-` function work in a fresh shell.
# (This is usually what I want to do.)
OLDPWD=~
v() {
# "View"
less "$@"
}
vv() {
# View the command's stdout and stderr in less.
# Don't preprocess with pygmentize or other syntax highlighter,
# since it will likely not work. (Also it's slow.)
"$@" 2>&1 | less --no-lessopen
}
mergeout() {
# Run the command, merging stderr to stdout.
# Also consider `|&` (pipe both stdout and stderr)
# (bash only; not available in sh)
"$@" 2>&1
}
background() {
# Start a background process, ignoring stdout and stderr
"$@" > /dev/null 2>&1 &
}
clean-shell() {
# Open a subshell without inheriting env vars (-i),
# and without sourcing .bashrc or .bash_profile.
# Set TERM=xterm because programs like less complain if you don't.
env -i TERM=xterm "$SHELL" --norc --noprofile
}
icloud() {
cd "$HOME/Library/Mobile Documents/com~apple~CloudDocs"
}
alias ic=icloud