-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bash_aliases
161 lines (142 loc) · 5.13 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
unalias -a
alias bye='true && exit'
alias cpreprocess='gcc -E -x c - | command grep -Fv "#" | clang-format -style="{ColumnLimit: 119}" | bat -l c'
alias c++preprocess='gcc -E -x c++ - | command grep -Fv "#" | clang-format -style="{ColumnLimit: 119}" | bat -l c'
alias d='diff -ad -W $COLUMNS -y --suppress-common-lines'
alias g='gvim'
alias less='command less -i'
alias perfstat='perf stat -e task-clock,cycles,instructions,branches,branch-misses,cache-references,cache-misses '
alias pgrep='command pgrep -il'
alias ps='command ps a -c'
alias time=$'/usr/bin/time -f "\n\e[3mReal %e s · User %U s · Kernel %S s · MRSS %M KiB · %P CPU · %c ICS · %w VCS\e[m" '
alias valgrind='command valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose '
alias x='xdg-open'
alias f='watch -n 1 "command grep -F MHz /proc/cpuinfo | nl -n rz -w 2 | sort -k 5 -gr | sed s/^0/\ /g"'
alias htop='command htop -d 10 -t -u $USER'
alias m='watch -d -n 1 free -ht'
alias s='watch -d -n 1 sensors'
alias top='command top -d 1 -H -u $USER'
alias l='command ls -lNX --color=auto --group-directories-first'
alias la='command ls -AhlNX --color=auto --group-directories-first'
alias ls='command ls -C --color=auto'
alias lt='command ls -AhlNrt --color=auto'
alias egrep='command grep -En --binary-files=without-match --color=auto'
alias fgrep='command grep -Fn --binary-files=without-match --color=auto'
alias grep='command grep -n --binary-files=without-match --color=auto'
if command -v batcat &>/dev/null
then
alias bat='batcat'
alias cat='batcat'
elif command -v bat &>/dev/null
then
alias cat='bat'
fi
alias json.tool='python3 -m json.tool --indent=2 --no-ensure-ascii --sort-keys | bat -l json --style=plain'
alias p='python3 -B'
alias pip='python3 -m pip'
alias timeit='python3 -m timeit'
alias L="$HOME/.bash_hacks.py L"
alias P="$HOME/.bash_hacks.py P"
alias T="$HOME/.bash_hacks.py T"
# Control CPU frequency scaling.
cfs()
{
local files=(/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor)
[ ! -f ${files[0]} ] && printf "CPU frequency files not found.\n" >&2 && return 1
if [ $# -lt 1 ]
then
column ${files[@]}
else
sudo tee ${files[@]} <<< $1
fi
}
# Restart the shell. Exit from any Python virtual environments before doing so.
e()
{
[ -n "$VIRTUAL_ENV" ] && deactivate
exec bash
}
# View object files.
o()
{
[ ! -f "$1" ] && printf "Usage:\n ${FUNCNAME[0]} <file>\n" >&2 && return 1
(
objdump -Cd "$1"
readelf -p .rodata -x .rodata -x .data "$1" 2>/dev/null
) | $BAT_PAGER
}
# View raw data.
h()
{
[ ! -f "$1" ] && printf "Usage:\n ${FUNCNAME[0]} <file>\n" >&2 && return 1
hexdump -e '"%07.7_Ax\n"' -e '"%07.7_ax " 32/1 " %02x" "\n"' "$1" | $BAT_PAGER
}
# Preprocess C or C++ source code.
c()
{
[ ! -f "$1" ] && printf "Usage:\n ${FUNCNAME[0]} <file>\n" >&2 && return 1
if [ "$2" == ++ ]
then
local c=g++
local l=c++
else
local c=gcc
local l=c
fi
clang-format <($c -E "$1" | command grep -Fv '#') | bat -l $l --file-name "$1"
}
# This is executed only if Bash is running on WSL (Windows Subsystem for
# Linux).
command grep -Fiq microsoft /proc/version && . $HOME/.bash_aliases_wsl.bash
# Pre-command for command timing. It will be called just before any command is
# executed.
_before_command()
{
[ -n "${__begin_window+.}" ] && return
__begin_window=$(custom-bash-prompt)
}
# Post-command for command timing. It will be called just before the prompt is
# displayed (i.e. just after any command is executed).
_after_command()
{
local exit_code=$?
[ -z "${__begin_window+.}" ] && return
local last_command=$(history 1)
PS1=$(custom-bash-prompt "$last_command" $exit_code $__begin_window $COLUMNS "$PWD" $SHLVL)
unset __begin_window
}
trap _before_command DEBUG
PROMPT_COMMAND=_after_command
# PDF optimiser. This requires that Ghostscript be installed.
pdfopt()
{
[ ! -f "$1" ] && printf "Usage:\n ${FUNCNAME[0]} input_file.pdf output_file.pdf [resolution]\n" >&2 && return 1
[ $# -ge 3 ] && local opt_level=$3 || local opt_level=72
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress \
-dNOPAUSE -dQUIET -dBATCH \
-sOutputFile="$2" \
-dDownsampleColorImages=true -dColorImageResolution=$opt_level \
-dDownsampleGrayImages=true -dGrayImageResolution=$opt_level \
-dDownsampleMonoImages=true -dMonoImageResolution=$opt_level \
"$1"
}
# Random string generator.
rr()
{
case $1 in
("" | *[^0-9]*) local length=20;;
(*) local length=$1;;
esac
for pattern in '0-9' 'A-Za-z' 'A-Za-z0-9' 'A-Za-z0-9!@#$*()'
do
tr -cd $pattern </dev/urandom | head -c $length
printf "\n"
done
}
# This program (part of the ImageMagick suite) is just schmuck bait. I've
# entered this at the Bash REPL instead of the Python REPL several times, and
# got scared because the computer seemed to freeze. No more.
import()
{
printf "This is Bash. Did you mean to type this in Python?\n" >&2 && return 1
}