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