-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS59_tools
92 lines (70 loc) · 2.81 KB
/
S59_tools
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
#!/bin/zsh
if [ "$PS1" ]; then
if [ -x $HOME/bin/vim ] ; then
export EDITOR=$HOME/bin/vim
elif ( which vim > /dev/null ) ; then
export EDITOR=vim
fi
export PAGER=less
#export PAGER=~/bin/vimpager
#alias less=$PAGER
export VPAGER="vim -R -"
# ---- paging ------------------------------------------------------------
function least() {
declare -a lines
if ! [ -z "$@" ] ; then
cat $@ | least
return 0
fi
if [ -z "$LINES" ] || ! ( echo $LINES | grep -q '^[0-9]\+$' ) ; then
LINES=20
fi
function dump_array () {
for n in `seq 1 "${#lines[@]}"` ; do
echo "${lines[$n]}"
done
}
#pre_IFS=$IFS
#IFS=
while read x ; do
#IFS=$pre_IFS
lines[((${#lines[@]}+1))]="$x"
if [ "${#lines[@]}" -ge $LINES ] ; then
( dump_array ; cat ) | $VPAGER
exit 0
fi
done
#IFS=$pre_IFS
dump_array
}
#function v() { $@ | vim -R - ; }
function v() { $@ | least ; }
function vv() { $@ | vim -R - ; }
function maxhead() { head -n `echo $LINES - 2|bc` ; }
function maxtail() { tail -n `echo $LINES - 2|bc` ; }
# ---- other ------------------------------------------------------------
# <dave0> if you use this bash function, you can do 'dpan DBD::ODBC'
# and it will get the debian package if it exists
function dpan () {
PKG=$(perl -e '$_=lc($ARGV[0]); s/::/-/g; print "lib$_-perl\n"' $1)
echo apt-get install $PKG
}
# <lpaseen> gives last time the cmdline was changed in seconds since epoc
# and since the process is a daemond it doesn't change once it started
getetime() {
pid=$(pgrep -o $1)
if [ -z "$pid" ];then
echo "-1"
return 1
fi
let etime=$(date +%s)-$(stat -c %Y /proc/$pid/cmdline)
echo $etime
}
alias lindent='sh /usr/src/linux/scripts/Lindent'
# print pretty calendars
alias pcal-portrait="pcal -F 1 -m -J -p"
alias pcal-landscape="pcal -F 1 -m -J -l"
alias grep='grep --color=auto'
# alias ack='ack --color'
export ACK_OPTIONS="--color"
fi