public
Description: my configuration files
Homepage:
Clone URL: git://github.com/fnando/dotfiles.git
dotfiles / bash_profile
100644 229 lines (200 sloc) 6.827 kb
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
export PATH="/usr/local/ruby/active/bin:$PATH"
export PATH="/usr/local/git/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export PATH="/usr/local/erlang/bin:/usr/local/couchdb/bin:/usr/local/spidermonkey/bin:/usr/local/erlang/lib/erlang/lib/rabbitmq_server-1.6.0/sbin:$PATH"
export PATH="/usr/local/prince/bin:$PATH"
export EVENT_NOKQUEUE=1
export MANPATH=/usr/local/git/man:$MANPATH
export EDITOR="/usr/bin/mate -wl1"
export SVN_EDITOR="/usr/bin/mate -wl1"
export HISTCONTROL=erasedups
export HISTFILESIZE=100000
export HISTSIZE=${HISTFILESIZE}
export GREP_OPTIONS="--color=auto"
export GREP_COLOR="4;33"
export CDPATH=.:~:~/Sites:~/Sites/github
export CDHISTORY="/tmp/cd-${USER}"
 
# Amazon EC2
export EC2_HOME="/Users/fnando/.ec2"
export EC2_PRIVATE_KEY="$EC2_HOME/pk.pem"
export EC2_CERT="$EC2_HOME/cert.pem"
export EC2_AMI_HOME="$EC2_HOME/ec2-ami-tools"
export PATH="$EC2_HOME/bin:$EC2_AMI_HOME/bin:$PATH"
export JAVA_HOME="/Library/Java/Home"
 
# Colours
BLUE="\[\033[0;34m\]"
NO_COLOR="\[\e[0m\]"
GRAY="\[\033[1;30m\]"
GREEN="\[\033[0;32m\]"
LIGHT_GRAY="\[\033[0;37m\]"
LIGHT_GREEN="\[\033[1;32m\]"
LIGHT_RED="\[\033[1;31m\]"
RED="\[\033[0;31m\]"
WHITE="\[\033[1;37m\]"
YELLOW="\[\033[0;33m\]"
 
source ~/.git_completion.sh
source ~/.bash_completion.sh
 
alias ls="ls -G"
alias ll="ls -Glahs"
alias colors="sh ~/.colors.sh"
alias psgrep="ps aux | egrep -v egrep | egrep"
alias showip="ifconfig | grep broadcast | sed 's/.*inet \(.*\) netmask.*/\1/'"
alias myip="curl http://www.whatismyip.com/automation/n09230945.asp"
alias lock="/System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSession -suspend"
alias quicksilver="open /Applications/Quicksilver.app"
alias qs="quicksilver"
alias top="top -o cpu"
alias irb="irb --readline --prompt-mode simple"
alias mysql="mysql --auto-rehash=TRUE"
alias ni="lsof -i -Pn"
alias search="find vendor/plugins -follow -name '*' | xargs grep "
 
shopt -s cdspell
shopt -s nocaseglob
shopt -s checkwinsize
shopt -s dotglob
shopt -s extglob
set -o ignoreeof
unset MAILCHECK
 
# start apache from mamp
mamp() {
    /Applications/MAMP/Library/bin/apachectl start
    ln /tmp/mysql.sock /Applications/MAMP/tmp/mysql/mysql.sock
}
 
# reload source
reload() { source ~/.bash_profile; }
 
# list directory after cd; also save the last directory
# and open it when a new tab is created
cd() {
    builtin cd "${@:-$HOME}" && ls && pwd > $CDHISTORY;
}
 
dir=$(cat $CDHISTORY)
 
if [ -f $CDHISTORY ]; then
    if [ -d "$dir" ]; then
        builtin cd "$dir" && clear
    fi
fi
 
# Specify which ruby version to use
# Here's how my ruby is installed:
#
# /usr/local/ruby/1.9.1-p243
# /usr/local/ruby/1.8.7-p174
# /usr/local/ruby/1.8.6-p383
# /usr/local/ruby/active
#
# The active directory is a symlink to the active
# ruby version. This is also on the $PATH.
#
# export PATH="/usr/local/ruby/active/ruby:$PATH"
use_ruby() {
  local root="/usr/local/ruby"
  local version="invalid"
  
  if [ "$1" = "191" ]; then
    version="1.9.1-p243"
  elif [ "$1" = "187" ]; then
    version="1.8.7-p174"
  elif [ "$1" = "186" ]; then
    version="1.8.6-p383"
  fi
  
  local rubydir="$root/$version"
  
  if [ -d $rubydir ]; then
    echo "Activating Ruby $version"
    sudo rm $root/active && sudo ln -s $root/$version $root/active
    renv use base
  else
    echo "Specify a Ruby version: 186, 187, 191"
  fi
}
 
