forked from awdeorio/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
executable file
·332 lines (282 loc) · 10.6 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
#
# .bashrc
#
# awdeorio's Bash customizations
### places ####################################################################
export NFSHOME=/net/trenton/w/awdeorio
export IFSHOME=/afs/umich.edu/user/a/w/awdeorio
export WWWHOME=/net/web/w/web/u/a/awdeorio
export WWWINFERNO=/net/web/w/web/inferno
export BACKUP=${NFSHOME}/backup/manzana/awdeorio
export EECS280=/afs/umich.edu/class/eecs280
# set umask for both scp and ssh
umask 002
### Aliases ###################################################################
alias g="git"
alias du="du -sh"
alias dusort="command du -s * .* | sort -n"
alias df="df -h"
alias cdd="cd .."
alias grep="grep --color"
alias egrep="egrep --color"
alias fgrep="fgrep --color"
alias zgrep="zgrep --color"
alias igrep="grep -i"
alias wcl="wc -l"
alias rmb='echo "rm -vf *~ .*~" && rm -vf *~ .*~'
alias rmt='[ -d ${HOME}/.Trash/ ] && echo "rm -rvf ${HOME}/.Trash/*" && rm -rvf ${HOME}/.Trash/*'
alias rmd='[ -d ${HOME}/Downloads/ ] && echo "rm -rvf ${HOME}/Downloads/*" && rm -rvf ${HOME}/Downloads/*'
alias rme='[ -d ${HOME}/Desktop/ ] && echo "rm -rvf ${HOME}/Desktop/*" && rm -rvf ${HOME}/Desktop/*'
alias latex='latex -halt-on-error'
alias dftp='ssh -R 19999:localhost:22'
function dftp-get { command scp -r -P19999 "$@" localhost: ; }
alias R='R --quiet --no-save'
alias grip='grip --norefresh --browser'
#NOTE: see later for ls options
alias whatismyip='curl ipinfo.io/ip'
# OSX
if [ -d /Applications/Meld.app ]; then
alias meld='open -a /Applications/Meld.app --args'
alias chrome='open -a "/Applications/Google Chrome.app" --args'
fi
### Editor ####################################################################
export EDITOR=emacs
alias e=$EDITOR
function emacs {
# Make emacs start in the background, change window title
if [ "$1" == "-nw" ]; then
command emacs "$@"
return
elif [ `uname` = "Darwin" ]; then
/Applications/Emacs.app/Contents/MacOS/Emacs "$@" &
elif [ "$DISPLAY" ] || [ "$OS" = "Windows_NT" ]; then
command nohup emacs "$@" &
else
# for console
command emacs "$@"
fi
}
### Pager #####################################################################
alias less="less --shift 5 --ignore-case --chop-long-lines --RAW-CONTROL-CHARS --LONG-PROMPT"
export PAGER=less
export LESSOPEN="| lesspipe.sh %s"
### GPG, SSH and paswords ###################################################
# Start gpg-agent and connect SSH agent only if secret keys are available
if gpg --list-secret-keys awdeorio &> /dev/null; then
export GPG_TTY=$(tty)
gpgconf --launch gpg-agent
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
fi
# Configure Password Store
# https://www.passwordstore.org/
# http://www.tricksofthetrades.net/2015/07/04/notes-pass-unix-password-manager/
export PASSWORD_STORE_DIR=${HOME}/Dropbox/password-store
export PASSWORD_STORE_CLIP_TIME=45
### Path stuff ################################################################
# remove item from $PATH
path-remove () {
local IFS=':'
local NEWPATH
for DIR in $PATH; do
if [ "$DIR" != "$1" ]; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export PATH=${NEWPATH};
}
# add item to end of $PATH, uniquely
path-append () {
[ -d $1 ] || return 1 # make sure directory exists
path-remove $1 # remove the directory
export PATH=${PATH}:${1} # append the directory
}
# add item to beginning of $PATH, uniquely
path-prepend () {
[ -d $1 ] || return 1 # make sure directory exists
path-remove $1 # remove the directory
export PATH=${1}:${PATH} # append the directory
}
path-append /usr/local/bin
path-append /usr/local/sbin
path-append /usr/bin
path-append /usr/sbin
path-append /bin
path-append /sbin
path-prepend ${HOME}/bin
path-append ${HOME}/local/bin
path-append ${HOME}/local/sbin
path-append ${HOME}/.rvm/bin # Add RVM to PATH for scripting
if [ `whoami` != "root" ]; then
path-append /usr/caen/bin
path-append /usr/um/bin
fi
### local tool installs ########################################################
[ -d ${HOME}/local/lib ] && export LIBARY_PATH=${LIBRARY_PATH}:${HOME}/local/lib
[ -d ${HOME}/local/lib ] && export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${HOME}/local/lib
[ -d ${HOME}/local/lib ] && export LD_RUN_PATH=${LD_RUN_PATH}:${HOME}/local/lib
[ -d ${HOME}/local/include ] && export CPATH=${CPATH}:${HOME}/local/include
[ -d ${CPATH} ] && export C_INCLUDE_PATH=${C_INCLUDE_PATH}:${CPATH}
[ -d ${CPATH} ] && export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:${CPATH}
[ -d ${HOME}/local/man ] && export MANPATH=${HOME}/local/man:${MANPATH}
# OS X GNU Coreutils
path-prepend /usr/local/opt/coreutils/libexec/gnubin
[ -d /usr/local/opt/coreutils/libexec/gnuman ] && export MATHPATH=/usr/local/opt/coreutils/libexec/gnuman:$MANPATH
# local perl module installs
if [ -d ${HOME}/local/lib/perl5 ]; then
PERL5LIB=${PERL5LIB}:${HOME}/local/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi
PERL5LIB=${PERL5LIB}:${HOME}/local/lib/perl5/site_perl/5.8.8
PERL5LIB=${PERL5LIB}:${HOME}/local/lib/perl5/site_perl
PERL5LIB=${PERL5LIB}:${HOME}/local/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi
PERL5LIB=${PERL5LIB}:${HOME}/local/lib/perl5/vendor_perl/5.8.8
PERL5LIB=${PERL5LIB}:${HOME}/local/lib/perl5/vendor_perl
PERL5LIB=${PERL5LIB}:${HOME}/local/lib64/perl5/5.8.8/x86_64-linux-thread-multi
PERL5LIB=${PERL5LIB}:${HOME}/local/lib/perl5/5.8.8
export PERL5LIB;
fi
# local python module installs
if [ -d ${HOME}/local/lib/python2.6 ]; then
export PYTHONPATH=${HOME}/local/lib/python2.6:${PYTHONPATH}
export PYTHONUSERBASE=${HOME}/local
fi
export PYTHONSTARTUP=~/.pythonrc.py
path-prepend /usr/local/opt/sqlite/bin
# local Ruby
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# CCache
path-prepend /usr/lib/ccache/bin || path-prepend /usr/lib/ccache
################################################################################
# Test for an interactive shell. There is no need to set anything past this
# point for scp and rcp, and it's important to refrain from outputting
# anything in those cases.
[[ $- != *i* ]] && return
### Utility Functions #########################################################
# recursively grep for string
alias gg='grep -r . --binary-files=without-match --exclude-dir ".git" --exclude "*~" -e'
# Find a file with a pattern in name:
function ff() {
find . -type f -iwholename '*'$*'*' ;
}
# Find a file with pattern $1 in name and Execute $2 on it:
function fe() {
find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \; ;
}
# Alias for locate on OSX
if [ `uname` = "Darwin" ]; then
alias locate='mdfind -name'
fi
### Printing ##################################################################
# enscript --margins=left:right:top:bottom in postscript points
# the following gives L=R=T=B=1in
export ENSCRIPT='--media=Letter --word-wrap --margins=72:72:72:72'
### Prompt Look and Feel ######################################################
set -o emacs # emacs commandline mode
set -o history # enable up-arrow command history
export HISTIGNORE="&:ls:cd:bg:fg:ll" # ignore these commands in history
export HISTCONTROL="ignoredups" # ignore duplicates in history
export FIGNORE="~" # don't show these prefixes in tab-comp
shopt -s checkwinsize # keep LINES and COLUMNS up to date
function find_git_context() {
# Based on https://github.com/jimeh/git-aware-prompt
# Branch
local BRANCH
local GIT_BRANCH
if BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
BRANCH='detached*'
fi
GIT_BRANCH="$BRANCH"
else
GIT_BRANCH=""
fi
# '*' for dirty
local STATUS=$(git status --porcelain 2> /dev/null)
local GIT_DIRTY
if [[ "$STATUS" != "" ]]; then
GIT_DIRTY='*'
else
GIT_DIRTY=''
fi
# Concatenate
GIT_CONTEXT="${GIT_BRANCH}${GIT_DIRTY}"
}
function ps1_context {
# For any of these bits of context that exist, display them and append
# a space. Ref: https://gist.github.com/datagrok/2199506
VIRTUAL_ENV_BASE=`basename "$VIRTUAL_ENV"`
find_git_context
for v in "${GIT_CONTEXT}" \
"${debian_chroot}" \
"${VIRTUAL_ENV_BASE}" \
"${GIT_DIRTY}" \
"${PS1_CONTEXT}"; do
echo -n "${v:+$v }"
done
}
# Fancy Prompt
source ~/.bashrc_colors
if [ "$LOGNAME" == "root" ]; then
# root
export PS1='\[${bldred}\]\]\u@\h \[${bldblue}\]\W\n\$ \[${txtrst}\]'
elif [ "$SSH_CONNECTION" ]; then
# remote machines
export PS1='$(ps1_context)\[${bldcyn}\]\u@\h \[${bldblu}\]\W\n\$ \[${txtrst}\]'
else
# local machine
export PS1='\[${txtpur}\]$(ps1_context)\[${bldgrn}\]\u@\h \[${bldblu}\]\W\n\$ \[${txtrst}\]'
fi
# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
;;
esac
# Colorized output
if [[ `uname` = "Linux" ]]; then
# GNU ls
eval `dircolors -b ${HOME}/.DIR_COLORS`
alias ls="ls --color=auto --human-readable --ignore-backups"
alias ll="ls --color=auto --human-readable --ignore-backups -l"
alias la="ls --color=auto --human-readable -A"
elif [[ `uname` = "Darwin" ]] && [[ `which gls` ]]; then
# GNU ls
eval `dircolors -b ${HOME}/.DIR_COLORS`
alias ls="gls --color=auto --human-readable --quoting-style=literal --ignore-backups --ignore $'Icon\r'"
alias ll="gls --color=auto --human-readable --quoting-style=literal --ignore-backups --ignore $'Icon\r' -l"
alias la="gls --color=auto --human-readable --quoting-style=literal -A"
else
alias ls="ls -h"
alias ll="ls -h -l"
alias la="ls -h -A"
export CLICOLOR=1
fi
### Bash-completion ###########################################################
if which brew &>/dev/null && [[ -f $(brew --prefix)/etc/bash_completion ]]; then
# OS X
. $(brew --prefix)/etc/bash_completion
elif [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]]; then
. /usr/share/bash-completion/bash_completion
fi
for F in `find ${HOME}/.bash_completion.d/ -type f`; do
source $F
done
### Todotxt setup #############################################################
export TODO_DIR=${HOME}/Dropbox/lists/todo/work
alias t='todo.sh'
alias et='e ${HOME}/Dropbox/lists/todo/*/todo.txt'
# todo toggle
# switches default todo list
function tt {
TODO_DIRS=(`ls -d Dropbox/lists/todo/*/`)
NEW_DIR_IDX=0
if [ "$TODO_DIR" == "${TODO_DIRS[$NEW_DIR_IDX]}" ]; then
NEW_DIR_IDX=1;
fi
echo "TODO_DIR=${TODO_DIRS[$NEW_DIR_IDX]}"
export TODO_DIR="${TODO_DIRS[$NEW_DIR_IDX]}";
}
# Clear History at the very end
history -c