-
Notifications
You must be signed in to change notification settings - Fork 0
/
.commonrc
309 lines (252 loc) · 8.59 KB
/
.commonrc
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
# Common RC config for bash and zsh
################################################################################
# Setting the PATH in commonrc (unlike in a profile) allows to quickly update
# PATH for all new shells. However if done naively, the path might grow
# uncontrollably. To avoid this, the path_prepend/path_append functions shall
# be used.
# See: https://unix.stackexchange.com/a/32054
path_prepend() {
case :"$PATH": in
*:"$1":*) ;;
*) PATH="$1":"$PATH" ;;
esac
}
path_append() {
case :"$PATH": in
*:"$1":*) ;;
*) PATH="$PATH":"$1" ;;
esac
}
path_prepend "$HOME"/.local/bin
export PATH
unset -f path_prepend
unset -f path_append
export EDITOR="vim"
if [ -x "$(command -v nvim)" ]; then
export EDITOR="nvim"
alias vim='nvim'
alias vimdiff='nvim -d'
fi
# Clear screen like real men do. (http://stackoverflow.com/a/5367075)
# This has been working with all terminals I've used so far, unlike clear.
# Note: M-C-l (ctrl-alt-L) available OotB since bash 5.1,
# cf. https://unix.stackexchange.com/a/664538
alias cls='printf \\ec'
alias here='(nautilus . 1>/dev/null 2>&1 &)'
alias rst='cd ~; reset'
alias tn='konami ping -c1 google.com'
alias open='xdg-open'
alias top='if type -p htop >/dev/null; then htop; else top; fi'
alias :q='exit'
alias myip='curl ipinfo.io/ip'
alias vimr='vim -R'
alias n='vimr -'
alias m='less'
alias mpa='mpv --no-video --mute=no --msg-level=ffmpeg=no'
alias dla='yt-dlp -f bestaudio -x --add-metadata --embed-thumbnail'
alias diff='colordiff' # requires colordiff package
alias grep='grep --color=auto'
alias df='df -h'
alias du='du -c -h'
alias du1='du --max-depth=1'
alias fdu='2>/dev/null /bin/du -Phx --max-depth 1'
alias mkdir='mkdir -p -v'
alias tmpcd='cd $(mktemp -d)'
alias ping='ping -c 5'
alias tree='tree -CF'
alias openports='netstat --all --numeric --programs --inet --inet6'
# ls
eval $(dircolors) # Color setup for ls
alias ls='ls -hF --color=auto'
alias lsa='ls -A'
alias lr='ls -R' # recursive ls
alias ll='ls -l'
alias la='ll -A'
alias lla='ll -A'
alias lx='ll -BX' # sort by extension
alias lz='ll -rS' # sort by size
alias lt='ll -rt' # sort by date
alias lm='la | more'
alias lsg='ls | grep -i'
alias llg='ll | grep -i'
# safety features
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -I' # 'rm -i' prompts for every file
alias ln='ln -i'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
# pacman aliases (if applicable, replace 'pacman' with your favorite AUR helper)
alias pac="pacman -S" # default action - install one or more packages
alias pacu="pacman -Syu" # '[u]pdate' - upgrade all packages to their newest version
alias pacs="pacman -Ss" # '[s]earch' - search for a package using one or more keywords
alias paci="pacman -Si" # '[i]nfo' - show information about a package
alias pacr="pacman -R" # '[r]emove' - uninstall one or more packages
alias pacl="pacman -Sl" # '[l]ist' - list all packages of a repository
alias pacll="pacman -Qqm" # '[l]ist [l]ocal' - list all packages which were locally installed (e.g. AUR packages)
alias paclo="pacman -Qdt" # '[l]ist [o]rphans' - list all packages which are orphaned
alias paco="pacman -Qo" # '[o]wner' - determine which package owns a given file
alias pacf="pacman -Ql" # '[f]iles' - list all files installed by a given package
alias pacc="pacman -Sc" # '[c]lean cache' - delete all not currently installed package files
alias pacm="makepkg -fci" # '[m]ake' - make package from PKGBUILD file in current directory
bak() {
mv -T "$1" "$1".bak
}
unbak() {
mv -T "$1" "${1%.bak}"
}
# Read rendered markdown files in the shell
markup() {
markdown "$1" | w3m -T text/html
}
# Display colorized information output
cinfo() {
printf '\033[01;33m%s\033[00;00m\n' "$@"
}
# Display colorized warning output
cwarn() {
printf '\033[01;31m%s\033[00;00m\n' "$@"
}
# Outputs a message about the number of packages ignored by Pacman
pkgblklst() {
cf='/etc/pacman.conf'
ip="$(cat $cf | grep -E '^[^#]*IgnorePkg\s*=' | sed 's/IgnorePkg\s*=\s*//' | sed 's/#.*//')"
if [ $ip ]; then
nr="$(echo $ip | wc -w)"
cwarn ":: $nr ignored packages in $cf"
echo " $ip"
fi
}
# Extracts a wide range of compressed files by extension
# source: https://wiki.archlinux.org/index.php/Bash#Functions
# Alternatives: unp, atool, dtrx
extract() {
local file cmd errs
# If called without arguments, prints help and exits.
(($#)) || {
>&2 echo 'Extracts a wide range of compressed files.'
>&2 echo 'Alternatives: atool, unp, dtrx.'
>&2 echo
>&2 echo 'Usage:'
>&2 echo " $0 FILE..."
return 1
}
for file; do
if [[ ! -r "$file" ]]; then
echo "$0: file is unreadable: \`$file'" >&2
errs+=1
continue
fi
case "$file" in
*.tgz|*.tlz|*.txz|*.tb2|*.tbz|*.tbz2|*.taz|\
*.tar|*.tar.Z|*.tar.bz|*.tar.bz2|*.tar.gz|*.tar.lzma|*.tar.xz)
cmd='bsdtar xvf';;
*.7z) cmd='7z x';;
*.Z) cmd='uncompress';;
*.bz2) cmd='bunzip2';;
*.exe) cmd='cabextract';;
*.gz) cmd='gunzip';;
*.rar) cmd='unrar x';;
*.xz) cmd='unxz';;
*.zip) cmd='unzip';;
*) >&2 echo "$0: unrecognized file extension: \`$file'"
errs+=1
continue;;
esac
command $cmd "$file"
errs+=$?
done
! ((errs))
}
# Colorized manpages
man() {
# The LESS_TERMCAP_* variables are used by `less` for colorization.
# If `less` is not the default pager, then they won't matter.
# `tput` outputs control chars used for formatting.
env \
LESS_TERMCAP_mb=$(tput bold; tput setaf 1) \
LESS_TERMCAP_md=$(tput bold; tput setaf 74) \
LESS_TERMCAP_me=$(tput sgr0) \
LESS_TERMCAP_so=$(tput smso; tput setaf 241; tput setab 177) \
LESS_TERMCAP_se=$(tput rmso; tput sgr0) \
LESS_TERMCAP_us=$(tput smul; tput setaf 146) \
LESS_TERMCAP_ue=$(tput rmul; tput sgr0) \
LESS_TERMCAP_mr=$(tput rev) \
LESS_TERMCAP_mg=$(tput dim) \
LESS_TERMCAP_ZN=$(tput ssubm) \
LESS_TERMCAP_ZV=$(tput rsubm) \
LESS_TERMCAP_ZO=$(tput ssupm) \
LESS_TERMCAP_ZW=$(tput rsupm) \
man "$@"
}
### §aliases ###################################################################
alias §§='cls'
alias §u='pkgblklst; pikaur -Syu'
alias §is='pikaur -Ss'
alias §i='pikaur -S'
alias §ir='pikaur -Rs'
alias §d='sudo systemctl'
alias §rg='nohup gnome-shell -d :0 -r &'
alias §-='r | less'
# Like `pwd` but also resolves symlinks
§() {
local p pP
p="$(pwd)"
pP="$(pwd -P)"
echo "$p"
[ "$p" != "$pP" ] && printf ' ↳ %s\n' "$pP"
}
# Stuff I never remember when I need it
§sysinfo() {
cat <<'EOF'
Use the following command to gather information about the system:
lscpu
List available cpus and their caracteristics
Not available on older distribution
lshw
Available on Debian and Ubuntu based distributions by default
Available in the Fedora repositories
Uses many inputs to detect all hardware: Kernel, HAL, DMI, etc.
As a neat ‘-html’ switch that generates hardware reports
lspci
Standard command
List all hardware connected to the PCI bus as detected by the kernel
lsusb
Standard command
List all hardware connected to the USB buses as detected by the kernel
dmidecode
Standard command
Get the source information from the DMI (a kind of BIOS interface)
List all hardware as reported by the DMI interface
uname -a
Show kernel version and system architecture
andhead -n1 /etc/issue
Show name and version of distribution
cat /proc/partitions
Show all partitions registered on the system
grep MemTotal /proc/meminfo
Show RAM total seen by the system
grep "model name" /proc/cpuinfo
Show CPU(s) info
lspci -tv
Show PCI info
lsusb -tv
Show USB info
mount | column -t
List mounted filesystems on theire system (and align output)
dmidecode -q | less
Display SMBIOS/DMI information
smartctl -A /dev/sda | grep Power_On_Hours
How long has this disk (system) been powered on in total
hdparm -i /dev/sda
Show info about disk sda
hdparm -tT /dev/sda
Do a read speed test on disk sda
badblocks -s /dev/sda
Test for unreadable blocks on disk sda
Other neat tools and commands at:
http://superuser.com/questions/303981/what-is-the-linux-command-to-find-out-hardware-info
http://www.pixelbeat.org/cmdline.html
EOF
}