-
Notifications
You must be signed in to change notification settings - Fork 0
/
.alias
459 lines (386 loc) · 13.3 KB
/
.alias
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
#!/usr/bin/bash
alias realias='source ~/.alias'
alias luap="lua -e \"require'pkglib':install()\""
alias ilua="luap -e \"R = require'ds'.R\" -i"
alias ,="luap $HOME/projects/civlua/civ.lua"
function luahelp() {
luap -e "require'civ'; print(require'doc'('$1'))"
}
alias :e='vim'
##################################################
# Environment
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
alias rg='grep -rP'
function cr() {
echo "cr: $1"
cc "$1".c -o "$1" && "./$1"; echo rc=$?
}
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_CONNECTION" ]; then
export DISPLAY=:0.0
fi
alias restart-display="sudo systemctl restart display-manager"
alias NOCAPS="python -c 'from ctypes import *; X11 = cdll.LoadLibrary(\"libX11.so.6\"); display = X11.XOpenDisplay(None); X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(2), c_uint(0)); X11.XCloseDisplay(display)'"
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*" --glob "!.hg/*"'
if [[ -e ~/.alias.local.before ]]; then
source ~/.alias.local.before
fi
function nix-pkgs {
nix-env --description -qaP "$@" | cat
}
alias nix-get='nix-env --install'
export EDITOR='vim'
alias vim-update='vim +PlugInstall +UpdateRemotePlugins +qa'
alias nvim-update='nvim +PlugInstall +UpdateRemotePlugins +qa'
alias vim-reset='rm -rf ~/.vim/data/viminfo ~/.vim/data/view/* ~/.vim/data/undo/* ~/.vim/data/swap/*'
alias dif='colordiff -ENwbu'
alias sudo='sudo '
alias suspend='sudo systemctl suspend'
alias hdmion="xrandr --output HDMI1 --auto --right-of eDP1"
alias hdmioff="xrandr --output HDMI1 --off"
alias mousefix="sudo modprobe -r psmouse && sudo modprobe psmouse"
alias vpnkill='sudo killall openconnect'
# urxvt font setter
setfont(){
fonts="\
xft:Inconsolata\ Nerd\ Font:style=Medium:size=$1\
,ttf: Noto Mono:style=Regular:size=$1\
,ttf: Noto Emoji:style=Regular:size=$1\
,ttf: Noto Sans Symbols:style=Regular:size=$1"
printf '\33]50;%s\007' "$fonts"
}
if [ -z ${TMUX+x} ]; then
setfont 13
fi
function ppath() { echo $PATH | tr -s ':' '\n' }
function pathremove() { export PATH="$(ppath | grep -Fv "$1" | xargs | tr ' ' ':')" }
pathappend() { # properly append path to end of PATH
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="${PATH:+"$PATH:"}$1" # handles case where path is empty
fi
}
function pathinsert() { # insert path in front
if [ -d "$1" ]; then pathremove "$1"; export PATH="$1:$PATH"; fi
}
pathinsert /opt/homebrew/bin
pathinsert "$HOME/bin"
# auto connect to ssh-agent
# if ! pgrep -u $USER ssh-agent > /dev/null; then
# ssh-agent > ~/.ssh-agent-thing
# fi
# if [[ "$SSH_AGENT_PID" == "" ]]; then
# eval $(<~/.ssh-agent-thing)
# fi
# ssh-add -l > /dev/null || alias ssh='ssh-add -l > /dev/null || ssh-add && unalias ssh; ssh'
##################################################
# development commands
# Gotten from $(luarocks path --bin)
CIVLUA="$HOME/projects/civlua"
export LUA_PATH="?.lua;$CIVLUA/lib/pkg/?.lua"
export LUA_PKGS="./;$CIVLUA"
pathappend '/home/rett/.cargo/bin:/home/rett/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
# move EVERYTHING in the current directory into an "old" directory in the current directory
allold() {
tmpmove='../__tmpmove__'
mkdir $tmpmove || return $?
mv * $tmpmove || return $?
mv $tmpmove old || return $?
}
# uses sd to replace $1 with $2 in $@
replace() {
find="$1"
shift
replace_with="$1"
shift
echo "replacing '$find' with '$replace_with' in ""$@"
sd -i "$find" "$replace_with" $(fd -t f ".*" "$@")
}
function mapPrefix() {
prefix=$1
if [ -z "$prefix" ]; then
echo "Usage: mapPrefix prefix value1 [valueN...]" 1>&2
fi
shift
for value in "$@"; do
echo "${prefix}${value}${postfix}"
done
}
# Use this function like: test thing && print_rc
# alias print_rc='echo "command was successful" || echo "failed rc=$?"'
function print_rc() {
rc="$?"
if [ "$rc" -eq 0 ]; then
echo -e "${GREEN}rc=${rc}${NC}"
else
echo -e "${RED}FAILED rc=${rc}${NC}"
fi
}
function aa_256 () { local o= i= x=`tput op` cols=`tput cols` y= oo= yy=; y=`printf %$(($cols-6))s`; yy=${y// /=}; for i in {0..256}; do o=00${i}; oo=`echo -en "setaf ${i}\nsetab ${i}\n"|tput -S`; echo -e "${o:${#o}-3:3} ${oo}${yy}${x}"; done;}
# Use to archive a webpage and all sub-pages
# alias archive-web="wget -rmkKEN"
alias archive-web="wget --no-clobber --recursive --convert-links"
alias hnew="hg update p4head"
alias gfm="git fetch origin master:master" # fetch origin/master and pull to master
alias gd="git diff"
alias gs="git status"
alias gcam="git commit -am"
alias hau="hg amend && hg upload tip"
alias hs="hg status | cat"
alias hsb="hg status --rev p4base | cat"
alias hx="hg xl | cat"
ds() {
# find what is taking up space on disk
sudo du -h $1 | grep '[0-9\.]\+G' | sort -nr
}
corrupt() {
let i=`ls -al $1 | awk '{print $5}'`
let i=`shuf -i 0-$i -n 1`
# let b=`dd if=$1 bs=1 count=1 seek=$i`
# let b=$(expr ($b + 1) % 256)
# let b=$(printf "\x$(printf %x $b)")
# echo "corrupting byte at $i with: " $(printf "%d" $b)
# echo b | dd of=$1 bs=1 count=1 seek=$i
echo "corrupting byte at $i"
dd if=/dev/urandom of=$1 bs=1 count=1 seek=$i conv=notrunc &> /dev/null
}
##################################################
# Python
pathinsert "$HOME/.local/bin"
export PYTHONDONTWRITEBYTECODE=1 # prevents .pyc files
# use the local installation of python first
#python_root="$HOME/software/pyconda/envs"
#py2bin="${python_root}/python2/bin"
#py3bin="${python_root}/python3/bin"
#pathinsert $py3bin
#pathinsert $py2bin
pyfmt() {
autopep8 $1 --max-line-length 105 -r --in-place
docformatter $1 --wrap-descriptions 105 --wrap-summaries 105 -r --in-place --no-blank
}
PYCONDA="$HOME/software/pyconda"
alias conda="$PYCONDA/bin/conda"
alias py2c="$PYCONDA/envs/python2/bin/python"
alias ipy2c="$PYCONDA/envs/python2/bin/ipython"
alias pip2c="$PYCONDA/envs/python2/bin/pip"
alias pypath='echo $PYTHONPATH'
alias py='python3'
alias pyt="py -m pytest --tb short"
alias pytdoc='pyt --doctest-modules' # don't forget you need to give module path
alias pytdb='pyt -sx --pdb'
alias pdb='py -m pdb'
alias dbe='py -m cloudtb.dbe'
alias pydev='py setup.py develop'
# http://peterdowns.com/posts/first-time-with-pypi.html
# passwords are stored at .pypirc
alias pypi='py setup.py register -r pypi sdist upload'
alias pypitest='py setup.py register -r pypitest'
alias py2='python2'
alias py2t="py2 -m pytest --tb short"
alias py2tdoc='py2t --doctest-modules'
alias py2tdb='py2t -vvsx --pdb'
alias pdb2='py2 -m pdb'
alias dbe2='py2 -m cloudtb.dbe'
alias py2dev='py2 setup.py develop'
alias pyclean="rm -r ./**/*.pyc"
pyfix() {
autopep8 $1 -r --in-place --max-line-length 105 || return $?
docformatter $1 -r --in-place --no-blank --wrap-descriptions 105 || return $?
}
##################################################
# Java
function jrun() {
tclear || return 1;
javac "$1.java" || return 1;
java "$1" || return 1;
}
##################################################
# Rust
export RUST_BACKTRACE=1
# export RUST_SRC_PATH="$(rustup run nightly rustc --print sysroot)/lib/rustlib/src/rust/src"
export CARGO_HOME=$HOME/.cargo
# use: cargo test |& rust_filter
alias rust_filter='rg "((error|warning)\[\w+\])|(^\s+--> \w+/\w+)" -N --color never'
alias rdoc='cargo +stable doc --open -p'
alias rs='cargo script'
alias rs-init='cp $HOME/.dotfiles/rust/init.crs'
alias rs-check='cargo +nightly check --tests'
alias rs-test='cargo +nightly test'
alias rs-fmt='cargo +nightly fmt'
alias rs-lint='cargo +nightly clippy'
alias rs-update="\
rustup update nightly \
&& cargo +nightly install clippy --force \
&& cargo +nightly install rustfmt-nightly"
##################################################
# Tmux
alias tls="tmux list-sessions"
alias tatt="tmux attach -t"
alias tnew="tmux new -s"
alias trm="tmux kill-session -t"
alias tmv="tmux rename-session -t" # target-session new-name
alias tkill="tmux kill-server"
alias town="tmux detach -a" # detach all other sessions from tmux, getting it to correct size
alias tclear="clear; tmux clear-history"
function tdump() {
# Dump tmux history to a file
OUT="$1"
tmux capture-pane -pS -1000000 > "$OUT"
echo "dumpled $(wc -l $OUT) lines to $OUT" 1>&2
}
##################################################
# Git
alias gpyignore="wget -q https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore -O .gitignore && echo created python .gitignore file"
alias g='git'
alias gs='git status'
alias gst='git status'
alias gss='git status -s'
alias gd='git diff --color-words'
alias gdc='gd --cached'
alias gdn='gd --name-only'
alias gp='git push'
alias gpo='git push origin'
alias gc='git commit'
alias gca='git commit -va'
alias gcam='git commit -vam'
alias gc!='git commit -v --amend'
alias gco='git checkout'
alias gcm='git checkout master'
alias gcb='git checkout -b'
alias gr='git remote'
alias grls='git remote -v'
alias grmv='git remote rename'
alias grrm='git remote remove'
alias gb='git branch'
alias gbd='git branch -d'
alias gconfig='git config --list'
alias glog='git log --oneline --decorate --color --graph'
alias ga='git add'
#alias gap='git add --patch'
#alias gaa='git add --all'
alias gm='git merge'
alias ghash='git rev-parse HEAD'
gitio() {
curl -i http://git.io -F "url=$1"
}
alias tsave="tmux capture-pane -S -100000 ; tmux save-buffer"
## Sign and verify commits with GPG
#alias gcs='git commit -S'
#alias gsps='git show --pretty=short --show-signature'
## Sign and verify tags with GPG
#alias gts='git tag -s'
#alias gvt='git verify-tag'
##################################################
# Networking
ipscan() {
sudo nmap -sn $1/24 | grep 'Nmap scan report for'
}
alias netinfo='echo "## netstat -nr:" && netstat -nr && echo "## ifconfig:" && ifconfig | pcregrep -M "(eth0|wlan0)\s+Link.*\n\s+inet"'
# File System
alias untar="tar -zxvf"
alias untar-all='for file in `ls *.tar.gz`; do tar -zxf "$file"; done'
dotar() {
tar -zcvf $1.tar.gz $1
}
reconnect() {
if ip link | grep wlp2s0; then
sudo systemctl restart [email protected]
else
sudo systemctl restart [email protected]
fi
}
##################################################
# OS specific aliases
alias arki=wiki-search
pacman-disowned() {
tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$
db=$tmp/db
fs=$tmp/fs
mkdir "$tmp"
trap 'rm -rf "$tmp"' EXIT
pacman -Qlq | sort -u > "$db"
find /etc /opt /usr ! -name lost+found \( -type d -printf '%p/\n' -o -print \) | sort > "$fs"
comm -23 "$fs" "$db"
}
pacman-list() {
# List explicitly installed packages
echo "### Installed from official repos"
pacman -Qen
echo "### Installed from non-official repos"
pacman -Qem
}
archeck() {
echo '############################################################'
echo '###' Broken symlinks: find . -type l -! -exec test -e {} \; -print
find . -type l -! -exec test -e {} \; -print
echo '############################################################'
echo '###' Cleaning Packages: pacache -r; paccache -ruk0; sudo pacman -R $(pacman -Qdtq);
sudo paccache -r # clean package cache (except most recent 3 versions)
sudo paccache -ruk0 # clean all uninstalled packages from cache
sudo pacman -R $(pacman -Qdtq) # remove packages with no dependency links
echo '\n############################################################'
echo '###' Major Errors / logs
echo '###' Checking if systemd services have failed: systemctl --failed
systemctl --failed
echo '\n############################################################'
echo '###' High priority systemd journals: journalctl -p 0..3 -xn
journalctl -p 0..3 -xn
}
# # Instead of below, remap caps to Cntrl in normal keyboard layout and:
# $ cat /usr/share/X11/xorg.conf.d/99-xkb.conf
# Section "InputClass"
# Identifier "keyboard defaults"
# MatchIsKeyboard "on"
#
# Option "XKbOptions" "caps:ctrl_modifier"
# EndSection
# if [[ `uname` == 'Darwin' ]]; then
# alias vim='/Applications/MacVim.app/Contents/MacOS/Vim'
# alias minicom=/opt/minicom/2.2/bin/minicom
# elif [[ `uname` == 'Linux' ]]; then
# true
# ## setxkbmap -option "ctrl:nocaps" >> /dev/null
# ## capslock= cntrl + esc:
# ## http://www.economyofeffort.com/2014/08/11/beyond-ctrl-remap-make-that-caps-lock-key-useful/
# setxkbmap -option 'caps:ctrl_modifier'
# if ps -ef | grep -v grep | grep xcape > /dev/null; then
# echo
# else
# xcape -e 'Caps_Lock=Escape'
# fi
#
# # http://efod.se/writings/linuxbook/html/caps-lock-to-ctrl.html
# #xmodmap -e 'keycode 66 = Control_L'
# #xmodmap -e 'clear Lock'
# #xmodmap -e 'add Control = Control_L'
# elif [[ `uname` == 'Cygwin' ]]; then
# echo "cygwin"
# fi
if [[ `uname` == 'Linux' ]]; then
if ps -ef | grep -v grep | grep xcape > /dev/null; then
true
else
xcape -e 'Control_L=Escape'
fi
fi
if [[ -e $HOME/.alias.local ]]; then
source $HOME/.alias.local
fi
## Fun
mp4_dl() {
# use: download song from youtube
# args: URL SONG_NAME
pytube -e mp4 -r $3 $1 -f "./$2" || return $?
}
mp4_show() {
pytube -s $1
}
duskcc-new() {
wget -O /tmp/duskcc.tar.gz "$1"
cd ~/Downloads
rm -r *-duskcc/ # remove previous versions
tar -xvf /tmp/duskcc.tar.gz
cd *-duskcc
}