-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.bashrc
293 lines (214 loc) · 8.19 KB
/
.bashrc
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# This file sets up a quality Bash environment both on Linux and OSX.
# WARNING WARNING
# this file is obsolete.
# interactive use is moving to zsh.
# TODO: something in here screws up filename completion, i.e. "30 for 30"
# TODO: sort out what should be in .profile and what should be in .bashrc
# bash manpage, in the INVOCATION section
# TODO: set a timeout on the prompt git stuff, it can take forever on macosx
# .f stands for dotfiles. .f diff, .f log, .f pull, etc.
alias .f="git --work-tree=$HOME --git-dir=$HOME/.dotfiles.git"
complete -o default -o nospace -F _git .f
#
# Environment
#
# my home dir is behind a symlink, sometimes bash doesn't recognize this.
# force the prompt to show the home dir when you're home.
[ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] && cd
export LESS="--RAW-CONTROL-CHARS" # interpret any embedded ansi escapes
export PAGER='less' # use less to view manpages, etc
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # let less show non-text files too
export PS1="\\u@\\h \\w\\$ " # simple prompt shows user, host and path
[ -d "$HOME/bin" ] && export PATH="$HOME/bin:$PATH"
[ -d "$HOME/Dropbox/bin" ] && export PATH="$HOME/Dropbox/bin:$PATH"
[ -d "/usr/local/heroku/bin" ] && export PATH="$PATH:/usr/local/heroku/bin"
# Disable annoying ~ expansion
# http://www.linuxquestions.org/questions/linux-software-2/how-to-stop-bash-from-replacing-%7E-with-home-username-643162/#post3162026
_expand() { return 0; }
__expand_tilde_by_ref() { return 0; }
# flush commans to ~/.bash_history immediately and use a git-friendly bash prompt
[ "$PS1" ] && source ~/.bash_prompt
PROMPT_COMMAND="history -a; prompt_function"
#
# Colors
#
if [ -x /usr/bin/dircolors ]; then
# use ~/.dircolors if user has specified one
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
fi
# --exclude-dir isn't supported on OSX Lion and Brew doesn't make it easy to fix.
# --exclude-dir=.git --exclude-dir=.svn --exclude-dir=log
export GREP_OPTIONS='--color=auto --exclude=tags --exclude=TAGS --exclude=*.min.js'
#
# History
#
shopt -s histappend # Append to history file instead of overwriting
shopt -s cmdhist # store multiline commands as 1 line
shopt -s checkwinsize # check the window size after each command and, if necessary, update the values of LINES and COLUMNS.
HISTSIZE=1000
HISTFILESIZE=100000
#
# Aliases
#
alias ..='cd ..'
alias ...='cd ../..'
alias sl=ls
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lF'
alias lla='ls -alF'
# sorted du -s (size on disk of named directory)
dus() { du -hs "$@" | sort -rh; }
alias tf='tail -f'
alias gre=grep # darn you vim's :gre command
alias mak=make # and :mak
alias MP='make program' # for avr parts
alias MPA='make program DEBUGGING=always'
alias MPP='make program ENVIRONMENT=production'
# calculator: "? 3+13*3" will print 42
# TODO: any way to store the output in a bash variable?
? () { echo "$@" | bc -l; }
# allow abbyy to ocr this file
alias snapify='exiftool -creator="ScanSnap Manager #iX500"'
#
# Git Aliases
#
# How this works: https://github.com/bronson/dotfiles/issues/1
__define_git_completion () {
eval "
_git_$2_shortcut () {
COMP_LINE=\"git $2\${COMP_LINE#$1}\"
let COMP_POINT+=$((4+${#2}-${#1}))
COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
let COMP_CWORD+=1
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
_git_$2
}
"
}
__git_shortcut () {
type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
local args=${@: 3}
alias $1="git $2 $args"
complete -o default -o nospace -F _git_$2_shortcut $1
}
__git_shortcut ga add
__git_shortcut gap add -p
__git_shortcut gb branch --column
__git_shortcut gba branch -a
__git_shortcut gbr branch --sort=committerdate # recent
__git_shortcut gco checkout
__git_shortcut gci commit -v
__git_shortcut gcia commit -a -v
__git_shortcut gcane commit --amend --no-edit
__git_shortcut gd diff
__git_shortcut gdc diff --cached
__git_shortcut gds diff --stat
__git_shortcut gfo fetch origin
__git_shortcut gfu fetch upstream
__git_shortcut gl log
__git_shortcut glp log -p
__git_shortcut gls log --stat
__git_shortcut gm merge
__git_shortcut gmom merge origin/master
__git_shortcut gmum merge upstream/master
__git_shortcut gpl pull
__git_shortcut gplom pull origin master
__git_shortcut gplum pull upstream master
__git_shortcut gps push
__git_shortcut gpsom push origin master
alias gs='git status -sb' # no completion necessary
alias gsa='git stash apply'
__git_shortcut grH reset --hard HEAD
if [ "Darwin" == "$(uname)" ]; then
#
# OSX Hacks
#
export LSCOLORS="GxGxBxDxCxEgEdxbxgxcxd"
export CLICOLOR=true
# Putting user binaries in system directoris is straight up insane
# but they say otherwise there will be lots of breakage. Seems unlikely?
# BREW_HOME=~/.brew is definitely worth testing one day.
export BREW_HOME=/usr/local # recommended location
export PATH="$BREW_HOME/bin:/usr/local/sbin:$PATH" # brew
export PATH="$PATH:/usr/local/mysql/bin" # default osx mysql dmg
command -v brew >/dev/null 2>&1 && [ -f "$(brew --prefix)/etc/bash_completion" ] && source "$(brew --prefix)/etc/bash_completion"
command -v brew >/dev/null 2>&1 && [ -f "$(brew --prefix)/etc/bash_completion.d" ] && source "$(brew --prefix)/etc/bash_completion.d"
alias gvim=mvim
# I alias gs to git status, no idea why homebrew doesn't allow full name
alias ghostscript=/usr/local/bin/gs
else
#
# emulate some things that osx gets right
alias open=xdg-open
alias mvim=gvim
fi
#
# Completion
#
# Install the bash-completion package on MacOS X using port or brew.
#if [ -f /etc/bash_completion ]; then
#source /etc/bash_completion
#fi
if [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
source /usr/local/etc/bash_completion.d/git-completion.bash
fi
# For some reason macports git doesn't install its completion file.
if [ -f /opt/local/share/doc/git-core/contrib/completion/git-completion.bash ]; then
source /opt/local/share/doc/git-core/contrib/completion/git-completion.bash
fi
#
# node.js
#
[ -d ~/.nvm ] && . ~/.nvm/nvm.sh
export PATH="node_modules/.bin:$HOME/node_modules/.bin:$PATH"
#
# Ruby
#
# using chruby and ruby-install
[ -f /usr/local/share/chruby/chruby.sh ] && source /usr/local/share/chruby/chruby.sh
[ -f /usr/local/share/chruby/auto.sh ] && source /usr/local/share/chruby/auto.sh
[ -f /usr/local/share/chruby-default-gems.sh ] && source /usr/local/share/chruby-default-gems.sh
# do everything I can think of to make slowass & useless rdoc go away
export RUBY_CONFIGURE_OPTS=--disable-install-doc
ruby-install() { /usr/local/bin/ruby-install "$@" -- --disable-install-rdoc; }
alias be='bundle exec'
alias rc='bin/rails console'
alias rgen='bin/rails generate'
alias rr='bin/rspec'
alias rs='rm -rf tmp/cache log/development.log && bin/rails server'
#
# Android
#
if [ -d ~/Android/sdk ]; then
export ANDROID_HOME="$HOME"/Android/sdk
export ANDROID_NDK_HOME="$HOME"/Android/sdk/ndk-bundle
# export ANDROID_NDK_HOME="$HOME"/Android/crystax-ndk-10.3.2
export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_NDK_HOME"
fi
#
# Editors
#
export EDITOR='vim'
# use gvim instead of terminal vim to edit bundles
export GEM_EDITOR=gvim BUNDLER_EDITOR=gvim
export ATOM_REPOS_HOME="$HOME" # otherwise apm clones to ~/github
#
# Google Cloud
#
alias gc=gcloud
[ -f /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc ] && \
source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc
[ -f /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc ] &&
source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc
#
# Etc
#
[ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env"
export PGDATA='/usr/local/var/postgres'
#
# Private Customizations
#
[ -f ~/.bashrc-private ] && . ~/.bashrc-private