-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.bash_aliases
552 lines (475 loc) · 16.7 KB
/
.bash_aliases
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - $HOME/.bash_aliases
# Started On - Thu 14 Sep 13:14:36 BST 2017
# Last Change - Fri 20 Apr 09:36:44 BST 2018
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
# If you're looking for some aliases which were removed, look in the new file I
# added to keep functions and aliases separate: $HOME/.bash_functions
#
# You may need to update insit if you're installing from there, but note that this
# will of course blast away your current configurations:
#
# sudo insit -S
# sudo insit -U bashconfig
#----------------------------------------------------------------------------------
# Just in-case.
[ -z "$BASH_VERSION" ] && return 1
# Nifty trick to allow aliases to work with sudo. This avoids needing sudo in these
# configuration files, since using sudo within a bash script/program is not great.
alias sudo="sudo "
# Sick of typing this in the termanal, out of habit!
alias ":q"="exit"
if [ -x /bin/df ]; then
alias df='/bin/df -lT -x devtmpfs -x tmpfs -x usbfs'
fi
# Quick and dirty personal alias to display a random note line from command notes.
if [ -x /bin/sed -a -x /bin/grep -a -x /usr/bin/shuf ]; then
alias get-random-note='\
/bin/sed "1,/^#END/!d" $HOME/Documents/TT/Useful_Commands\
| /bin/grep -v "^#"\
| /bin/grep -v "^$"\
| /usr/bin/shuf -n 1
'
fi
# Grab a list of TODOs for git projects, per a specific method. This only works if
# you use "#T0D0 - Note message here" syntax for your TODOs, where "0" is "O". If
# you use a different style, but it's perfectly consistent, change the below match.
GIT="$HOME/GitHub/terminalforlife/Personal"
if [ -d "$GIT" -a -x /bin/grep ]; then
alias todo="\
if cd \"$GIT\"; then
/bin/grep --color=auto -R\
--exclude-dir=\".git\" \"[#\\\"]TODO - \"
cd - 2>&1 > /dev/null
fi
"
fi
# Display a list of all of the currently available font families.
if [ -x /usr/bin/fc-list ]; then
alias lsfont="/usr/bin/fc-list : family"
fi
# ???
if [ -x /usr/bin/gvfs-ls ]; then
alias lstrash="/usr/bin/gvfs-ls -h trash:///"
fi
# View the entire (17,000+ lines) VIM User Guide.
if [ -x /bin/cat -a -x /usr/bin/vim ]; then
alias vug='/bin/cat /usr/share/vim/vim74/doc/usr_*.txt | /usr/bin/vim -'
fi
# A useful file to edit, if you use the X Display Manager.
if [ -x /usr/bin/xdm -a -f /etc/X11/xdm/Xresources ]; then
alias xdm-xresources='/usr/bin/rvim /etc/X11/xdm/Xresources'
fi
# A less excessive, yet still very, very useful current-user-focused ps command.
if [ -x /bin/ps ]; then
alias ps='/bin/ps -faxc -U $UID -o pid,uid,gid,pcpu,pmem,stat,comm'
fi
# This is where I usually have the main bulk of my music, and since I like to have
# little in my $HOME, I might as well just point mplay/MOC to the one on Main Data.
if [ -x /usr/bin/mplay ]; then
alias mplay='/usr/bin/mplay /media/$USER/Main\ Data/Linux\ Generals/Music'
fi
# I'm done with the boring original apt-get output! I'm also sick of specifying
# --purge --autoremove, so I want it to be assumed! A much more useful apt-get.
if [ -x /usr/bin/apt-get ]; then
alias apt-get='\
/usr/bin/apt-get --quiet -o Dpkg::Progress=true\
-o Dpkg::Progress-Fancy=true -o APT::Get::AutomaticRemove=true\
-o APT::Get::Purge=true '
fi
# Display the current DPI setting.
if [ -x /usr/bin/xdpyinfo ]; then
alias dpi='\
while read -a X; do
if [ "${X[0]}" == "resolution:" ]; then
printf "%s\n" "${X[1]/*x}"
fi
done <<< "$(/usr/bin/xdpyinfo)"
'
fi
# Quick alias to clear out some junk from HOME.
if [ -x /bin/rm ]; then
PLACES=(\
"$HOME/.cache"
"$HOME/.thumbnails"
"$HOME/.mozilla/firefox/Crash Reports"
"$HOME/.mozilla/firefox/Pending Pings"
)
alias hsh="/bin/rm --interactive=never -rv ${PLACES[@]} 2> /dev/null"
fi
# Make the ffmpeg output less cluttered, but also ignore many errors.
[ -x /usr/bin/ffmpeg ] && alias ffmpeg="ffmpeg -v 0 -stats"
# Just points to a personal script for moving my screenshots.
if [ -f "$HOME/Documents/TT/shotmngr.sh" ]; then
alias sm="/bin/bash $HOME/Documents/TT/shotmngr.sh"
fi
# Used to notify you of a job completion on the terminal.
if [ -x /usr/bin/notify-send -a -x /usr/bin/tty ]; then
# Standard notification.
alias yo='\
/usr/bin/notify-send --urgency=normal\
"Your normal job in `/usr/bin/tty` has completed."
'
# Urgent notification.
alias YO='\
/usr/bin/notify-send --urgency=critical\
"Your critical job in `/usr/bin/tty` has completed."
'
fi
# Used to use gpicview, until I realised feh could be used as an image viewer!
if [ -x /usr/bin/feh ]; then
alias img='\
/usr/bin/feh --fullscreen --hide-pointer --draw-filename\
--no-menus --preload 2> /dev/null
'
fi
# Very useful, quick alias to scan anything you specify, if you have clamscan.
if [ -x /usr/bin/clamscan -a -x /usr/bin/tee ]; then
alias scan='\
{
printf "SCAN_START: %(%F (%X))T\n" -1
/usr/bin/clamscan --bell -r --no-summary -i\
--detect-pua=yes --detect-structured=no\
--structured-cc-count=3 --structured-ssn-count=3\
--phishing-ssl=yes --phishing-cloak=yes\
--partition-intersection=yes --detect-broken=yes\
--block-macros=yes --max-filesize=256M\
|& /usr/bin/tee -a $HOME/.scan_alias.log
} |& /usr/bin/tee -a $HOME/.scan_alias.log
'
fi
# Quickly flash the terminal and sound the bell 3 times.
if [ -x /bin/sleep ]; then
alias alertme='\
for I in {1..3}; {
/bin/sleep 0.03s
printf "\a\e[?5h"
/bin/sleep 0.03s
printf "\a\e[?5l"
}
'
fi
# Remove trailing spaces or lines with only spaces. Tabs included. Needs testing.
[ -x /bin/sed ] && alias nospace='/bin/sed -i s/^[\\s\\t]\\+$//\;\ s/[\\s\\t]\\+$//'
# Efficient and fairly portable way to display the current iface.
[ -x /sbin/ip ] && alias iface='X=(`/sbin/ip route`) && echo ${X[4]}'
# Get and display the distribution type. (original base first)
if [ -f /etc/os-release -a -r /etc/os-release ]; then
alias distro='\
while read -a X; do
if [[ "${X[0]}" == ID_LIKE=* ]]; then
echo "${X[0]/*=}"; break
elif [[ "${X[0]}" == ID=* ]]; then
echo "${X[0]/*=}"; break
fi
done < /etc/os-release
'
fi
# Quickly view all of your sd* storage device temperatures.
if [ -x /usr/sbin/hddtemp ]; then
alias temphdd='/usr/sbin/hddtemp /dev/sd{a..z} 2> /dev/null'
fi
# Quickly download with wget, using some tider settings with -c.
if [ -x /usr/bin/wget ]; then
alias get='/usr/bin/wget -qc --show-progress'
fi
# View the system boot log.
if [ -f /var/log/boot.log ]; then
alias bootlog='\
while read -r; do
printf "%s\n" "$REPLY"
done < /var/log/boot.log
'
fi
if [ -x /usr/bin/newsbeuter ]; then
# Load newsbeuter more quickly to get access to RSS feeds.
alias news='\
/usr/bin/newsbeuter -qr\
-c "$HOME/.newsbeuter/cache.db"\
-u "$HOME/.newsbeuter/urls"\
-C "$HOME/.newsbeuter/newsbeuter.conf"
'
# Quickly edit RSS feed list.
alias rss='/usr/bin/vim $HOME/.newsbeuter/urls'
fi
# Watches a directory as its size and number of files increase. Useful while you're
# downloading or making other sorts of changes to its contents, and want to watch.
if [ -x /bin/ls -a -x /usr/bin/watch ]; then
alias dwatch='\
/usr/bin/watch -n 0.1 "/bin/ls -SsCphq\
--color=auto --group-directories-first"
'
fi
# Fix all CWD file and directory permissions to match the safer 0077 umask.
if [ -x /bin/chmod ]; then
alias fixperms='\
/usr/bin/find -xdev \( -type f -exec /bin/chmod 600 "{}" \+ -o\
-type d -exec /bin/chmod 700 "{}" \+ \)\
-printf "FIXING: %p\n" 2> /dev/null
'
fi
# Create or unmount a user-only RAM Disk (tmpfs, basically) of 32MB.
if [ -x /bin/mount -a -x /bin/umount ]; then
RAMDISK="/media/$USER/RAMDisk_32M"
alias rd='\
/bin/mount -t tmpfs tmpfs\
-o x-mount.mkdir=700,uid=1000,gid=1000,mode=700,nodev\
-o noexec,nosuid,size=32M "$RAMDISK"
'
alias nord='\
/bin/sh -c /bin/umount\ "$RAMDISK"\ \&\&\ /bin/rmdir\ "$RAMDISK"
'
fi
# Show the fan speeds using sensors.
if [ -x /usr/bin/sensors ]; then
alias showfans='\
while read; do
[[ "$REPLY" == *[Ff][Aa][Nn]*RPM ]] && echo "$REPLY"
done <<< "$(/usr/bin/sensors)"
'
fi
# Display a columnized list of bash builtins.
if [ -x /usr/bin/column ]; then
alias builtins='\
while read -r; do
echo "${REPLY/* }"
done <<< "$(enable -a)" | /usr/bin/column
'
fi
# Rip audio CDs with ease, then convert to ogg, name, and tag. Change the device
# as fits your needs, same with the formats used. Needs testing.
declare -i DEPCOUNT=0
for DEP in /usr/bin/{eject,kid3,ffmpeg,cdparanoia}; {
[ -x "$DEP" ] && DEPCOUNT+=1
# Only execute if all 3 dependencies are found.
if [ $DEPCOUNT -eq 4 ]; then
alias cdrip='\
/usr/bin/cdparanoia -B 1- && {
for FILE in *; {
/usr/bin/ffmpeg -i "$FILE"\
"${FILE%.wav}.ogg" &> /dev/null
}
}
'
fi
}
# Enable a bunch of git aliases, if you have git installed.
[ -x /usr/bin/git ] && {
for CMD in\
\
"rm":grm "add":add "tag":tag "push":push "pull":pull "diff":diff\
"init":init "clone":clone "merge":merge "branch":branch\
"config":config "rm --cached":grmc "commit -m":commit\
"status -s":status "checkout":checkout "config --list":gcl\
"describe --long --tag":describe "mv":gmv;
{
alias "${CMD/*:}"="/usr/bin/git ${CMD%:*}"
}
}
# If you have gvfs-trash available, be safe with that.
[ -x /usr/bin/gvfs-trash ] && alias rm="/usr/bin/gvfs-trash"
# Ease-of-use youtube-dl aliases; these save typing!
for DEP in /usr/{local/bin,bin}/youtube-dl; {
[ -x "$DEP" ] && {
alias ytdl-video="$DEP -c --yes-playlist --sleep-interval 5\
--format best --no-call-home --console-title --quiet\
--ignore-errors"
alias ytdl-audio="$DEP -cx --audio-format mp3 --sleep-interval 5\
--max-sleep-interval 30 --no-call-home --console-title\
--quiet --ignore-errors"
alias ytpldl-audio="$DEP -cix --audio-format mp3 --sleep-interval\
5 --yes-playlist --no-call-home --console-title --quiet\
--ignore-errors"
alias ytpldl-video="$DEP -ci --yes-playlist --sleep-interval 5\
--format best --no-call-home --console-title --quiet\
--ignore-errors"
# Just use the first result.
break
}
}
# Various [q]uick apt-get aliases to make life a bit easier.
if [ -x /usr/bin/apt-get ]; then
for CMD in\
\
quf:"-qq --show-progress remove --purge"\
qufu:"-qq --show-progress remove --purge --autoremove"\
qu:"-qq --show-progress remove"\
qa:"-qq --show-progress autoremove"\
qi:"-qq --show-progress install"\
qri:"-qq --show-progress reinstall"\
qupg:"-qq --show-progress upgrade"\
qdupg:"-qq --show-progress dist-upgrade"\
qupd:"-q update"
{
alias ${CMD%:*}="/usr/bin/apt-get ${CMD/*:}"
}
fi
# Various [q]uick apt-cache aliases to make lifeeasier still.
if [ -x /usr/bin/apt-cache ]; then
for CMD in qse:"search" qsh:"show"; {
alias ${CMD%:*}="/usr/bin/apt-cache ${CMD/*:}"
}
fi
# Workaround for older versions of dd; displays progress.
declare -i DEPCOUNT=0
for DEP in /bin/{dd,pidof}; {
[ -x "$DEP" ] && DEPCOUNT+=1
[ $DEPCOUNT -gt 3 ] && {
alias ddp="kill -USR1 `/bin/pidof /bin/dd`"
}
}
# These are just options I find the most useful when using dmesg.
[ -x /bin/dmesg ] && alias klog="/bin/dmesg -t -L=never -l err,crit,alert,emerg"
# Enable the default hostkey when vboxsdl is used, if virtualbox GUI is not found.
if [ -x /usr/bin/vboxsdl -a ! -x /usr/bin/virtualbox ]; then
alias vboxsdl="/usr/bin/vboxsdl --hostkey 305 128"
fi
# Clear the clipboard using xclip.
if [ -x /usr/bin/xclip ]; then
alias ccb='\
for X in "-i" "-i -selection clipboard"; {
printf "%s" "" | /usr/bin/xclip $X
}
'
fi
# Get more functionality by default when using grep and ls.
if [ -x /bin/ls -a -x /bin/grep ]; then
case "${TERM:-EMPTY}" in
linux|xterm|xterm-256color)
alias ls="/bin/ls -nphq --time-style=iso --color=auto\
--group-directories-first --show-control-chars"
alias lsa="ls -A"
alias grep="/bin/grep --color=auto"
alias egrep="/bin/egrep --color=auto"
alias fgrep="/bin/fgrep --color=auto" ;;
esac
fi
# Quick navigation aliases in absence of the autocd shell option.
shopt -qp autocd || {
alias ~="cd $HOME"
alias ..="cd .."
}
# For each directory listed to the left of :, create an alias you see on the right
# of :. This is a key=value style approach, like dictionaries in Python. HOME only.
for DIR in\
\
"Music":mus "GitHub":gh "Videos":vid "Desktop":dt "Pictures":pic\
"Downloads":dl "Documents":doc "Documents/TT":tt "ShellPlugins":sp\
"GitHub/terminalforlife":ghtfl "GitHub/terminalforlife/Forks":ghtflf\
"GitHub/terminalforlife/Personal":ghtflp "DosBox":db "Archives":arc\
".i3a":i3a "LearnLinux":ll;
{
[ -d "$HOME/${DIR%:*}" ] && alias ${DIR/*:}="cd $HOME/${DIR%:*}"
}
# When dealing with udisksctl or mount, these are very useful!
[ -d "/media/$USER" ] && alias sd="cd /media/$USER" || alias mnt="cd /mnt"
# For each found "sr" device, enables alias for opening and closing the tray. For
# example, use ot0 to specific you want the tray for /dev/sr0 to open. Testing for
# /dev/sr0 to ensure at least the one device is available, to avoid errors.
if [ -x /usr/bin/eject -a -b /dev/sr0 ]; then
for DEV in /dev/sr[0-9]*; {
alias ot${DEV/\/dev\/sr}="/usr/bin/eject $DEV"
alias ct${DEV/\/dev\/sr}="/usr/bin/eject -t $DEV"
}
fi
# These aliases save a lot of typing and do away with the output.
if [ -x /usr/bin/mplayer ]; then
# If you're having issues with mpv/mplayer here, try -vo x11 instead.
MPLAYER_FONT="$HOME/.mplayer/subfont.ttf"
alias mpa="/usr/bin/mplayer -nolirc -vo null -really-quiet &> /dev/null"
if [ -f "$MPLAYER_FONT" ]; then
alias mpv="/usr/bin/mplayer -vo x11 -nomouseinput -noar\
-nojoystick -nogui -zoom -nolirc -font \"$MPLAYER_FONT\"\
-really-quiet &> /dev/null"
alias mpvdvd="/usr/bin/mplayer -vo x11 -nomouseinput -noar\
-nojoystick -nogui -zoom -nolirc -font \"$MPLAYER_FONT\"\
-really-quiet dvd://1//dev/sr1 &> /dev/null"
else
alias mpv="/usr/bin/mplayer -vo x11 -nomouseinput -noar\
-nojoystick -nogui -zoom -nolirc -really-quiet\
&> /dev/null &> /dev/null"
alias mpvdvd="/usr/bin/mplayer -vo x11 -nomouseinput -noar\
-nojoystick -nogui -zoom -nolirc --really-quiet\
dvd://1//dev/sr1 &> /dev/null"
fi
elif [ -x /usr/bin/mpv ]; then
alias mpve="\
/usr/bin/mpv --af=equalizer=8:7:6:5:0:6:0:5:5:5\
--no-stop-screensaver &> /dev/null \
"
alias mpv="\
/usr/bin/mpv --no-stop-screensaver &> /dev/null \
"
fi
# A more descriptive, yet concise lsblk; you'll miss it when it's gone.
if [ -x /bin/lsblk ]; then
alias lsblkid='\
/bin/lsblk -o name,label,fstype,size,uuid,mountpoint --noheadings
'
fi
# Some options I like to have by default for less and pager.
if [ -x /usr/bin/pager -o -x /usr/bin/less ]; then
alias pager='/usr/bin/pager -sN --tilde'
alias less='/usr/bin/pager -sN --tilde'
fi
# Text files I occasionally like to view, but not edit.
if [ -x /usr/bin/pager ]; then
for FILE in\
\
"/var/log/apt/history.log":aptlog\
"$HOME/Documents/TT/python/Module\ Index.txt":pymodindex;
{
{ [ -f "${FILE%:*}" ] && [ -r "${FILE%:*}" ]; } && {
alias ${FILE/*:}="/usr/bin/pager ${FILE%:*}"
}
}
fi
if [ -x /usr/bin/vim ]; then
# Many files I often edit; usually configuration files.
for FILE in\
\
".zshrc":zshrc ".vimrc":vimrc ".bashrc":bashrc ".conkyrc":conkyrc\
".profile":profile ".i3bbelow":i3b1 ".i3babove":i3b2\
".config/i3/config":i3c "bin/maintain":maintain-sh\
".bash_aliases":bashaliases ".config/compton.conf":compconf\
"Documents/TT/Useful_Commands":cn "i3blocks1.conf":i3cb1\
"Documents/TT/python/Useful_Commands.py":cnp\
".maintain/changelog.txt":maintain-cl ".xbindkeysrc":xbkrc\
".maintain/maintain.man":maintain-man ".config/openbox/rc.xml":obc\
".maintain/usersettings.conf":maintain-set ".wgetrc":wgetrc\
".dosbox/dosbox-0.74.conf":dbc ".bash_functions":bashfunctions\
".libi3bview":li3bv;
{
[ -f "$HOME/${FILE%:*}" ] || continue
alias ${FILE/*:}="/usr/bin/vim $HOME/${FILE%:*}"
}
# As above, but for those which need root privileges.
for FILE in\
\
"/etc/hosts":hosts "/etc/fstab":fstab "/etc/modules":modules\
"/etc/pam.d/login":pamlogin "/etc/bash.bashrc":bash.bashrc\
"$HOME/bin/maintain":maintain-sh\
"/etc/X11/default-display-manager":ddm\
"/etc/X11/default-display-manager":defdm\
"/etc/modprobe.d/blacklist.conf":blacklist
{
[ -f "${FILE%:*}" ] || continue
alias ${FILE/*:}="/usr/bin/rvim ${FILE%:*}"
}
fi
# When in a TTY, change to different ones.
if [[ `/usr/bin/tty` == /dev/tty* ]] && [ -x /usr/bin/tty -a -x /bin/chvt ]; then
for TTY in {1..12}; {
alias $TTY="chvt $TTY"
}
fi
if [ -x /usr/bin/evince ]; then
alias pdf="/usr/bin/evince &> /dev/null"
fi
# Clean up functions and variables.
unset -f FOR_THE_EDITOR
unset DEP FILE DEPCOUNT FOR_THE_EDITOR TTDIR DIR CHOSEN_EDITOR GIT
# vim: noexpandtab colorcolumn=84 tabstop=8 noswapfile nobackup