forked from bartonski/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.alias
355 lines (292 loc) · 10.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
################################################################################
# .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
export OPEN_FILE=${OPEN_FILE:-"$(which \"$_alias_open_file\")"
## $MARKDOWN should accept a markdown formatted text file as input,
## and write html to stdout.
${MARKDOWN:="pandoc -f markdown+grid_tables"}
export MARKDOWN
## DIRECTORY VARIABLES #########################################################
${PDF_DIR:="$HOME/PDF"}
export PDF_DIR
${ARCHIVE:="$HOME/archive"}
export ARCHIVE
################################################################################
# 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'
################################################################################
# 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 *. $*"; }
## History grep
hg() { history | egrep -- "$*"| egrep -v "egrep *. $*"; }
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
}
# requires xsel or pbpaste
sfifo () {
local PASTE='xsel -o'
if [ which xsel ]
then
PASTE='xsel -o'
else
PASTE='pbpaste'
fi
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
$PASTE > $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" ; }
# requires enscript
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 | enscript
}
# requires xsel
pbi() {
xsel | pastebinit
}
# requires scrot, mtpaint
sshot() {
scrot '/tmp/screenshot.%Y-%m-%d.%H-%M-%S.png' --select --delay 5 --count
lastfile /tmp
mtpaint "$(lastfile /tmp)";
}