-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.alias
515 lines (433 loc) · 14.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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
################################################################################
# .alias -- a series aliases and shell functions which act as shortcuts for
# commands often used at Appriss.
# Version: 1.2
# Date: Name: Description:
# 2009-08-14 Barton Chittenden Initial Version
# 2010-11-16 Barton Chittenden Integrated commands from various machines.
################################################################################
################################################################################
# SHELL VARIABLES
################################################################################
## ABSTRACT EXECUTABLE VARIABLES ###############################################
# All of these should set defaults, but allow the use of variables that
# are already defined.
## $OPEN_FILE takes a file name or directory as an argument.
## Directories should be opened in a task manager,
## Files should be opened by mime type or extension.
## There should probably be some checks done here to see if
## the shell is interactive and has access to the desktop
## e.g. checking $DISPLAY if running under X.
case "$OSTYPE" in
darwin*) _alias_open_list="open";;
*) _alias_open_list="xdg-open gnome-open kde-open";;
esac
for _alias_open_file in $_alias_open_list
do
which "$_alias_open_file" > /dev/null && break;
done
OPEN_FILE="$(which "$_alias_open_file")"
export OPEN_FILE
## Probably need to test using a combination of $OSTYPE and
## which.
if which xclip > /dev/null
then
export CLIPCOPY='xclip -i'
export CLIPCLIPBOARD='xclip -i -selection clipboard'
export CLIPPASTE='xclip -o'
else
export CLIPCOPY='pbcopy'
export CLIPCLIPBOARD='pbcopy'
export CLIPPASTE='pbpaste'
fi
## DATE VARIABLES ##############################################################
## I find the date formatting strings (i.e. date "+..." formats) impossible to
## remember; these variables follow yyyy-mm-dd HH:MM:SS, for the most part.
export yy='%y'
export yyyy='%Y'
export mm='%m'
export dd='%d'
export HH12='%I'
export HH='%H'
export MM='%M'
export SS='%S'
export UNIXTIME='%s'
export JULIAN='%j'
export AMPM='%P'
export ampm='%p'
## $MARKDOWN should accept a markdown formatted text file as input,
## and write html to stdout.
MARKDOWN=${MARKDOWN:-"pandoc -f markdown+grid_tables"}
export MARKDOWN
## DIRECTORY VARIABLES #########################################################
PDF_DIR=${PDF_DIR:-"$HOME/PDF"}
export PDF_DIR
ARCHIVE=${ARCHIVE:-"$HOME/archive"}
export ARCHIVE
################################################################################
# checkdir ()
# creates a directory if it does not exist.
# takes name of directory to be checked/created
# Variables changed
# None
################################################################################
checkdir ()
{
if [ ! -d $1 ]; then
mkdir -p $1;
fi
}
################################################################################
# ruler ()
# prints an ascii ruler which runs the width of the terminal.
# Does not expect any argumens.
# Variables changed
# None
# Requires 'ruler.pl' to be in $PATH
################################################################################
ruler ()
{
ruler.pl $COLUMNS
}
################################################################################
# range ()
# Converts a comma separated pair of arguments, and prints a range between the
# start and calculated end positions.
# Expects 2 arguments:
# start-position
# length
# Variables changed
# None
################################################################################
range() { start=$(echo $1 | cut -d ',' -f1)
len=$(echo $1 | cut -d ',' -f2)
end=$(echo "$start + $len - 1" | bc)
echo "$start-$end";
}
# ################################################################################
# # I keep a running list of projects in $HOME/.project. This command is used
# # to search through my project file.
# ################################################################################
# project() {
# echo "================================================================================"
# touch $HOME/.project
# egrep -i $1 $HOME/.project
# echo "================================================================================"
# }
################################################################################
# Returns today's date in YYYYMMDD format.
################################################################################
alias dts='date +%Y%m%d'
################################################################################
# Returns yesterday's date in YYYYMMDD format.
################################################################################
alias yesterdts='date -d yesterday +%Y%m%d'
################################################################################
# Returns timestamp in YYYY-MM-DD_HH:MM:SS format.
################################################################################
alias timestamp='date +%Y-%m-%d_%H:%M:%S'
################################################################################
# Returns timestamp in YYYYMMDDHHMMSS format.
################################################################################
alias fts='date +%Y%m%d%H%M%S'
################################################################################
# Force mtr to use terminal
################################################################################
# requires mtr
alias mtr='mtr --curses'
################################################################################
# Fix common typo
################################################################################
alias gti='git'
################################################################################
# Create a directory named with the current date in YYYYMMDD format. Takes
# the name of the directory where you want to create the directory as an
# argument. If no argument is given, creates directory in current directory.
################################################################################
dmd ()
{
( if [ "$1"x != "x" ]; then cd "$1"; fi
mkdir $(dts) )
}
## Set options for ls
if [ $OSTYPE="linux-gnu" ]
then
export LS_OPTIONS="-N --color=tty -T 0 "
else
export LS_OPTIONS=""
fi
alias ls='/bin/ls $LS_OPTIONS'
## Make bc use floating point.
alias bc='bc -l'
## Sum a column of numbers
# requires perl
alias plsum="perl -e '\$sum=0; while(<>){\$sum+=\$_}; print \"\$sum\\n\"'"
## Yields date in YYYYMMDD format
mydate=$(date +%Y%m%d)
## list given directory in reverse-time order
ll () {
if [ $OSTYPE="linux-gnu" ]
then
TIME_STYLE='--time-style=+"%Y-%m-%d %H:%M:%S"'
else
TIME_STYLE=''
fi
ls -lart "$TIME_STYLE" "$@";
}
past () { ll "$@"; echo "'past' is deprecated, use 'll' instead."; }
## Alias common misspellings of 'past'
alias pat=past
alias paset=past
alias psat=past
## Echo all of the arguments, underlined with '=' characters.
title () {
echo "$@" | perl -ne 'chomp; print "\n$_\n"; print "=" x length($_) . "\n" '
}
## use 'slice' as a text filter to chop off the number of characters equal to the
## width of the argument string. For example, to remove the permissions string from
## ls -l, you could use
## $ ls -l | slice "-rw-r--r-- "
slice() { cut -c$((${#1}+1))-; }
# requires sqlite3
alias s3='sqlite3'
alias browse="$OPEN_FILE ."
## Create a text box around a quoted string.
box() { t="$1xxxx";c=${2:-=}; echo ${t//?/$c}; echo "$c $1 $c"; echo ${t//?/$c}; }
## Recover a borked terminal
alias sane=reset
alias dush="du -sm *|sort -n|tail"
comment() { echo "" > /dev/null; }
## add this command to $HOME/.bashtemprc
addtemp() { echo "$@" >> $HOME/.bashtemprc; }
alias addtmp='addtemp'
## Grep process list
psg() { ps aux | command egrep -- "$*" | egrep -v "egrep *. $*"; }
## Grep history
hg() { history | egrep -- "$*" | egrep -v "egrep *. $*"; }
## Grep set
sg() { set | egrep -- "$*|\(\)" | egrep -B1 "$*"; }
editcmd() { $1 > $2 && $EDITOR $2; }
# requires vim
vimcmd() { local EDITOR=$(which vim); editcmd $1 $2; }
# use $google when DNS is down.
export google='74.125.65.104'
svnpath() { svn info | sed -n '/URL:/s/URL: //p'; }
alias svndir='svnpath'
cdl() { cd $1; ll; }
# requires dirname
fcd() { cd "$( dirname \"${1}\")";}
################################################################################
# lastfile ()
# Arguments: directory
# Find the most recent file in the directory given by $1.
################################################################################
lastfile() {
find "${1:-.}" -maxdepth 1 -type f -printf "%T+ %p\n" | sort -n | tail -1 | sed 's/[^[:space:]]\+ //'
}
pdffile() { $OPEN_FILE $(lastfile "$PDF_DIR"); }
# requires tidy
xmltidy() { tidy -xml -i "$@" 2> /dev/null ; }
gripe() {
echo "-- $(timestamp) -- " $@ >> $HOME/.gripefile
}
fifo () {
local fifo="$HOME/fifo"
if [ ! -e $fifo ]
then
mkfifo $fifo
elif [ ! -p $fifo ]
then
echo "$fifo exists, but is not a named pipe"
return 1
fi
cat > $fifo
}
sfifo () {
local fifo="$HOME/fifo"
if [ ! -e $fifo ]
then
mkfifo $fifo
elif [ ! -p $fifo ]
then
echo "$fifo exists, but is not a named pipe"
return 1
fi
$CLIPPASTE > $fifo
}
# requires jpegtopnm, pnmscale, ppmtopgm, ppmdither, potrace
jpg2svg () {
jpgname=$1
base=$(echo $jpgname | sed 's/\.jpg$//i' )
jpegtopnm $jpgname | pnmscale 2 | ppmtopgm | ppmdither -dim 2 | potrace -s -o $base.svg
ls -lart $base.svg
}
# requires perl, vim
vimgn () {
perl -e '@F=split( ":", $ARGV[0]); system("vim +$F[1] $F[0]")' $@
}
# requires enscript
perlprint() {
/usr/bin/enscript --no-header -d PDF -r -C --highlight=perl "$@" --color
}
# requires markdown2pdf
mkpdf() {
base=$1
$EDITOR $base.markdown
markdown2pdf -o $PDF/$base.pdf $base.markdown
$OPEN_FILE $PDF/$base.pdf
}
freeze() {
if [ X"" != X"$1" ]
then
tar zcvf "$1.tgz" "$1" && rm -rf "$1"
mv "$1.tgz" $ARCHIVE
fi
}
## Given a filename containing a timestamp
## call tstouch filename REGEX
## where REGEX is a regular expression matching the timestamp.
## The modification time of the file will then be changed to that timestamp.
tstouch() { [[ $1 =~ $2 ]] && touch -t ${BASH_REMATCH[1]} $1; }
# requires tmux
alias tmux='TERM=xterm-256color tmux'
# takes regex, files as arguments, returns the subroutines containing the arguments.
grepsub() { regex=$1; shift; egrep "^sub|$regex" "$@" | grep -B1 "$regex" | grep '^sub'; }
# Shows which file a function is defined in.
showfunc() { shopt -s extdebug; declare -F $1; shopt -u extdebug; }
# Wrapper around 'git add/git commit'
# Runs git diff and edits output as commit message -- delete contents to cancel.
# requires git
checkin() {
local git_msg_file="/tmp/checkin.$(dts).diff.git"
git diff "$@" > $git_msg_file
$EDITOR $git_msg_file
if [[ -s $git_msg_file ]]
then
git add "$@"
git commit -F $git_msg_file
fi
}
# edit executable in path.
vimx() { $EDITOR $(which "$1"); checkin "$1" ; }
planner()
{
local line1='|________________________________________________________________________________|'
local line2='| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .|'
for hh in {8..17}
do
printf "%2d:00 $line1\n\n%2d:30 $line2\n\n" ${hh} ${hh}
done
}
pbi() {
$CLIPPASTE | pastebinit
}
# requires scrot, mtpaint
sshot() {
scrot '/tmp/screenshot.%Y-%m-%d.%H-%M-%S.png' --select --delay 5 --count
lastfile /tmp
mtpaint "$(lastfile /tmp)";
}
myip() {
echo $(curl ifconfig.me 2> /dev/null)
}
imgsearch ()
{
tmp="$*";
query="${tmp// /+}";
echo "https://www.google.com/search?q=$query&btnI=I%27m+Feeling+Lucky"
echo "https://www.google.com/search?tbm=isch&q=$query"
}
lucky ()
{
tmp="$*";
query="${tmp// /+}";
echo "https://www.google.com/search?q=$query&btnI=I%27m+Feeling+Lucky"
}
################################################################################
# md ()
# Render markdown.
# Requires pandoc
# Expects 1 or 2 arguments:
# markdown file (named '*.markdown' or '*.md' )
# html directory
# Variables changed
# None
################################################################################
md ()
{
local file="$1";
local base="${file%'.markdown'}"
base="${base%'.md'}"
shift
local htmldir="${1:-.}";
test -d $htmldir || mkdir $htmldir;
local htmlfile="$htmldir/${base}.html";
pandoc --ascii -f markdown+pipe_tables $file > "$htmlfile";
echo "$htmlfile"
}
################################################################################
# crashlog
# Look in syslog and kern log to see what happened just prior to the last reboot.
# Expects no arguments.
# Variables changed
# None
################################################################################
crashlog() {
grep '0\.000000' -h /var/log/{syslog,kern.log} -B 20 | grep -v '0\.000000' -A1
}
################################################################################
# ci
# Check in file in a git repo. File should be in the current directory.
# Takes the name of the file to be checked in as an argument.
# Variables changed
# None
################################################################################
ci ()
{
git diff $1 > /tmp/${1}.git.diff;
git add $1;
/usr/bin/vi /tmp/${1}.git.diff;
git commit $1;
git status
}
calc() {
bc <<< "${@}"
}
# ghurl: Github URL
ghurl()
{
local file="{$1}"
rel_file="$(git ls-files --full-name $1)"
local sedcmd='/github.com.*push/{s/^[^[:space:]]\+[[:space:]]\+//;s|git@github.com:|https://github.com/|;s/\.git.*//;p}'
local giturl="$( git remote -v | sed -n $sedcmd )"
if [ -z $file ]; then
echo $giturl
else
echo ${giturl}/blob/master/${rel_file}
fi
}
example ()
{
echo "EXAMPLE:";
echo;
echo " $@";
echo;
echo "OUTPUT:";
echo;
eval "$@" | sed 's/^/ /'
}
################################################################################
# mdl ()
# Markdown Link
# Requires mojolicious
# Expects 1 argument:
# URL to create link from.
# Variables changed
# None
################################################################################
mdl ()
{
url=$1;
text="$( mojo get "$url" title text | sed 's/^[[:space:]]*//g;/^$/d' )";
echo "[$text]($url)"
}