# enter a recently created directory
mkdir() { /bin/mkdir $@ && eval cd "\$$#"; }
 
# get the tinyurl
tinyurl () {
    local tmp=/tmp/tinyurl
    rm $tmp 2>1 /dev/null
    wget "http://tinyurl.com/api-create.php?url=${1}" -O $tmp 2>1 /dev/null
    cat $tmp | pbcopy
}
 
# complete rake tasks
complete -C ~/.rake_completion.rb -o default rake
 
# complete renv envs
_renvcomplete() {
  COMPREPLY=($(compgen -W "`NAME=${COMP_WORDS[COMP_CWORD]} renv complete`"))
  return 0
}
 
complete -o default -o nospace -F _renvcomplete renv
 
# github repository cloning
# usage:
# github has_permalink ~> will clone $USER repositories
# github username repository ~> will clone someone else's
github() {
    if [ $# = 1 ]; then
        git clone git@github.com:$USER/$1.git;
        builtin cd $1 && ls;
    elif [ $# = 2 ]; then
        git clone git://github.com/$1/$2.git;
        builtin cd $2 && ls;
    else
        echo "Usage:";
        echo " github <repo> ~> will clone $USER's <repo>";
        echo " github <user> <repo> ~> will clone <user>'s <repo>";
    fi
}
 
git-prompt () {
    local BRANCH=`git branch 2> /dev/null | grep \* | sed 's/* //'`
    local STATUS=`git status 2>/dev/null`
    local PROMPT_COLOR=$GREEN
    local STATE=" "
    local BEHIND="# Your branch is behind"
    local AHEAD="# Your branch is ahead"
    local UNTRACKED="# Untracked files"
    local DIVERGED="have diverged"
    local CHANGED="# Changed but not updated"
    local TO_BE_COMMITED="# Changes to be committed"
    
    if [ "$BRANCH" != "" ]; then
        if [[ "$STATUS" =~ "$DIVERGED" ]]; then
            PROMPT_COLOR=$RED
            STATE="${STATE}${RED}↕${NO_COLOR}"
        elif [[ "$STATUS" =~ "$BEHIND" ]]; then
            PROMPT_COLOR=$RED
            STATE="${STATE}${RED}↓${NO_COLOR}"
        elif [[ "$STATUS" =~ "$AHEAD" ]]; then
            PROMPT_COLOR=$RED
            STATE="${STATE}${RED}↑${NO_COLOR}"
        elif [[ "$STATUS" =~ "$CHANGED" ]]; then
            PROMPT_COLOR=$RED
            STATE=""
        elif [[ "$STATUS" =~ "$TO_BE_COMMITED" ]]; then
            PROMPT_COLOR=$RED
            STATE=""
        else
            PROMPT_COLOR=$GREEN
            STATE=""
        fi
        
        if [[ "$STATUS" =~ "$UNTRACKED" ]]; then
            STATE="${STATE}${YELLOW}*${NO_COLOR}"
        fi
        
        PS1="\n[\u] ${YELLOW}\w\a${NO_COLOR} (${PROMPT_COLOR}${BRANCH}${NO_COLOR}${STATE})\n$ "
    else
        PS1="\n[\u] ${YELLOW}\w\a${NO_COLOR}\n\$ "
    fi
}
 
# taken from http://github.com/bryanl/zshkit/
git-track () {
    local BRANCH=`git branch 2> /dev/null | grep \* | sed 's/* //'`
git config branch.$BRANCH.remote origin
git config branch.$BRANCH.merge refs/heads/$BRANCH
echo "tracking origin/$BRANCH"
}
github-url () { git config remote.origin.url | sed -En 's/git(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\3\/\4/p'; }
github-go () { open $(github-url); }
git-scoreboard () { git log | grep '^Author' | sort | uniq -ci | sort -r; }
manp () { man -t $* | ps2pdf - - | open -f -a Preview; }
 
export LESS_TERMCAP_mb=$'\E[04;33m'
export LESS_TERMCAP_md=$'\E[04;33m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[00;32m'
 
PROMPT_COMMAND=git-prompt
 
export RENVDIR="$HOME/.renv"
export PATH="$RENVDIR/active/bin:$PATH"
export GEM_PATH="$RENVDIR/active/lib"