-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliases
483 lines (419 loc) · 14 KB
/
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
# vim: set filetype=sh:
# ================================================================
# John Kerl's bash aliases and shell functions, 1992-2013 and onward ...
# Don't do this for non-interactive shells
if [ "${-/i/}" = "$-" ] ; then
return 0
fi
# ================================================================
# First, simple aliases.
UNAME=$(uname)
# -j.5: search results in middle of screen, not top-line (which is default).
# -r: render ANSI color codes as such.
# Setting $LESS makes git diff et al. do things I don't like; use an alias instead.
# export LESS="-j.5 -r"
alias less='less -r'
# See also vars file
# I do not prefer -i aliases.
unalias cp 2> /dev/null
unalias mv 2> /dev/null
unalias rm 2> /dev/null
alias minpath='export PATH=/usr/bin:/bin:/usr/local/bin; export PS1="MINPATH\$ "'
alias 1='fg %1'
alias 2='fg %2'
alias 3='fg %3'
alias 4='fg %4'
alias 5='fg %5'
alias 6='fg %6'
alias 7='fg %7'
alias 8='fg %8'
alias 9='fg %9'
alias bb='pbpaste'
alias bbv='pbpaste | vim -'
alias cls=clear
alias h='history 30'
alias j='jobs -l'
wreset () {
bind '"\C-w": backward-kill-word'
stty werase undef
}
whither () {
for arg; do
which $arg || declare -f $arg || alias $arg
done
}
# ----------------------------------------------------------------
alias R='R --no-save -q'
ttl() {
Rscript -e 'testthat::test_local("tests/testthat")'
}
# ----------------------------------------------------------------
alias dreb='docker run --rm -it --entrypoint=/bin/bash'
alias drit='docker run --rm -it'
# ----------------------------------------------------------------
alias rca='Rscript -e "Rcpp::compileAttributes()"'
alias rox="Rscript -e 'roxygen2::roxygenise()'"
alias pbs="Rscript -e 'pkgdown::build_site()'"
alias rcb='rm -f *.tar.gz; R CMD build --no-build-vignettes --no-manual .'
alias rcc='R CMD check --as-cran --no-vignettes --no-manual *.tar.gz'
alias rci='R CMD INSTALL --no-test-load --no-docs --no-html *tar.gz'
alias rcbi='rcb && rci'
alias rcac='R CMD check --as-cran --no-manual *.tar.gz'
alias tht='Rscript -e testthat::test_local\(\"tests/testthat\"\)'
alias rabi='rca && rcb && rci && echo && echo DONE'
# ----------------------------------------------------------------
alias qp='quarto preview'
alias qr='quarto render'
# Since "java" is a leading substring of "javac", "!java" doesn't work right in
# an edit-compile loop. Hence, these two. Likewise for scalac and scala.
alias jvc=javac
alias jvr=java
#alias si=scala
#alias sc=scalac
#alias sr=scala
#alias st='scala org.scalatest.tools.Runner -p . -o -s'
alias grep='grep --color=auto'
alias gog='rg --type=go'
alias pyg='rg --type=py'
alias cpp20='clang++ -std=c++20'
alias cmz='cmake --build build --target clean && rm -rf build'
alias cmg='cmake -B build'
alias cmgdist='cmake -B build -DCMAKE_INSTALL_PREFIX=./dist'
alias cmgd='cmake -B build -DCMAKE_BUILD_TYPE=Debug'
alias cmb='cmake --build build'
alias cmt='cmake --build build --target test* -j 12'
alias cmi='cmake --build build --target install'
alias sudocmi='sudo cmake --build build --target install'
alias cmgb='cmg && cmb'
alias cmgbt='cmg && cmb && cmt'
alias cmgbti='cmg && cmb && cmti'
my_assign_dir spf "$HOME/git/johnkerl/spffl"
# For Python REPL with my most-used modules pre-loaded:
#alias py='python -Qnew -i ~/.mypy'
alias pve='python --version'
alias pves='pyenv versions'
if [ "$UNAME" = "Darwin" ]; then
alias ls='ls -G'
else
alias ls='ls --color=tty'
fi
alias ll='ls -l'
alias lll='ls -lL'
alias llh='ls -lh'
# Biggest files last:
#alias lss='ls -Slr'
alias lss='ls -hSlr'
# Most recent files last:
alias lt='ls -lrt'
alias nnbu='nbu -d ~/Desktop/folder/bak'
alias v='vim'
alias v-='vim -' # E.g. for "diff ... | vim -":
alias pbv='pbp | v-'
alias vt='vim -t' # Tag jump
alias vim='vim -i NONE -X'
tvim() {
title $(basename $@)
vim "$@"
}
ttvim() {
title "$@"
vim "$@"
}
# Edit "$variablename" but put "variablename" in the title bar
vvim() {
name="$1"
val=$(eval echo '$'"$name")
if [ -z "$val" ]; then
echo "Couldn't expand \$$name."
else
title "$name"
vim "$val"
fi
}
alias ppx='pingety-ping 8.8.8.8'
alias gln='git log -n'
alias gs='git status'
alias gd='git diff'
#alias gd1='git diff HEAD~ HEAD'
#alias gd2='git diff HEAD~2 HEAD'
#alias gd3='git diff HEAD~3 HEAD'
alias gd1='git diff HEAD~'
alias gd2='git diff HEAD~2'
alias gd3='git diff HEAD~3'
alias gd4='git diff HEAD~4'
alias gd5='git diff HEAD~5'
alias gd12='git diff HEAD~2 HEAD~1'
alias gd13='git diff HEAD~3 HEAD~1'
alias gd14='git diff HEAD~4 HEAD~1'
alias gd15='git diff HEAD~5 HEAD~1'
alias gd23='git diff HEAD~3 HEAD~2'
alias gd24='git diff HEAD~4 HEAD~2'
alias gd25='git diff HEAD~5 HEAD~2'
alias gd34='git diff HEAD~4 HEAD~3'
alias gd35='git diff HEAD~5 HEAD~3'
alias gd45='git diff HEAD~5 HEAD~4'
alias ga='git add'
alias gam='git add $(git status | grep modified: | sed "s/ *modified: *//" | cpick 1)'
alias gcm='git commit -m'
alias gcmr='git commit -m "DESCRIPTION and NEWS.md [skip ci]"'
alias gcmdba='git commit -m "doc-build artifacts for previous commit"'
alias gca='git commit --amend --date $(systime) --no-edit'
alias gcae='git commit --amend --date $(systime)'
alias gcam='git commit --amend -m'
alias gcmc='git commit -m "$(cat gcm.txt)"'
alias gp='git push'
alias gpf='git push --force-with-lease'
alias gaa='gam && echo "" && gca'
alias gaap='gam && echo "" && gca && echo "" && gpf'
alias gsl='git sl ...upstream/main'
alias grc='git rebase --continue'
alias glog='git log'
alias glogg='git log --graph'
alias glogga='git log --graph --all'
alias gloggo='git log --graph --oneline'
alias gloggoa='git log --graph --all --oneline'
alias grh='git reset --hard'
alias gprm='git pull --rebase origin main'
alias gprmr='git pull --rebase origin master'
alias grom='git rebase origin/main'
alias groma='git rebase origin/master'
alias gri='git rebase -i'
alias griod='git rebase -i origin/dev'
alias griom='git rebase -i origin/main'
alias grioma='git rebase -i origin/master'
alias gdm='git diff origin/main'
alias gdma='git diff origin/master'
alias gdmo='git diff origin/main-old'
gacp() {
if [ $# -eq 1 ]; then
gam && gcm "$@" && git push
else
echo "Need commit message as single argument"
fi
}
# from https://github.com/johnkerl/scripts/tree/main/git
alias gsb='git show-current-branch'
alias sbs='git show-branches'
alias gub='git checkout'
alias gnb='git new-branch'
alias gmb='git merge'
alias gxb='git delete-branch'
alias gxxb='git delete-branch-force'
alias g2b='git switch-branch'
alias gpom='git pull origin main'
alias gff='git files-from'
gffa() {
gff "$@" | sed 's:apis/python/::'
}
alias grh='git reset --hard'
alias gra='git rebase --abort'
alias bcd='black . --check'
# ----------------------------------------------------------------
alias g17='g++ -std=c++17'
alias g20='g++ -std=c++20'
# ----------------------------------------------------------------
alias cbr='cargo build --release'
# ----------------------------------------------------------------
# Miller
. ~/.vars-tracker
my_assign_file vv "$HOME/Desktop/folder/PLAN.txt"
alias nn='nnbu ~/Desktop/folder/PLAN.txt'
my_assign_dir mlb "$HOME/git/johnkerl/miller"
my_assign_dir mld "$mlb/docs"
my_assign_dir mlds "$mlb/docs/src"
my_assign_dir mman "$mlb/man"
alias five='PATH=../c:$PATH'
alias six='PATH=../go:$PATH'
alias vvv='vim $mlb/todo.txt'
alias vtt='vim ~/Desktop/TODAY.txt'
my_assign_dir pkg "pkg"
my_assign_dir mlv "pkg/mlrval"
my_assign_dir bifs "pkg/bifs"
my_assign_file bfm "pkg/dsl/cst/builtin_function_manager.go"
my_assign_file bnf "pkg/parsing/mlr.bnf"
my_assign_dir ast "pkg/dsl/"
my_assign_file astt "pkg/dsl/ast_types.go"
my_assign_file astb "pkg/dsl/ast_build.go"
my_assign_file astp "pkg/dsl/ast_print.go"
my_assign_dir cli "pkg/cli"
my_assign_dir clim "pkg/climain"
my_assign_dir clu "pkg/cliutil"
my_assign_dir cst "pkg/dsl/cst"
my_assign_dir lib "pkg/lib"
my_assign_dir inp "pkg/input"
my_assign_dir tra "pkg/transformers"
my_assign_dir outp "pkg/output"
my_assign_dir types "pkg/types"
my_assign_file put "pkg/transformers/put-or-filter.go"
my_assign_file udf "pkg/dsl/cst/udf.go"
my_assign_file uds "pkg/dsl/cst/uds.go"
my_assign_file mlrmap "pkg/types/mlrmap.go"
my_assign_file mlrval "pkg/types/mlrval.go"
my_assign_file stream "pkg/stream/stream.go"
my_assign_file stack "pkg/runtime/stack.go"
my_assign_file typing "pkg/types/mlrval_typing.go"
my_assign_dir repl "pkg/auxents/repl"
my_assign_file hofs "$cst/hofs.go"
my_assign_file exv "docs/src/example.csv"
my_assign_file dflags "reference-main-flag-list.md.in"
my_assign_file dverbs "reference-verbs.md.in"
my_assign_file dfuncs "reference-dsl-builtin-functions.md.in"
my_assign_file dgloss "glossary.md.in"
alias clonemiller='git clone https://github.com/johnkerl/miller'
alias mygroff='groff -man -Tascii'
alias bake='make -f Makefile.no-autoconfig'
alias mds='mkdocs serve'
alias mdb='mkdocs build'
alias mrpl='rlwrap mlr repl'
alias mr='make && mlr regtest'
# ================================================================
# For pathnicks.c in repo johnkerl/dotfiles
export PATHNICKS="$mlb:MLR"
export PATHNICKS="$PATHNICKS,$HOME/pub_http_internet/miller-releases:MLRREL"
export PATHNICKS="$PATHNICKS,$HOME/git/fork:GIT-FORK"
export PATHNICKS="$PATHNICKS,$HOME/git:GIT-MAIN"
# ================================================================
# Next are some shell functions. The main deliverables are vimr and cd2file.
# These enable vim and cd to find files several levels deep, which is
# particularly important for Java development wherein package naming forces
# several levels of directories.
# ----------------------------------------------------------------
# file2dir:
# * Given a file name, searches for it recursively downward from the pwd.
# * I don't use this directly but it's used by cd2file and vimr.
# * If exactly one such file is found, prints to stdout the name of the
# directory containing that file and returns 0 (success).
# * On failure, prints a message to stderr and prints nothing to stdout;
# exits with 1 (failure).
# * Wildcards may be used as long as they're escaped, to get them past initial
# shell globbing so that they can reach here unglobbed.
#
# Examples:
# * bash$ file2dir CommonFileName.java
# Sorry, multiple matches (> 10).
#
# * bash$ file2dir MoreSpecificPattern\*.java
# Sorry, multiple matches:
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern1.java
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern2.java
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern3.java
#
# * bash$ file2dir AnotherFileName.java
# ./java/src/org/johnkerl/packagename
#
# ----------------------------------------------------------------
# John Kerl, 2010-06-18
# ----------------------------------------------------------------
file2dir () {
if [ $# -eq 0 ]; then
echo "$FUNCNAME: Need an argument." 1>&2
return 1
elif [ $# -ne 1 ]; then
echo "$FUNCNAME: Need just one argument." 1>&2
return 1
fi
local arg="$1"
local paths="$(find . -follow -name $arg)"
local num_found=$(echo "$paths" | wc -w)
if [ $num_found -gt 10 ]; then
echo "Sorry, multiple matches (> 10)." 1>&2
return 1
elif [ $num_found -gt 1 ]; then
echo "Sorry, multiple matches:" 1>&2
local path="" # keep local for iterator
for path in $paths; do
echo " " $path 1>&2
done
return 1
fi
if [ $num_found -lt 1 ]; then
echo "Couldn't find $arg." 1>&2
return 1
fi
local dir=$(dirname $paths)
if [ -z "$dir" ]; then
echo "Oddity in $FUNCNAME in ~/.aliases: dir name is \"\"." 1>&2
return 1
fi
if [ ! -d "$dir" ]; then
echo "$FUNCNAME: Not cd'ing to \"$dir\" since it's not a directory." 1>&2
echo "This is weird." 1>&2
return 1
fi
echo $dir
return 0
}
# ----------------------------------------------------------------
# cd2file:
# * Given a file name, searches for it recursively downward from the pwd.
# * If exactly one such file is found, chdirs the shell to the directory
# containing that file.
# * On failure, prints a message to stderr and does not chdir the shell.
# * Wildcards may be used as long as they're escaped, to get them past initial
# shell globbing so that they can reach here unglobbed.
# Examples:
# * bash$ file2dir CommonFileName.java
# Sorry, multiple matches (> 10).
#
# * bash$ file2dir MoreSpecificPattern\*.java
# Sorry, multiple matches:
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern1.java
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern2.java
# ./java/src/org/johnkerl/packagename/MoreSpecificPattern3.java
#
# * bash$ cd2file AnotherFileName.java
# cd'ing to:
# ./java/src/org/johnkerl/packagename
#
# ----------------------------------------------------------------
# John Kerl, 2010-06-18
# ----------------------------------------------------------------
cd2file() {
dir=$(file2dir "$@")
if [ $? -ne 0 ]; then
# An error message was already printed out by file2dir.
return 1
fi
echo " cd'ing to:"
echo " $dir"
cd $dir && return 0 # Normal
return 1 # Failure
}
pushd2file() {
dir=$(file2dir "$@")
if [ $? -ne 0 ]; then
# An error message was already printed out by file2dir.
return 1
fi
echo " pushd'ing to:"
echo " $dir"
pushd $dir && return 0 # Normal
return 1 # Failure
}
# ----------------------------------------------------------------
# vimr: does not chdir the shell but does edit the file.
vimr() {
dir=$(file2dir "$@")
if [ $? -ne 0 ]; then
# An error message was already printed out by file2dir.
return 1
fi
vim $dir/"$@"
}
# ------------------------------------------------------------------------------
cdwhich() {
local cmd
local path
cmd="$1"
path=$(which $cmd)
if [ $? -ne 0 ]; then
echo "Can't find dir for \"$cmd\""
else
dir=$(dirname $path)
cd $dir
fi
}
# ================================================================
# Reminders:
# git clone ssh://git@github.com/johnkerl/scripts
# jq '.|select(.key=="value")' filename.json