Pulling in some ideas from the trisquel .bashrc
[dotfiles] / .bashrc
1 # ~/.bashrc: executed by bash(1) for non-login shells.
2
3 # If not running interactively, don't do anything
4 case $- in
5     *i*) ;;
6       *) return;;
7 esac
8
9 # don't put duplicate lines in the history. See bash(1) for more options
10 # don't overwrite GNU Midnight Commander's setting of `ignorespace'.
11 export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
12 # ... or force ignoredups and ignorespace
13 export HISTCONTROL=ignoreboth
14
15 # append to the history file, don't overwrite it
16 shopt -s histappend
17
18 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
19
20 # check the window size after each command and, if necessary,
21 # update the values of LINES and COLUMNS.
22 shopt -s checkwinsize
23
24 # If set, the pattern "**" used in a pathname expansion context will
25 # match all files and zero or more directories and subdirectories.
26 shopt -s globstar
27
28 # make less more friendly for non-text input files, see lesspipe(1)
29 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
30
31 # set the prompt
32 PS1='\w\$ '
33
34 # set variable identifying the chroot you work in (used in the prompt below)
35 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
36     debian_chroot=$(cat /etc/debian_chroot)
37 fi
38
39 # enable color support of ls and also add handy aliases
40 if [ -x /usr/bin/dircolors ]; then
41     eval "`dircolors -b`"
42     alias ls='ls --color=auto'
43     alias dir='dir --color=auto'
44     alias vdir='vdir --color=auto'
45
46     alias grep='grep --color=auto'
47     alias fgrep='fgrep --color=auto'
48     alias egrep='egrep --color=auto'
49 fi
50
51 alias emacs='emacs -nw'
52 alias serve='python -m SimpleHTTPServer 8080'
53
54 export SVN_EDITOR=vim
55
56 # Enable programmable completion features (you don't need to enable
57 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
58 # sources /etc/bash.bashrc).
59 if [ -f /etc/bash_completion ]; then
60     . /etc/bash_completion
61 fi
62
63 # Add the ~/bin directory to the path.  This allows you to install simple
64 # binaries by simply moving them into ~/bin.
65 if [ -d $HOME/bin ]; then
66         PATH="$HOME/bin:$PATH"
67         export PATH
68 fi
69
70 # Put $HOME/.cabal/bin on the path. Installing cabal doesn't
71 # automatically put installed packages on the path.
72 if [ -d $HOME/.cabal/bin ]; then
73     PATH="$HOME/.cabal/bin:$PATH"
74     export PATH
75 fi
76
77 # Put /usr/local/bin (where homebrew installs stuff) before /usr/bin on the
78 # path. This means that if a program exists at both locations, calls to that
79 # program will use the homebrew version rather than the system version.
80 PATH="/usr/local/bin:$PATH"
81 export PATH
82
83 # Run a machine-specific bashrc (if it exists).
84 if [ -f $HOME/.bashrc_local ]; then
85         source $HOME/.bashrc_local
86 fi
87
88 # Install RVM if it's not installed.
89 if [ ! -f $HOME/.rvm/scripts/rvm ]; then
90     bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
91 fi
92
93 # Load RVM into shell session.
94 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
95
96 # Automatically open screen.
97 # The if statement prevents it from recursing (since screen opens bash).
98 if [ $TERM != screen ]; then
99         screen
100 fi
101
102 # Gets a directory named .env if it exists in the currend directory or any of its parents
103 get_env() {
104     if [ -d "$1/.env" ] ; then
105         echo "$1/.env"
106     else
107         if [ -d "$1/.." ] ; then
108             get_env "$1/.."
109         fi
110     fi
111 }
112
113 on_prompt() {
114     # Load a virtualenv environment if it exists in a file named .env
115     env_folder=$(get_env $(pwd))
116
117     if [ -d "$env_folder" ] ; then
118         if [[ $VIRTUAL_ENV != $env_folder ]] ; then
119             echo "Activating env '$env_folder'"
120             source "$env_folder/bin/activate"
121         fi
122     else
123         if [ -d "$VIRTUAL_ENV" ] ; then
124             deactivate
125         fi
126     fi
127 }
128
129 # Set vi keybindings
130 set -o vi
131
132 # Call on_prompt() every time the command prompt executes
133 PROMPT_COMMAND=on_prompt
134