Dave Perrett

Useful .bashrc Functions

bash, linux, programming, quickie

A couple of useful functions for .bashrc :

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
#--------------------------------------------------------
* rlist()
#
* List/Kill RubyOnRails Processes
function rlist() {
  #     ps -aux | egrep -i "light|ruby" | grep -v grep
  # if no args, list all
  if [ $# == 0 ]
  then
    ps -aux | egrep -i "light|ruby" | grep -v grep
  fi

  # if 1 arg, list lines containing that arg
  if [ $# == 1 ]
  then
    ps -aux | egrep -i "light|ruby" | grep -v grep | grep $1
  fi

  if [ $# == 2 ]
  then
    if [ $1 == 'kill' ]
    then
      tokill=`ps -aux | egrep -i "light|ruby" | grep -v grep |  grep $2 | cut -f6 -d' '`
      kill -9 $tokill
    fi
  fi
}

#--------------------------------------------------------
* srch()
#
* Find a word in files under the current directory,
* ignoring .svn and log files
function srch() {
    grep -R $1 * | grep -v "\.svn" | grep -v "\.log"
}

#--------------------------------------------------------
* svndiff()
#
* Improved svn diff command
function svndiff() {
    svn diff --diff-cmd /usr/bin/diff -x "-bB" $1
}

#--------------------------------------------------------
* svnedit()
#
* Edit svn log entries (need to enable pre-revprop-change
* hook first)
function svnedit() {
    svn propedit svn:log --revprop -r $1 svn://localhost/analytics_server --editor-cmd vi
}