-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalias
More file actions
455 lines (399 loc) · 15 KB
/
Copy pathalias
File metadata and controls
455 lines (399 loc) · 15 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/bin/sh
# Helper functions {{{1
# NOTE: these are unset at the end of the file
#
# have {{{2
#
# @description Check PATH for a command
#
# @arg $1 str Command to search for
#
# @exitcode true if found
# @exitcode false if not found
#
have() { command -v "$1" >/dev/null; }
# grc(1)-only aliases {{{1
#
# This block creates aliases that do nothing more than add grc coloring. Aliases
# that do more but also want grc coloring should be defined outside this block
# and use the $grc variable which will be empty if grc is not installed
#
unset grc
if have grc; then
# shellcheck disable=SC2016
grc='grc $GRC_OPTS'
# Defining this alias first allows 'grc' to expand everyehwere in this file
# So 'alias foo='grc foo' will become 'alias foo='<$grc value> foo'
alias grc="$grc"
# Create alias for all configs found *if* the command exists
for c in /usr/share/grc/conf.* ~/.grc/conf.*; do
c=${c##*/}; c=${c#conf.} # extract command name
have "$c" && alias "$c=grc $c"
done
# Get .grc conf directory
unset grc_dir
for d in \
"${XDG_CONFIG_HOME:-"$HOME/.config"}/grc" \
"$HOME/.grc" \
; do
if [ -d "$d" ]; then
grc_dir=$d/
break
fi
done
# Create additional aliases or modify auto-generated ones as needed
#
# - $HOME is interpreted **now** so the alias works with sudo, even
# if the command doesn't actually need sudo
# - stdbuf is used for commands that don't do line-buffering through a pipe
alias getsebool="grc getsebool"
alias go='grc go' # for conf.go-test
alias lastb="grc --config ${grc_dir}conf.last lastb"
alias lastlog="grc --config ${grc_dir}conf.lastlog lastlog" # override /etc/grc.conf
alias make='grc make' # uses conf.gcc
alias ping="grc --config ${grc_dir}conf.ping stdbuf -oL ping"
alias printenv="grc --config ${grc_dir}conf.printenv printenv" # grc picks the wrong config
alias semanage="grc semanage"
alias tcpdump="grc --config ${grc_dir}conf.tcpdump tcpdump -l"
alias who='grc who'
# The confirmation prompt when installing packages does not
# display and dnf already does decent coloring on its own
unalias dnf
fi
# ls(1) {{{1
#
# In case $LS was not defined in ~/.env
[ -z "$LS" ] && LS=ls
ls=$LS
# Use GNU options if available
[ "$ls" = ls ] && command ls --version 2>/dev/null | grep -q GNU && ls=gnu-ls
case $ls in
eza | exa)
ls_opts=''; ll_opts='-lg';
la_opts='-a'; lla_opts='-lag';
ld_opts='-d'; lld_opts='-lgd';
ldot_opts='-d .*'; lldot_opts='-lgd .*';
;;
gnu-ls) # GNU ls
ls_opts=''; ll_opts='-l';
la_opts='-A'; lla_opts='-lA';
ld_opts='-d'; lld_opts='-ld'
ldot_opts='-d .*'; lldot_opts='-ld .*';
;;
ls) # POSIX ls
ls_opts=''; ll_opts='-l';
la_opts='-a'; lla_opts='-la';
ld_opts='-d'; lld_opts='-lgd';
ldot_opts='-d .*'; lldot_opts='-lgd .*';
;;
*) printf 'How did we get here?\n' >&2 ;;
esac
# Force color if using grc with an ls that supports color
#
# This function is only needed for aliases that may add grc.
# Other aliases can use LS_OPTS directly
if have grc && [ -n "$HAS_COLOR" ] && [ "$ls" != 'ls' ]; then
_LS_OPTS() { printf %s "$LS_OPTS" | sed 's/--color=auto/--color=always/'; }
else
_LS_OPTS() { printf %s "$LS_OPTS"; }
fi
# shellcheck disable=SC2153
alias ls="$LS $ls_opts "'$LS_OPTS'
alias ll="${grc:+grc }$LS $ll_opts "'$(_LS_OPTS)'
alias ld="$LS $ld_opts "'$LS_OPTS'
alias lld="${grc:+grc }$LS $lld_opts "'$(_LS_OPTS)'
alias la="$LS $la_opts "'$LS_OPTS'
alias lla="${grc:+grc }$LS $lla_opts "'$(_LS_OPTS)'
alias l.="$LS $ldot_opts "'$LS_OPTS'
alias ll.="${grc:+grc }$LS $lldot_opts "'$(_LS_OPTS)'
# grc and LS_OPTS are handled in the lsp function
alias lp="lsp $ll_opts"
alias lpd="lsp $lld_opts"
alias lpa="lsp $lla_opts"
alias lp.="lsp $lldot_opts"
unset ls ls_opts la_opts ll_opts lla_opts ld_opts lld_opts ldot_opts lldot_opts ldap_opts
# cd {{{1
#
alias ..='cd ..' # up one directory
alias ...='cd ../..' # up two directories
alias ${BASH:+--} -='cd -' # cd to previous directory
# X-specific {{{1
#
if [ -n "$DISPLAY" ]; then
# force using vimx so Vim can access the system clipboard
if have vimx; then
alias vim=vimx
alias vi=vimx
fi
fi
# OS-specific {{{1
#
case $(uname -o 2>/dev/null || uname -v) in
*) ;;
esac
# Alternatives {{{1
#
alias term='( $(my terminal)& )'
alias calc='( $(my calculator)& )'
alias calendar='( $(my calendar)& )'
# Cassowary {{{1
#
if have cassowary; then
alias word='cassowary -c guest-run winword'
alias excel='cassowary -c guest-run excel'
alias ppt='cassowary -c guest-run powerpnt'
alias mspub='cassowary -c guest-run mspub'
alias onenote='cassowary -c guest-run onenote'
alias access='cassowary -c guest-run msaccess'
fi
# PAGER / cat {{{1
#
# - less / zless calls $PAGER
# - syntax highlight cat if possible (depends on *_STYLE variables)
#
case $PAGER in
vimpager)
alias less='vimpager'
alias zless='vimpager'
alias cat='vimcat' ;;
bat)
alias less='bat -p -pager less'
alias zless='bat -p -pager less'
alias cat='bat -p --paging never' ;;
*)
if [ "$PAGER" != less ]; then
alias less="$PAGER"
alias zless="$PAGER"
else
# NOTE: Manually pass $LESS as less is not automatically
# using it for some reason
alias less='less $LESS'
alias zless='less $LESS'
fi
if have highlight || have bat || have pygmentize; then
if have highlight; then
_docat() { highlight --force -O truecolor --style "${HIGHLIGHT_STYLE:-solarized-dark}" "$@"; }
elif have bat; then
_docat() { bat --decorations never --paging never "$@"; }
elif have pygmentize; then
_docat() { pygmentize -O style="${PYGMENTIZE_STYLE:-solarized-light}" -g "$@"; }
fi
cat() {
# Use cat(1) if no files are given or if redirecting stdout
# (avoid colors)
if [ $# -eq 0 ] || ! [ -t 1 ]; then
/bin/cat "$@"
else
# If stdout is the terminal, use highlight but loop through
# $@ so it works properly
for _a in "$@"; do
# Emulate cat(1) ENOENT error message
if ! [ -r "$_a" ]; then
printf '/bin/cat: %s: No such file or directory\n' "$_a" >&2
continue
fi
_docat "$_a"
done
fi
}
fi ;;
esac
# Get public IP & ipinfo.io{{{1
#
ipurl=ipv4.icanhazip.com
infourl=ipinfo.io
if have curl; then
alias myip="curl $ipurl"
alias ipinfo="curl $infourl; echo"
elif have wget; then
alias myip="wget $ipurl -O - -q"
alias ipinfo="wget $infourl -O - -q; echo"
else
alias myip='printf "wget or curl not available\n"'
alias ipinfo='printf "wget or curl not available\n"'
fi
unset ipurl infourl
# tmux {{{1
#
if [ -n "$TMUX" ]; then
# tmux popups
alias tcal='tmux-popup -k -w23 -h27 "cal -3"'
alias ttop='tmux-popup htop'
alias wttr='tmux-popup -k -w127 -h43 "curl wttr.in"'
alias net='tmux-popup -w80 -h40 nmtui'
alias wgsh='tmux-popup -k -w80 -h25 "sudo wg show"'
fi
# Vim & Ex {{{1
#
alias minpac_clean='vim +PackCleanAndQuit' # remove old plugins
alias minpac_update='vim +PackUpdateAndQuit' # add and update plugins
alias minpac_status='vim +PackStatus +only' # show plugin status
alias gist='vim "+Gist -l"' # open Gist browser
alias trim='ex +"bufdo! %s/\s\+$//e" -scxa' # trim trailing whitespace
# Trash can {{{1
#
# Aliases {{{2
#
# tm : move to trash
# tl : list trash contents
# tu : restore file
# trm : delete from trash
# tempty : empty trash
# tinfo : summary of trash can contents
# tui : restore files using TUI (gtrash only)
# tuig : restore groups of files using TUI (gtrash only)
#
if have gtrash; then # {{{3
alias tm='gtrash put'
alias tl='gtrash find'
alias tu='gtrash find --restore'
alias trm='gtrash find --rm'
alias tempty='gtrash find --rm'
alias tinfo='gtrash summary'
# gtrash doesn't need this
unset _tinfo
alias tui='gtrash restore'
alias tuig='gtrash restore-group'
elif have trash-d; then # {{{3
alias tm='trash-d --recursive --force'
alias tl='trash-d --list'
alias tu='trash-d --recursive --restore'
alias trm='trash-d --recursive --delete'
alias tempty='trash-d --empty'
alias tinfo=_tinfo
elif have trash-put; then # {{{3
alias tm='trash-put -f'
alias tl=trash-list
alias tu=trash-restore
alias trm=trash-rm
alias tempty=trash-empty
alias tinfo=_tinfo
elif have gio; then # {{{3
alias tm='gio trash -f'
alias tl='gio trash --list'
alias tu='_tu'
alias trm='echo "'\''trm'\'' not implemented" >&2; false'
alias tempty='gio trash --empty'
alias tinfo=_tinfo
_tu() { gio trash --restore "trash:///$1"; }
fi
# Disable rm {{{3
alias tm >/dev/null && \
alias rm='printf "'\''rm'\'' disabled. Use '\''tm'\'' or '\''\\\rm'\''.\n" >&2; false'
# Emulate 'gtrash summary' if gtrash is not installed {{{2
#
# Requires bc and numfmt
_tinfo() {
# User trash can
cans=$XDG_DATA_HOME/Trash/files
# Look for user trash cans on other mountpoints, skipping places where
# one really should not exist
for topdir in $(command df --output=target |
sed -r '1d; /^\/$/d; /^\/\<(dev|sys|run|boot|home)\>/d'); do
can="$topdir/.Trash-$(id -u)"
[ -d "$can" ] && cans="$cans $can/files"
done
# Print summary for each trash can
count_total=0
size_total=0
for can in $cans; do
count=$(find "$can" -type f | wc -l)
# Use find to print file sizes with + appended (echo 0 finishes off
# the equation) and then add them
size=$( (find "$can" -type f -printf '%s+'; echo 0) | bc)
count_total=$((count_total + count))
size_total=$((size_total + size))
printf '[%s]\n' "$(printf %s "$can" | sed 's@/files$@@')"
printf 'item: %s\n' "$count"
printf 'size: %s\n' "$(numfmt --to=iec "$size" | sed 's/K/ kB/; s/M/ MB/')"
echo
done
printf '[total]\n'
printf 'item: %s\n' "$count_total"
printf 'size: %s\n' "$(numfmt --to=iec "$size_total" | sed 's/K/ kB/; s/M/ MB/')"
}
# Miscellaneous {{{1
#
have reset || alias reset='tput sgr0' # reset terminal
have clear || alias clear='tput clear' # emulate clear(1) if I don't have it
alias cls='clear' # windows clear
have buku && alias b='buku --suggest' # easier buku
have mgitstatus && alias gits='mgitstatus -e -c' # get status of git repos
have dunst && alias huh='dunstctl history-pop' # Show previous desktop notifications
have locate && alias loc='locate -d "$LOCATEDB"' # use my personal locate(1) db
have colormake && alias make='colormake' # use colormake
have pandoc && alias md2html='pandoc -f markdown' # convert Markdown to HTML
have rpg-cli && alias rpg='rpg-cli' # easier rpg-cli
have dict && alias thesaurus='dict -d "moby-thesaurus"' # A...thesaurus
alias +x='chmod +x' # make file executable
alias ${BASH:+--} -x='chmod -x' # make file non-executable
alias :q='exit' # exit like it's vim
alias :e='vim' # edit a file like it's vim
alias bell='printf "\a"' # ring the bell
alias nu="who | cut -d' ' -f1 | uniq | wc -l" # get number of logged on users
alias r='fc -s' # ^old^new but global (r pat=rep)
alias sudo='sudo ' # enable aliases to be sudo’ed
alias tree='command tree -CFI ".git" --dirsfirst' # better looking tree(1)
alias unexec='find . -type f -exec chmod ogu-x "{}" \;' # chmod -x all FILES in tree (needed when copying from Windows)
# Force color in *grep
alias grep="grep ${HAS_COLOR:+--color=auto}"
alias fgrep="grep -F ${HAS_COLOR:+--color=auto}"
alias egrep="grep -E ${HAS_COLOR:+--color=auto}"
alias zgrep="zgrep ${HAS_COLOR:+--color=auto}"
alias zfgrep="zfgrep ${HAS_COLOR:+--color=auto}"
alias zegrep="zegrep ${HAS_COLOR:+--color=auto}"
alias xzgrep="xzgrep ${HAS_COLOR:+--color=auto}"
alias xzfgrep="xzfgrep ${HAS_COLOR:+--color=auto}"
alias xzegrep="xzegrep ${HAS_COLOR:+--color=auto}"
# Search through aliases, functions and $PATH. Taken from /etc/profile.d/which2.sh
[ -n "$BASH" ] &&
alias which='(alias; declare -f) | /usr/bin/which --read-alias --read-functions'
# It would be nice if telnet had something like ssh configs
alias rcbb='telnet realitycheckbbs.org -l "Jeremy Brubaker"'
# Show my Nerd Test result
alias nerd='feh https://www.nerdtests.com/images/badge/nt2/$NERDTEST_ID.png'
# start / stop a local-only ssh server
if have sshd && [ -n "$LOCAL_SSHD_CONFIG" ]; then
# start and stop a local ssh server
alias lsshd='/usr/sbin/sshd -f "$LOCAL_SSHD_CONFIG"'
alias klsshd='/bin/kill -TERM $(command cat $(sshd -f "$LOCAL_SSHD_CONFIG" -T | grep pidfile | cut -d" " -f2))'
fi
if have todo.sh; then
todo_alias=t
alias "$todo_alias=todo.sh"
# Used to setup bash completion in ~/.bashrc
[ -n "$BASH_VERSION" ] && export todo_alias
fi
[ -d "$XDG_DATA_HOME/make/make-tools" ] && \
alias mkvenv="make -f $XDG_DATA_HOME/make/make-tools/venv.mk"
# Use grc(1) if available {{{1
#
# The ${grc:+...} construction is to avoid needless spaces
# at the front of the alias if $grc is not defined
#
alias df="${grc:+grc }df -hT" # human-readable is better
alias du="${grc:+grc }du -h" # human-readable is better
alias du0="${grc:+grc }du -h --summarize" # top-level summary
alias du1="${grc:+grc }du -h --max-depth=1" # one-level summary
alias free="${grc:+grc }free -h" # human-readable is better
# Add a blank line after uptime
# Truncate at $COLUMNS (roughly because of color escapes)
alias w="${grc:+grc --colour on }w | sed 1G | colrm "'$COLUMNS'
# list PIDs
# jobs has to run in the current shell
alias jobs="jobs -l${grc:+${BASH:+ | grcat conf.jobs}}"
# grep removes loopback
# sed removes IPv6 addresses
alias ipa="${grc:+grc --config ${grc_dir}conf.ipaddr --colour on }\
ip --color=always --brief address \
| grep -v '\blo\b' \
| sed 's@[0-9a-f]*:[0-9a-f]*.[0-9]*@@g; s/[[:space:]]*$//'"
alias configure="${grc:+grc }./configure"
# Load aliases for things installed in ~/opt {{{1
#
[ -r "$HOME/opt/alias" ] && . "$HOME/opt/alias"
# Cleanup {{{1
#
unset grc grc_dir
unset have
# vim: ft=sh foldlevel=0