-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
executable file
·333 lines (284 loc) · 10.2 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
333
#!/bin/bash
# Ola's startup scripts (~/.bashrc)
# this .bashrc should be accompanied by a
# .bash_profile containing one line
# [ -f "$HOME/.bashrc" ] && . $HOME/.bashrc
#
usernames="ola"
# Figure out what our username is on this system
case " $usernames " in
*" $USER "*)
username=$USER
;;
*)
for i in $all_usernames; do
eval [ -r ~$i/.bashrc ] && { username=$i; break; }
done
;;
esac
unset PROMPT_COMMAND # We have no prompt command; Useless and slow.
ulimit -c 0 # Remove this if you like core files :)
set -o vi
unalias -a #turn off all other aliases
#alias x='startx -- +xinerama'
alias x='startx'
#alias ls='ls --color'
alias la='ls -a'
alias ll='ls -l'
alias verify='ssh-add ~/.ssh/id_dsa'
alias destruct='ssh-add -D'
alias ant='cvs up >& /dev/null; /usr/bin/ant'
#alias resource='killall -USR1 bash'
# todo support
export TODO=~/Dropbox/todo
function todo() { if [ $# == "0" ]; then cat $TODO; else echo "• $@" >> $TODO; fi }
function todone() { sed -i -e "/$*/d" $TODO; }
# make all users bashes reread ~/.bash_profile
resource()
{
for i in $(ps -ef | grep bash | grep "^ola" | awk '{print $2}');
do
kill -USR1 $i
done
}
# See what OS we're using... standard commands in one may not work in another.
case $(uname -s) in
Linux) os=linux ;;
*[bB][Ss][Dd]) os=bsd ;;
*) os=unix ;;
esac
# ls colors
if [ "$os" = "linux" ]; then
export LS_COLORS="no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:*.tar=01;31:*.tgz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.rpm=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.pdf=01;35:*.h=00;31:*.cpp=00;36:*.c=00;36:ex=01;32"
alias ls='ls --color'
else
export CLICOLOR=1
export TERM=xterm-256color
export LSCOLORS=GxFxCxDxBxegedabagaced
#alias ls='ls -F'
fi
# This addpath adds a path only if it's not already in $PATH and it's a dir.
function myaddpath () {
case :$PATH: in *:$1:*) ;; *) [ -d $1 ] && PATH="$PATH${PATH:+:}$1" ;; esac
}
# Set path properly. Insert all paths you'd ever want to have in your $PATH.
_IFS="$IFS"; IFS=:
_PATH="$PATH"; PATH=
[ -e /usr/local/bin/go ] && GOBINS="$(/usr/local/bin/go env GOROOT)/bin"
for path in $HOME/bin /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin \
/sbin /usr/X11R6/bin usr/share/texmf/bin /usr/local/opt/go/bin \
/usr/lib/jdk1.3.1/bin $HOME/go/bin \
$_PATH; do
myaddpath $path
done
export PATH; unset _PATH
IFS=$_IFS; unset _IFS
# for whatever reason this sets the TERM=dumb which removes colors in the Terminal on OS X
#eval [ -f "$HOME/goroot/golang-crosscompile/crosscompile.bash" ] && eval source "$HOME/goroot/golang-crosscompile/crosscompile.bash"
#
#export GOROOT=/usr/local/go
export GOPATH=$HOME/go
case $HOSTNAME in
*silver*)
HOST="silver"
;;
*scrape*)
HOST="scrape"
;;
esac
export OLAOLA=SHISHI
export HOST=${HOST:-${HOSTNAME%%.*}}
# This ensures that when using su, we will still run our own bashrc
[ "$os" = "linux" ] && alias su="su -c 'bash -rcfile ~$username/.bashrc'"
# put this ~/.inputrc
# set bell-style none
eval [ -f \~$username/.inputrc ] && eval export INPUTRC=\~$username/.inputrc
C_WHTE="\[\033[0;37m\]" C_RED="\[\033[0;31m\]"
C_GREN="\[\033[0;32m\]" C_BRWN="\[\033[0;33m\]"
C_BLUE="\[\033[0;34m\]" C_PINK="\[\033[0;35m\]"
C_NEON="\[\033[0;36m\]" C_WHTE="\[\033[0;37m\]"
# FIXME: go thru and correct the colors later
BLACK="\[\033[0;30m\]"
BLUE="\[\033[0;34m\]"
GREEN="\[\033[0;32m\]"
CYAN="\[\033[0;36m\]"
RED="\[\033[0;31m\]"
PURPLE="\[\033[0;35m\]"
BROWN="\[\033[0;33m\]"
LIGHT_GRAY="\[\033[0;37m\]"
DARK_GRAY="\[\033[1;30m\]"
LIGHT_BLUE="\[\033[1;34m\]"
LIGHT_GREEN="\[\033[1;32m\]"
LIGHT_CYAN="\[\033[1;36m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
YELLOW="\[\033[1;33m\]"
WHITE="\[\033[1;37m\]"
NC="\[\033[0m\]"
#PS1="$COLOR3\u$C_GREN@$C_PINK\h$C_BLUE|\$(date +%T)|$C_PINK\w$C_BLUE|$C_WHTE\n\$ "
# no puts "KEYS" if keys are active
#PS1="$COLOR3\u$C_GREN@$C_PINK\h\$( if \$(ssh-add -l 2>/dev/null | grep "^[:alnum:]*" > /dev/null; then echo \"$C_NEON(KEYS)\") fi $C_BLUE|\$(date +%T)|$C_PINK\w$C_BLUE|$C_WHTE\n\$ "
#PS1="$COLOR3\u$C_GREN@$C_PINK\h\$( "`ssh-add -l | grep 'The agent has no id' >& /dev/null`" -gt 0 ] && echo '-KEYS-';)$C_BLUE|\$(date +%T)|$C_PINK\w$C_BLUE|$C_WHTE\n\$ "
if [ $HOSTNAME = "silver" ];
then
PS1="$COLOR3\u$C_GREN@$C_PINK\h\$([ \"\$(ssh-add -l)\" = \"The agent has no identities.\" ] || echo \"$C_NEON(KEYS)\")$C_BLUE|\$(date +%T)|$C_PINK\w$C_BLUE|$C_WHTE\n\$ "
else
PS1="$COLOR3\u$C_GREN@$C_PINK\h$C_BLUE|\$(date +%T)|$C_PINK\w$C_BLUE|$C_WHTE\n\$ "
fi
export PS1
export PS2='> '
export ignoreeof=0
export checkwinsize=1 # update LINES and COLUMNS
export cmdhist=1 # multiple repeated cmds go in one
export dotglob=1 # expand . files in expansions please
export cdspell=1 # fix cd <dir> spell errors
export histappend=0 # don't write the history file
export EDITOR='vim'
export REPLYTO='ola.nordstrom@gmail.com'
export COLORFGBG="lightgray;black" # needed for the slang library, hench mutt "default" color
export CALENDAR_DIR="~/.calendar"
# umask settings
# umask 002 makes files -rw-rw-r-- and directories -rwxrwxr-x
# umask 022 makes files -rw-r--r-- and directories -rwxr-xr-x
# umask 006 makes files -rw-rw---- and directories -rwxrwx---
# umask 066 makes files -rw------- and directories -rwx------
umask 066
# Ola linux eterm
[ "$TERM" = xterm ] && export PROMPT_COMMAND='echo -ne "\033]0;ETerm .:. ${PWD}\007"'
#Mac term is xterm-256color
[ "$TERM" = xterm-256color ] && export PROMPT_COMMAND='echo -ne "\033]0;${USER} .:. ${PWD}\007"'
if [ -f ~/.bash_history ]; then
rm ~/.bash_history; ln -s /dev/null ~/.bash_history
fi
# When the shell is sent SIGUSR1, it re-sources .bashrc
eval trap "\"SIGUSR1=1; . ~$username/.bash_profile; kill -2 $$\"" USR1
function xtitle ()
{
case $TERM in
*term | rxvt)
echo -n -e "\033]0;$*\007" ;;
*) ;;
esac
}
docker-ip() {
boot2docker ip 2> /dev/null
}
# aliases...
alias top='xtitle Processes on $HOST && top'
alias make='xtitle Making $(basename $PWD) ; make'
alias ncftp="xtitle ncFTP ; ncftp"
function man()
{
xtitle "man $@"
/usr/bin/man $@
}
function getrands()
{
for i in {1..5};do od -vAn -N4 -tu4 < /dev/urandom; done
}
## function vi()
## {
## local NAME=$(basename $@)
## export PROMPT_COMMAND='echo -n -e "\033]0; vim $NAME \007"'
## /usr/bin/vi $@
## }
# swap 2 filenames
function swap()
{
local TMPFILE=tmp.$$
mv $1 $TMPFILE
mv $2 $1
mv $TMPFILE $2
}
function ii() # get current host related info
{
#echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nYou are logged on \033[1;32m$HOST\033[0m"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
#my_ip 2>&- ;
echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo
}
function repeat() # repeat n times command
{
local i max
max=$1; shift;
for ((i=1; i <= max ; i++)); do # --> C-like syntax
eval "$@";
done
}
# sync silver and scrape directories
synccomp()
{
H=$HOME
FILES="$H/.bashrc $H/.vim $H/.vimrc $H/.inputrc"
if [ `hostname` = "silver" ]; then
rsync -av --delete --force -e "ssh -o ClearAllForwardings=yes" $FILES scrape:.
else
echo "unknown host"
fi
}
ipaddr()
{
if [ ! $# = 1 ]; then
INTERFACE="en0"
else
INTERFACE="$1"
fi
ifconfig $INTERFACE | grep 'inet ' | awk '{print $2}'
}
# extended globbing
shopt -s extglob
set +o nounset # otherwise some completions will fail
bind 'TAB:complete'
# from abs
_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
## Use Homebrew completion
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi