-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshellrc
More file actions
283 lines (249 loc) · 7.43 KB
/
shellrc
File metadata and controls
283 lines (249 loc) · 7.43 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
# shellcheck shell=bash
# ~/.shellrc - for common *sh settings
# enable colour support of ls and add handy aliases
if command -v dircolors >/dev/null; then
eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias rgrep='rgrep --color=auto'
fi
if [[ $OSTYPE == "darwin"* ]]; then
# native/BSD `grep`
alias grep='grep --color=auto'
if command -v gdircolors >/dev/null; then
eval "$(gdircolors -b)"
# GNU `grep`
alias gls='gls --color=auto'
alias ggrep='ggrep --color=auto'
alias gfgrep='gfgrep --color=auto'
alias gegrep='gegrep --color=auto'
# `grgrep` doesn't exist
fi
fi
alias ll='ls -l'
alias lh='ls -lh'
alias la='ls -A'
alias lt='ls -lt'
alias l='ls -CF'
# don't shadow macos /usr/bin/log
alias plog='vim ~/doc/log'
alias logp='plog'
alias todo='vim ~/TODO'
alias todos='grep -c "^- " ~/TODO'
alias tasks='find ~/doc/tasks -type f | wc -l'
alias wlog='vim ~/work/org/log'
alias logw=wlog
alias wtodo='vim ~/work/org/todo'
alias todow='wtodo'
alias stonks='~/src/go/src/github.com/acx0/stocks/run.sh'
alias sg='stonks -g'
sgl() {
stonks -g "$@" | less
}
alias sgla='sgl -a'
alias ml='left -g'
alias mla='left -g -a'
alias dl='dleft'
alias vi='vim -u NONE'
alias vimupdate="vim +PlugUpdate"
alias g='git'
alias c='cargo'
py() {
for pybin in ipython3 ipython python3 python; do
if command -v $pybin >/dev/null; then
$pybin
return
fi
done
echo >&2 "error: none found"
}
alias io='sudo iotop -o'
alias fa='sudo fatrace -t'
alias mtr='mtr --curses'
alias dfn='findmnt -D'
# note: including `-brief` in alias for `ip` means certain command outputs will be 'truncated'
# e.g.: `ip -brief -s link show` vs `ip -s link show`
alias ip='ip -color'
alias ipa='ip -brief addr'
alias sc='systemctl'
alias jc='journalctl'
alias dmsg='sudo dmesg --follow --human'
alias npg='noping -g histogram'
if [[ $OSTYPE == "darwin"* ]]; then
alias swap='du -csh /var/vm/* /System/Volumes/VM/* 2>/dev/null'
alias tbw='smartctl -a disk0 | grep "Data Units"'
else
alias swap='command -v zramctl && zramctl --output-all && echo; cat /proc/swaps'
fi
alias mounted='mount | grep "/dev/\(sd[b-z]\|mapper\)"'
alias ppath='echo $PATH | tr : "\n"'
alias etlog='sudo etckeeper vcs log'
alias update='sudo aptitude update && sudo aptitude safe-upgrade'
alias rmad='rmadison'
alias acm='apt-cache madison'
alias acp='apt-cache policy'
alias ain='sudo aptitude install'
alias are='sudo aptitude remove'
alias apu='sudo aptitude purge'
alias auc='sudo aptitude autoclean'
alias ase='aptitude search'
alias ash='aptitude show'
alias ay='aptitude why'
alias afl='apt-file list'
alias aff='apt-file find'
alias dep='apt-rdepends'
alias rdep='apt-rdepends -r'
depd() {
if [[ -z $* ]]; then
echo >&2 "args: <apt-rdepends-args>"
return 1
fi
dot -Txlib <(apt-rdepends -d "$@")
}
alias rdepd='depd -r'
if [[ $OSTYPE == "darwin"* ]]; then
alias b='brew'
alias bse='brew search'
alias bup='brew update'
alias bin='brew install'
alias bout='brew outdated'
alias boutg='brew outdated --greedy'
alias bupg='brew upgrade'
alias bupgg='brew upgrade --greedy'
alias bu='brew uses --eval-all'
alias bui='brew uses --installed'
fi
# note: -a == -rlptgoD
alias rs='rsync -av --progress'
alias rschk='rsync --dry-run -av --delete'
alias rschk-itemize='rsync --dry-run -av --delete --itemize-changes'
# note: default `--out-format` will output `*deleting` prefix for each item being removed (if remote rsync is recent)
rschk-content-only() {
if [[ -z $* ]]; then
echo >&2 "args: <rsync-args>"
return 1
fi
rsync --dry-run -rltDvO --delete --itemize-changes "$@" \
| grep -e '^\*' -e '^.f[\.c][\.s]'
}
rschk-content-checksum() {
if [[ -z $* ]]; then
echo >&2 "args: <rsync-args>"
return 1
fi
rschk-content-only --checksum "$@"
}
alias m='make -j $(nproc)'
alias d='docker'
alias dc='docker-compose'
alias tf='terraform'
# list processes which are using a deleted map file after a system update
alias dm="sudo lsof +c 15 | grep 'DEL.*lib' | cut -d ' ' -f 1 | sort -u"
alias fm='ranger'
alias f='ranger_cd'
ranger_cd() {
local cd_file="$HOME/.config/ranger/shell_cd"
ranger --choosedir "$cd_file" "${@:-$PWD}" # use supplied arg otherwise $PWD if none
local chosen_dir
chosen_dir="$(<"$cd_file")" || return 1
if [[ -n $chosen_dir ]] && [[ $chosen_dir != "$PWD" ]]; then
cd -- "$chosen_dir"
fi
rm -f -- "$cd_file"
}
# enable colours in less for man pages
man() {
# note:
# - setting LC_CTYPE prevents substitution of `-` with `‐` which causes failed searches e.g.:
# `man less` -> `--RAW‐CONTROL‐CHARS` vs `--RAW-CONTROL-CHARS`
# - groff 1.23.0 removed support for `sgr` device control command unless `GROFF_NO_SGR` used
# - without this, identifiers used for colour hints won't be emitted
# see also:
# `LESS='+/String capabilities' man termcap` for meaning of LESS_TERMCAP_* vars
# `LESS='+/sgr0' man terminfo`
# `LESS='+/Color Handling' man terminfo`
# `LESS_TERMCAP_DEBUG=1 man less`
LC_CTYPE=C \
GROFF_NO_SGR=1 \
LESS_TERMCAP_md=$'\E[01;36m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[01;43;30m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[01;32m' \
command man "$@"
}
alias yt-dlp-audio-only='yt-dlp --extract-audio --audio-quality 320K --audio-format mp3'
strace-output() {
if [[ -z $* ]]; then
echo >&2 "args: <cmd> [<cmd-args>]"
return 1
fi
mkdir -p /tmp/strace-output
strace \
-fo $(mktemp -u /tmp/strace-output/XXXXXXXX-$(basename $1)) \
"$@"
}
strace-output-verbose() {
if [[ -z $* ]]; then
echo >&2 "args: <cmd> [<cmd-args>]"
return 1
fi
mkdir -p /tmp/strace-output
strace \
--no-abbrev \
--string-limit 1024 \
-fo $(mktemp -u /tmp/strace-output/XXXXXXXX-$(basename $1)) \
"$@"
}
alias venvc-pyenv='python -m venv'
alias venvc='python3 -m venv'
alias venvd='deactivate'
venvu() {
local venv_dir="$1"
if [[ -z $venv_dir ]]; then
echo >&2 "arg: <venv-dir>"
return 1
fi
# inject into shell history for ctrl-r
local cmd="source \"$(realpath "$venv_dir")/bin/activate\" # venvu"
if [[ -n $ZSH_VERSION ]]; then
print -S "$cmd"
elif [[ -n $BASH_VERSION ]]; then
history -s "$cmd"
fi
eval "$cmd"
}
get_git_branch() {
local branch=$(git symbolic-ref --short HEAD 2>/dev/null)
if [[ -n $branch ]]; then
echo "(br:$branch) "
fi
}
get_git_stash_count() {
local num_stashes=$(git rev-list --walk-reflogs --count refs/stash 2>/dev/null)
if [[ -n $num_stashes ]]; then
echo "(st:$num_stashes) "
fi
}
get_last_exit_status() {
local last_exit_status=$?
if [[ $last_exit_status -ne 0 ]]; then
echo "(e:$last_exit_status) "
fi
}
get_python_venv() {
if [[ -n $VIRTUAL_ENV ]]; then
echo "(venv:$(basename $VIRTUAL_ENV)) "
fi
}
if [[ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]]; then
source "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
# for managing python versions
if command -v pyenv >/dev/null; then
eval "$(pyenv init -)"
fi
# vim: set ts=8 sts=4 sw=4 et ft=bash: