Filetype-specific tabstops
[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 # make less more friendly for non-text input files, see lesspipe(1)
25 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
26
27 # set the prompt
28 PS1='\w\$ '
29
30 # set variable identifying the chroot you work in (used in the prompt below)
31 if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
32     debian_chroot=$(cat /etc/debian_chroot)
33 fi
34
35 # enable color support of ls and also add handy aliases
36 if [ -x /usr/bin/dircolors ]; then
37     eval "`dircolors -b`"
38     alias ls='ls --color=auto'
39     alias dir='dir --color=auto'
40     alias vdir='vdir --color=auto'
41
42     alias grep='grep --color=auto'
43     alias fgrep='fgrep --color=auto'
44     alias egrep='egrep --color=auto'
45 fi
46
47 alias emacs='emacs -nw'
48 alias serve='python -m SimpleHTTPServer 8080'
49
50 export SVN_EDITOR=vim
51
52 # Enable programmable completion features (you don't need to enable
53 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
54 # sources /etc/bash.bashrc).
55 if [ -f /etc/bash_completion ]; then
56     . /etc/bash_completion
57 fi
58
59 # Add the ~/bin directory to the path.  This allows you to install simple
60 # binaries by simply moving them into ~/bin.
61 if [ -d $HOME/bin ]; then
62         PATH="$HOME/bin:$PATH"
63         export PATH
64 fi
65
66 # Put $HOME/.cabal/bin on the path. Installing cabal doesn't
67 # automatically put installed packages on the path.
68 if [ -d $HOME/.cabal/bin ]; then
69     PATH="$HOME/.cabal/bin:$PATH"
70     export PATH
71 fi
72
73 # Put /usr/local/bin (where homebrew installs stuff) before /usr/bin on the
74 # path. This means that if a program exists at both locations, calls to that
75 # program will use the homebrew version rather than the system version.
76 PATH="/usr/local/bin:$PATH"
77 export PATH
78
79 # Run a machine-specific bashrc (if it exists).
80 if [ -f $HOME/.bashrc_local ]; then
81         source $HOME/.bashrc_local
82 fi
83
84 # Install RVM if it's not installed.
85 if [ ! -f $HOME/.rvm/scripts/rvm ]; then
86     bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
87 fi
88
89 # Load RVM into shell session.
90 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
91
92 # Automatically open screen.
93 # The if statement prevents it from recursing (since screen opens bash).
94 if [ $TERM != screen ]; then
95         screen
96 fi
97
98 # Gets a directory named .env if it exists in the currend directory or any of its parents
99 get_env() {
100     if [ -d "$1/.env" ] ; then
101         echo "$1/.env"
102     else
103         if [ -d "$1/.." ] ; then
104             get_env "$1/.."
105         fi
106     fi
107 }
108
109 on_prompt() {
110     # Load a virtualenv environment if it exists in a file named .env
111     env_folder=$(get_env $(pwd))
112
113     if [ -d "$env_folder" ] ; then
114         if [[ $VIRTUAL_ENV != $env_folder ]] ; then
115             echo "Activating env '$env_folder'"
116             source "$env_folder/bin/activate"
117         fi
118     else
119         if [ -d "$VIRTUAL_ENV" ] ; then
120             deactivate
121         fi
122     fi
123 }
124
125 # Set vi keybindings
126 set -o vi
127
128 # Call on_prompt() every time the command prompt executes
129 PROMPT_COMMAND=on_prompt
130