Pelicanux

Just A Few Random Words

My Bashrc

Well, I have struggled enough to create my ~/.bashrc. Here it is, so that I will always get it from anywhere, from my jobplace as from home. Hoping it will inspire some unlikly readers.

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
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+:}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

PS1='\[\033[01;32m\]\u\[\033[01;34m\]@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
[[ "$HOME" == "/root" ]] && PS1='\[\033[01;31m\]\u\[\033[01;32m\]@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]:~# '

alias ls='ls --color=auto'
alias sl='ls'
alias dc='cd'

[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases
[[ -f /etc/bash_completion ]] && ! shopt -oq posix && . /etc/bash_completion

ipgrep () {

  grep -Ern "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" .

}

Egrep () {

  if [ $# -eq 1 ]; then
      grep -Ev "#|^$" $1
  elif [ $# -eq 2 ]; then
      grep -Ev "$2|^$" $1
  else
      echo "Usage: Egrep file [char]"
  fi

}

export dev="/home/philippe/Documents/dev"
export nb="/home/philippe/Documents/dev/newbie-contest"
export o="$dev/octopress/octopress"
export t="$dev/twitter-bootstrap/bootstrap/"

export HISTSIZE=2000
export HISTIGNORE='history*'

# I like using Ctrl+<- to move backward word and Ctrl+-> to move forward-word
bind '"\e\x5b\x31\x3b\x35\x44"':backward-word
bind '"\e\x5b\x31\x3b\x35\x43"':forward-word

# https://stackoverflow.com/questions/945288/saving-current-directory-to-bash-history
hcmnts() {

    export HISTTIMEFORMAT=

    local hcmnt
    local cwd
    local extra

    hcmnt=$(history 1)
    hcmnt="${hcmnt# *[0-9]*  }"

    if [[ ${hcmnt%% *} == "cd" ]]
    then
        cwd=$OLDPWD
    else
        cwd=$PWD
    fi

    extra=$(eval "$hcmntextra")

    hcmnt="${hcmnt% ### *}"
    hcmnt="$hcmnt ### ${extra:+$extra }$cwd"

    history -s "$hcmnt"
}
export hcmntextra='date +"%d-%m-%Y %H:%M:%S"'
export PROMPT_COMMAND='hcmnts'

killbill() {

  PROCESS_NAME=$1
  for i in $(ps aufx | grep ${PROCESS_NAME} | grep -v grep | awk '{printf $2}');
  do
      if [[ $2 == "-t" ]]; then
          echo $i;
      else
          kill -9 $i;
      fi
  done

}

Unfortunately, I won’t allow any comment on my blog, at least for now. No one would give me some hints about their own bashrc; But anyway, I won’t get less Spam and a static blog is always easier to protect than a dynamic one.