-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_bashrc
501 lines (415 loc) · 11 KB
/
dot_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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
#===============================================================
#
# PERSONAL $HOME/.bashrc FILE for bash-2.04 (or later)
# by Emmanuel Rouat
#
# This file is read (normally) by interactive shells only.
# Here is the place to define your aliases, functions and
# other interactive features like your prompt.
#
# This file was designed for Solaris
#
#===============================================================
set +u
if [ -z "$PS1" -o $TERM = "DUMB" ]; then
INTERACTIVE=0
else
INTERACTIVE=1
fi
set -o nounset
GNU=0
OSX=0
FINK=0
export EDITOR="vim"
export SVN_EDITOR="vim"
if [ `uname -s` = "Darwin" ]; then
OSX=1
if [ -r /sw/bin/init.sh ]; then
. /sw/bin/init.sh
export PATH=/usr/local/bin:$PATH
FINK=1
fi
fi
if [ -d /usr/local/opt/coreutils/libexec/gnubin ]; then
HOMEBREW=1
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
export MANPATH=/usr/local/opt/coreutils/libexec/gnuman:$MANPATH
fi
if [ -d ~/Library/Python/2.7/bin ]; then
export PATH=~/Library/Python/2.7/bin:$PATH
fi
if [ -d ~/Library/Python/3.6/bin ]; then
export PATH=~/Library/Python/3.6/bin:$PATH
fi
if [ -d ~/Library/Python/3.7/bin ]; then
export PATH=~/Library/Python/3.7/bin:$PATH
fi
if [ -d ~/.local/bin ]; then
export PATH=~/.local/bin:$PATH
fi
if [ -d ~/bin ]; then
export PATH=~/bin:$PATH
fi
if [ -d ~/.pyenv ]; then # && [ -z $PYENV_VIRTUALENV_INIT ]; then
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
vmake () {
local version=${2:-3}
if [ -d ~/.virtualenvs/$1 ]; then
echo $1 already exists
return -1
fi
python${version} -m venv ~/.virtualenvs/$1
}
vactivate () {
source ~/.virtualenvs/$1/bin/activate
}
_vactivate () {
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=`ls --color=none ~/.virtualenvs/`
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
function exists_and_execs()
{
FNAME=`which $1`
[ -n "$FNAME" -a -x "$FNAME" ]
}
complete -F _vactivate vactivate
#don't do anything if it's a dumb terminal because it could cause scp to fail
#[ -z "$PS1" -o $TERM == "dumb" ] && return
#-----------------------------------
# Source global definitions (if any)
#-----------------------------------
if [ -f /etc/bashrc ]; then
. /etc/bashrc # Read system bash init file, if exists.
fi
if [ -d "${FREE:=''}/bin" ]; then
GNU=1
fi
if [ `uname` == "Linux" ]; then
GNU=1
fi
if [ -x `which dircolors` ] ; then # use gnu/free stuff
eval `dircolors`
fi
#-------------------------------------------------------------
# Automatic setting of $DISPLAY (if not set already)
# This works for linux and solaris - your mileage may vary....
#-------------------------------------------------------------
#if [ -z ${DISPLAY:=""} ]; then
# DISPLAY=$(who am i)
# DISPLAY=${DISPLAY%%\!*}
if [ -n ${DISPLAY:=''} ]; then
export DISPLAY=$DISPLAY
else
export DISPLAY="" # fallback
fi
#fi
#---------------
# Some settings
#---------------
set -o notify
#set -o noclobber
#set -o ignoreeof
set -o nounset
#set -o xtrace # useful for debuging
shopt -s cdspell
#shopt -s cdable_vars
shopt -s checkhash
shopt -s checkwinsize
shopt -s mailwarn
shopt -s sourcepath
shopt -s no_empty_cmd_completion
shopt -s histappend histreedit
shopt -s extglob # useful for programmable completion
#-----------------------
# Greeting, motd etc...
#-----------------------
# Define some colors first:
red='\033[0;31m'
RED='\033[1;31m'
blue='\033[0;34m'
BLUE='\033[1;34m'
cyan='\033[0;36m'
CYAN='\033[1;36m'
NC='\033[0m' # No Color
if [ $INTERACTIVE -eq 1 ]; then
# Looks best on a black background.....
echo -en "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY "
if [ -z $DISPLAY ] ; then
echo -ne "${RED}off${NC}\n";
else
echo -en "on ${RED}$DISPLAY${NC}\n"
fi
date
function _exit() # function to run upon exit of shell
{
echo -e "${RED}MMmm I smell brains.${NC}"
}
trap _exit 0
fi
#---------------
# Shell prompt
#---------------
function fastprompt()
{
unset PROMPT_COMMAND
case $TERM in
xterm | rxvt | dtterm )
PS1="[\h] \W > \[\033]0;[\u@\h] \w\007\]" ;;
*)
PS1="[\h] \W > " ;;
esac
}
function powerprompt()
{
_powerprompt()
{
RET=$?
#echo -e $RET
if [ $RET -eq 0 ]; then
COLOR='1;36m'
else
COLOR='1;31m'
fi
if [ -n "${TMUX:=""}" ]; then
tmux setenv TMUXPWD_$(tmux display -p "#I_#P") "$PWD"
tmux setenv VIRTUAL_ENV_$(tmux display -p "#I_#P") "${VIRTUAL_ENV:=""}"
tmux refresh-client -S
fi
case $TERM in
xterm* | dtterm | rxvt )
echo -n -e "\033]0;$USER@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007";;
esac
}
PROMPT_COMMAND=_powerprompt
_powerprompt
EPS1='\$'
case $TERM in
xterm* | dtterm | rxvt )
local SPS1="\[\033]0;\u@\h:\w\007\]";;
# linux | vt100 )
# SPS1="\u@\h:\w";;
* )
local SPS1="";;
esac
SPS1=""
PS1="${SPS1}\u@\h:\w\[\033[\$COLOR\]$EPS1\[${NC}\] "
}
# this is the default prompt - might be slow
# If too slow, use fastprompt instead....
if [ $INTERACTIVE -eq 1 ]; then
powerprompt
fi
#===============================================================
#
# ALIASES AND FUNCTIONS
#
# Arguably, some functions defined here are quite big
# (ie 'lowercase') but my workstation has 512Meg of RAM, so
# If you want to make this file smaller, these functions can
# be converted into scripts.
#
#===============================================================
#-------------------
# Personnal Aliases
#-------------------
if exists_and_execs "vim"; then
alias vi=vim
fi
if exists_and_execs "nvim"; then
alias vi=nvim
alias vim=nvim
fi
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias path='echo -e ${PATH//:/\\n}'
alias finch='screen -S finch -p finch -RaAD -e^bB finch'
alias irssi='screen -S irssi -p irssi -RaAD -e^bB irssi -ckt'
#-----------------------------------------
# Environment dependent aliases/variables
#-----------------------------------------
export ircname=hbar
export PAGER="less -r"
export EDITOR="vim -X"
if [ $GNU -eq 1 ] ; then # use gnu/free stuff
alias vi='vi -X'
alias csh='tcsh'
alias du='du -h'
alias df='df -kh'
alias ls='ls -h --color=always'
alias more='less'
elif [ $OSX -eq 1 ]; then
export CLICOLOR=1
export SVN_EDITOR=vi
if [ $FINK -eq 1 ]; then
if [ -x '/sw/bin/ls' ]; then
alias ls='/sw/bin/ls --color=always'
fi
alias du='du -h'
alias df='df -kh'
fi
if [ $FINK -eq 1 -o $HOMEBREW -eq 1 ]; then
alias ls='ls -h --color=always'
fi
else # use regular solaris stuff
alias df='df -k'
#alias ls='ls -F'
fi
#----------------
# a few fun ones
#----------------
function xtitle ()
{
case $TERM in
xterm* | dtterm | rxvt)
echo -n -e "\033]0;$HOSTNAME:$*\007" ;;
*) ;;
esac
}
alias top='xtitle Processes on $HOSTNAME && top'
alias make='xtitle Making $(basename $PWD) ; make'
alias ncftp="xtitle ncFTP ; ncftp"
#---------------
# and functions
#---------------
function man ()
{
xtitle The $(basename $1|tr -d .[:digit:]) manual
/usr/bin/man -a "$*"
}
#-----------------------------------------
# Environment dependent functions
#-----------------------------------------
function dislink()
{
if [ -f $1 -a ! -f .$1.tmp ]; then
cp -L $1 .$1.tmp
if [ ! -f .$1.tmp ]; then
echo copy didn\'t work
return
fi
unlink $1
mv .$1.tmp $1
else
echo either file does not exist or tmp file exists
fi
}
#=========================================================================
#
# PROGRAMMABLE COMPLETION - ONLY IN BASH-2.04
#
#=========================================================================
if [ "${BASH_VERSION%.*}" \< "2.04" ]; then
echo "No programmable completion available"
return
fi
shopt -s extglob # necessary
complete -A hostname rsh rcp telnet rlogin r ftp ping disk
complete -A command nohup exec eval trace truss strace sotruss gdb
complete -A command command type which
complete -A export printenv
complete -A variable export local readonly unset
complete -A enabled builtin
complete -A alias alias unalias
complete -A function function
complete -A user su mail finger
complete -A helptopic help # currently same as builtins
complete -A shopt shopt
complete -A stopped -P '%' bg
complete -A job -P '%' fg jobs disown
complete -A directory mkdir rmdir
complete -f -X '*.gz' gzip
complete -f -X '!*.ps' gs ghostview gv
complete -f -X '!*.pdf' acroread
complete -f -X '!*.+(gif|jpg|jpeg|GIF|JPG|bmp)' xv gimp
_make_targets ()
{
local mdef makef gcmd cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# if prev argument is -f, return possible filename completions.
# we could be a little smarter here and return matches against
# `makefile Makefile *.mk', whatever exists
case "$prev" in
-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;
esac
# if we want an option, return the possible posix options
case "$cur" in
-) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
esac
# make reads `makefile' before `Makefile'
if [ -f makefile ]; then
mdef=makefile
elif [ -f Makefile ]; then
mdef=Makefile
else
mdef=*.mk # local convention
fi
# before we scan for targets, see if a makefile name was specified
# with -f
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -*f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion
break
fi
done
[ -z "$makef" ] && makef=$mdef
# if we have a partial word to complete, restrict completions to
# matches of that word
if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
# if we don't want to use *.mk, we can take out the cat and use
# test -f $makef and input redirection
COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
}
complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake
_configure_func ()
{
case "$2" in
-*) ;;
*) return ;;
esac
case "$1" in
\~*) eval cmd=$1 ;;
*) cmd="$1" ;;
esac
COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) )
}
complete -F _configure_func configure
_killps ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
PSBIN=`which ps`
# get a list of processes (the first sed evaluation
# takes care of swapped out processes, the second
# takes care of getting the basename of the process)
COMPREPLY=( $( $PSBIN -u $USER -o comm | \
sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \
awk '{if ($0 ~ /^'$cur'/) print $0}' ))
return 0
}
complete -F _killps killps
function r() {
if [[ -n $TMUX ]]; then
NEW_SSH_AUTH_SOCK=`tmux showenv | grep ^SSH_AUTH_SOCK | cut -d= -f2`
if [[ -n $NEW_SSH_AUTH_SOCK ]] && [[ -S $NEW_SSH_AUTH_SOCK ]]; then
export SSH_AUTH_SOCK=$NEW_SSH_AUTH_SOCK
fi
export DISPLAY=`tmux showenv | grep ^DISPLAY | cut -d= -f2`
fi
}
[ -f ~/.bashrc.local ] && source ~/.bashrc.local
if [ $INTERACTIVE -eq 1 ]; then
set +u
w
fi