-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaliases.sh
273 lines (194 loc) · 8.33 KB
/
aliases.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# Shorthand
alias ..='cd ..'
alias L='l -tr'
alias l='LC_COLLATE=C ls -alh'
alias p='pwd'
alias c="printf '\033[2J\033[3J\033[H\033c'"
alias t='run-tests'
# Git shorthand
have git && {
alias ga='git add --all'
alias gb='git branch -av --color=always'
alias gc='git gc && git prune -v'
alias gd='git diff --cached'
alias gh='gh-clone'
alias gl='git log'
alias gp='git push'
alias gr='git remote --verbose'
alias gs='git show'
alias fd='git clean -fd'
alias PS='git commit --amend'
alias yeah='git reset HEAD .;'
alias nah='git checkout -- . && git clean -fd'
alias G='g --ignored'
}
# Program defaults
alias bc='bc -l'
alias df='df -h'
alias du='du -h'
alias mv='mv -i'
alias cp='cp -i'
alias scp='scp -pr'
alias nl='nl -ba'
# Aliases for programs that mightn't be available/installed
have bundle && alias brake='LANG=en_AU.UTF-8 bundle exec rake'
have fdupes && alias dedupe='fdupes -dN'
have file && alias mime='file --brief --mime-type'
have fs_usage && alias fs_usage='sudo fs_usage -w'
have mysql && alias mysql='mysql --auto-vertical-output'
have plutil && alias pl='convert-plist'
have sudo && alias sudo='sudo '
have doas && alias doas='doas '
have less && alias ll='l | less'
have xq && alias xq='xq --tab --indent=4'
have exiftool && {
alias stripmeta='exiftool -All= -overwrite_original'
alias x='exiftool -a -U'
alias X='x -b -X'
}
# Programs known by other names on other systems
have pbcopy || { alias pbcopy=clip; alias pbpaste=clip; }
have sudo && ! have doas && alias doas=sudo
# Recursively search for a pattern in current working directory
alias s=~/.files/bin/rgrep
(cd ~/.files/bin && echo . | grep -r . 2>&1)>/dev/null && alias s='grep -irn . -e'
# Enable coloured grep output if supported
(echo . | grep . --colour=auto 2>&1)>/dev/null && {
alias grep='grep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias egrep='egrep --colour=auto'
};
# Hide summary lines in tree(1) output
have tree && if tree -a --noreport ~/.files/share >/dev/null 2>&1
then alias tree='tree -a --noreport'; alias bush='tree -spugDF --metafirst --timefmt="%Y-%m-%d %T"'
else alias tree='tree -as'
fi
# Hide GNU bc(1)'s startup message
(echo quit | bc --quiet 2>&1)>/dev/null && alias bc='bc --quiet -l'
# Prefer GNU units(1) over the older BSD-licensed version
have gunits && alias units='gunits'
# Prefer authentic vi(1) implementations over Vim's symlinks
have nvi && (vi --version | grep -iq VIM 2>&1)>/dev/null && alias vi=nvi
have nex && (ex --version | grep -iq VIM 2>&1)>/dev/null && alias ex=nex
# Ksh: Emulate Bash's history expansion
case ${SHELL##*/} in ksh)
alias !!='`history | tail -n1 | cut -f2 | tee /dev/stderr`';;
esac
# Use libarchive's `bsdtar' to shim missing extraction commands
have bsdtar && {
have untar || alias untar='bsdtar -xf'
have unzip || alias unzip='bsdtar -xf'
}
# Shortcut to start window manager (ignored if it's running)
[ "$DISPLAY" ] || have startxfce4 && alias desktop='startxfce4'
# Display bytes 0—255 in terminal's current encoding
have jot && alias ansi='jot -ns '\'\'' -c 256 0 | { [ -t 1 ] && LANG=C fold -bw16 && echo || tee; }'
# Copy a hard tab (U+0009) to the system's clipboard
alias tab='printf "\t" | clip'
# Chop leading or trailing blank lines from input
alias trimstart='sed -n $'"'"'/[^ \t]/,$p'"'"
alias trimend='sed -e :a -e '"'"'/^\n*$/{$d;N;};/\n$/ba'"'"
# Delete broken symlinks in the current directory
alias prune='find -L . -name . -o -type d -prune -o -type l -exec rm -v {} +'
# List files with at least one hard-link
alias hardlinks='find . \! -type d \! -links 1'
# Transliterate non-ASCII characters to their nearest ASCII equivalents
have uconv && alias asciify='uconv -x ":: Any-Latin; :: Latin-ASCII; [:^ASCII:] > \\_"'
# Copy the last command to the clipboard. Useful for saving helpful one-liners.
alias copythat='printf %s "$(history | tail -2 | head -1 | sed s/^[[:space:]]*[[:digit:]]*[[:space:]]*//)" | clip'
# Copy a JavaScript one-liner for listing globals. Sometimes needed when running certain REPLs.
fn='var pp = x => Object.getOwnPropertyNames(x).concat(Object.getOwnPropertySymbols(x))'
alias pp='printf %s '\'"$fn"'.map(n => String(n)).sort().join("\n"); pp(globalThis)'\'' | clip'
unset fn
# Order-of-operations check. Runs clipboard contents through Terser to reveal which brackets are unnecessary.
have terser && alias ooc='clip | sed '\''s/^[^=]*$/_=&/'\'' | terser -mc'
# Irrevocably annihilate a file
have shred && alias nuke='shred -u' || alias nuke='rm -rfP'
# Bring up notes for things I keep forgetting
alias notes='less ~/.files/share/doc/reminders.md'
# Codepoint and base conversion
for fn in chr oct hex; do alias "$fn"="perl -E 'say join $/, map $fn, -t ? @ARGV : map split, <>'"; done;
alias ord='perl -mEncode=decode -E "map { printf \"%1\\\$s\tU+%1\\\$X\n\", ord decode \"UTF-8\", \$_ } -t ? @ARGV : map split, <>"'
unset fn
# Print public IP address
alias myip='dig +short myip.opendns.com @resolver1.opendns.com'
# Generate nicer-looking hexadecimal dumps
have xxd && alias xxd='NO_COLOR=1 xxd -u -g1'
have hexdump && alias hexdump='hexdump -v \
-e \""[2m│[22m0x%08.8_ax[2m│[22m "\" \
-e '\''16/1 "%02X "'\'' \
-e \"" [2m│[22m"\" \
-e '\''16/1 "%_p" "'\''"[2m│[22m"'\''\n"'\'
# OS-specific
# shellcheck disable=SC3009,SC2139
case `uname -s` in
OpenBSD)
# Reconnect WiFi
alias reconnect='doas sh /etc/netstart iwn0'
# Turn off the computer after shutting down
alias halt='halt -p'
# Print temperature diagnostics
alias temp='sysctl hw.sensors | grep temp | sed "s/hw.sensors.//; s/\.temp[0-9]=/: /;"'
# Mount USB stick
alias usb='mount -t msdos /dev/sd"`(mount | grep -q /dev/sd2) && echo 3 || echo 2`"i /mnt'
# macOS-specific aliases that creep into muscle memory
alias bi='pkg_info'
have nvi || alias nvi='vi'
have nex || alias nex='ex'
# Shims for missing/non-portable commands
have sudo || alias sudo='doas'
have unlink || alias unlink='rm'
# Run the following commands as superuser by default
for fn in cdio ch{own,grp,mod} {,u}mount pkg_{add,delete} syspatch mount.exfat{,-fuse}; do
have "$fn" && alias "$fn"="doas $fn"
done; unset fn
;;
Darwin)
# Update installed Homebrew formulae
alias bup='brew update && brew upgrade && brew cleanup --prune=all -s'
# Run livecheck for `alhadis/troff` tap
alias blc='brew livecheck -q --newer-only --tap alhadis/troff'
# Display information about Homebrew formulae
alias bi='brew info'
alias bd='brew desc'
# Archive macOS-specific filesystem attributes
have bsdtar && alias bsdtar='bsdtar --acls --fflags --xattrs --mac-metadata'
# Store download URLs in extended file attributes
have wget && alias wget='wget --xattr'
# Resize Terminal.app to fill the screen
alias fit='printf '\''\e[3;0;0t\e[4;0;9999t'\'
alias FIT='for i in /dev/ttys???; do fit > "$i"; done'
# Preview a file using Quick Look
alias peek='qlmanage -p >/dev/null 2>&1'
# Print temperature diagnostics
alias temp='sudo powermetrics --samplers smc -i1 -n1 | grep --colour=none "^Fan\|temp"'
# Print power diagnostics (battery-level and charge status)
alias pow='pmset -g batt'
# Apple recommend diskutil(1) be used instead of umount(1)
alias umount='diskutil unmount'
# Remove annoying extended attributes added to downloads
alias unquarantine='xattr -d com.apple.quarantine * 2>/dev/null || true'
# Locate an “.app” bundle by ID
alias findapp='mdfind "kMDItemContentType = com.apple.application-bundle && kMDItemCFBundleIdentifier ="'
# Print UTIs (Uniform Type Identifiers)
alias uti='mdls -name kMDItemContentType -name kMDItemContentTypeTree -name kMDItemKind'
# Print 4-character creator/type codes
have GetFileInfo && {
alias typecode='GetFileInfo -t'
alias creatorcode='GetFileInfo -c'
}
# Alias unreachable commands specific to macOS
for cmd in \
~/.files/etc/darwin/{open*.scpt,*.sh} \
/usr/libexec/PlistBuddy \
/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport \
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \
; do
fn="${cmd##*/}"; fn="${fn%.*}"
have "$fn" || [ -x "$cmd" ] && alias "$fn"="$cmd"
unset fn
done; unset cmd
# Mount temporary case-sensitive filesystem
alias tempfs='hdiutil create -size 512m -fs "Case-sensitive APFS" -type UDIF -nospotlight -attach'
;;
esac