2 # ~/.bashrc: executed by bash(1) for non-login shells.
3 # A basically sane bash environment.
4 # Tony Duckles <http://nynim.org/about/> (based on http://github.com/rtomayko/dotfiles)
6 # short-circuit for non-interactive sessions
7 [ -z "$PS1" ] && return
10 PATH
="/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:$PATH"
12 : ${LOGNAME=$(id -un)}
14 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
15 UNAME
=${UNAME/CYGWIN_*/Cygwin}
17 # complete hostnames from this file
18 HOSTFILE
=~
/.ssh
/known_hosts
23 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
24 case $(tput colors 2>&1) in
26 export TERM
=xterm
-color
27 case $(tput colors 2>&1) in
35 if [ "$UNAME" = "Darwin" ]; then
37 test -r /sw
/bin
/init.sh
&&
38 source /sw
/bin
/init.sh
41 # ----------------------------------------------------------------------
43 # ----------------------------------------------------------------------
45 # bring in system bashrc
46 test -r /etc
/bashrc
&&
49 # notify of bg job completion immediately
52 # shell opts. see bash(1) for details
53 shopt -s cdspell
>/dev
/null
2>&1
54 shopt -s extglob
>/dev
/null
2>&1
55 shopt -s histappend
>/dev
/null
2>&1
56 shopt -s hostcomplete
>/dev
/null
2>&1
57 shopt -s interactive_comments
>/dev
/null
2>&1
58 shopt -u mailwarn
>/dev
/null
2>&1
59 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
61 # don't check for new mail
70 # ----------------------------------------------------------------------
72 # ----------------------------------------------------------------------
74 # we want the various sbin's on the path along with /usr/local/bin
75 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
76 PATH
="/usr/local/bin:$PATH"
78 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
80 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
82 # ~/.rvm/bin on PATH if exists (RVM)
83 test -d "$HOME/.rvm/bin" &&
84 PATH
="$PATH:$HOME/.rvm/bin"
86 # put ~/bin on PATH if exists
87 test -d "$HOME/bin" &&
88 PATH
="$HOME/bin:$PATH"
90 # put ~/sbin on PATH if exists
91 test -d "$HOME/sbin" &&
92 PATH
="$HOME/sbin:$PATH"
94 # ----------------------------------------------------------------------
95 # ENVIRONMENT CONFIGURATION
96 # ----------------------------------------------------------------------
98 # detect interactive shell
100 *i
*) INTERACTIVE
=yes ;;
101 *) unset INTERACTIVE
;;
110 # setup locale. Try to enable en_US locale w/ utf-8 encodings
111 # (if not already configured), but do graceful fall-back.
112 lclist
=$(locale -a | grep en_US)
113 if test -n "$(echo $lclist | grep UTF-8)"; then
114 : ${LANG:="en_US.UTF-8"}
116 : ${LC_CTYPE:="en_US.UTF-8"}
117 : ${LC_ALL:="en_US.UTF-8"}
118 elif test -n "$(echo $lclist | grep utf8)"; then
119 : ${LANG:="en_US.utf8"}
121 : ${LC_CTYPE:="en_US.utf8"}
122 : ${LC_ALL:="en_US.utf8"}
123 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
124 : ${LANG:="en_US.ISO8859-1"}
126 : ${LC_CTYPE:="en_US.ISO8859-1"}
127 : ${LC_ALL:="en_US.ISO8859-1"}
131 : ${LC_CTYPE:="en_US"}
134 export LANG LANGUAGE LC_CTYPE LC_ALL
137 # ignore backups, CVS directories, python bytecode, vim swap files
138 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
141 HISTCONTROL
=ignoreboth
145 # ----------------------------------------------------------------------
147 # ----------------------------------------------------------------------
149 # See what we have to work with ...
150 HAVE_VIM
=$(command -v vim)
153 test -n "$HAVE_VIM" &&
159 if test -n "$(command -v less)" ; then
168 export PAGER MANPAGER
172 ACK_PAGER_COLOR
="$PAGER"
174 # ----------------------------------------------------------------------
176 # ----------------------------------------------------------------------
178 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
180 if [ "$UID" = 0 ]; then
182 PS_C1
="\[\033[1;31m\]" # red
183 PS_C2
="\[\033[0;37m\]" # grey
188 PS_C1
="\[\033[0;32m\]" # green
189 PS_C2
="\[\033[0;37m\]" # grey
192 PS_C1
="\[\033[1;97m\]" # white
193 PS_C2
="\[\033[0;37m\]" # grey
196 PS_C1
="\[\033[1;96m\]" # cyan
197 PS_C2
="\[\033[0;36m\]" # cyan
200 PS_C1
="\[\033[1;93m\]" # yellow
201 PS_C2
="\[\033[0;33m\]" # brown
214 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
219 # If git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
220 # Never show branch info for $HOME (dotfiles) repo.
221 # Use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
222 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
223 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
224 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
225 test "$(git config --bool bash.hidePrompt)" != "true" &&
226 __git_ps1 "{\[\033[0;100m\]%s\[\033[0;90m\]}")'
227 export GIT_PS1_SHOWDIRTYSTATE
=1
229 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_GIT}${PS_P}\[\033[0m\] "
233 # ----------------------------------------------------------------------
234 # MACOS X / DARWIN SPECIFIC
235 # ----------------------------------------------------------------------
237 if [ "$UNAME" = Darwin
]; then
238 # put ports on the paths if /opt/local exists
239 test -x /opt
/local -a ! -L /opt
/local && {
242 # setup the PATH and MANPATH
243 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
244 MANPATH
="$PORTS/share/man:$MANPATH"
246 # nice little port alias
247 alias port
="sudo nice -n +18 $PORTS/bin/port"
251 # ----------------------------------------------------------------------
252 # ALIASES / FUNCTIONS
253 # ----------------------------------------------------------------------
255 # alias 'vi' to 'vim' if Vim is installed
262 # disk usage with human sizes and minimal depth
263 alias du1
='du -h --max-depth=1'
264 alias fn
='find . -name'
265 alias hi
='history | tail -20'
267 # For Solaris, use GNU versions of core utils
268 if [ "$UNAME" = SunOS
]; then
269 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
270 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
271 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
274 # Alias csh-style "rebash" to bash equivalent
275 alias rehash
="hash -r"
277 # ----------------------------------------------------------------------
279 # ----------------------------------------------------------------------
281 test -z "$BASH_COMPLETION" && {
282 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
283 test -n "$PS1" && test $bmajor -gt 1 && {
284 # search for a bash_completion file to source
285 for f
in /usr
/local
/etc
/bash_completion \
286 /usr
/pkg
/etc
/bash_completion \
287 /opt
/local
/etc
/bash_completion \
296 unset bash bmajor bminor
299 # override and disable tilde expansion
304 # ----------------------------------------------------------------------
306 # ----------------------------------------------------------------------
308 # we always pass these to ls(1)
310 ## OS-specific options
312 # "Linux" ) LS_COMMON="--color=auto";;
313 # "Cygwin" ) LS_COMMON="--color=auto";;
314 # "Darwin" ) LS_COMMON="--color=auto";;
317 # if the dircolors utility is available, set that up for ls
318 dircolors
="$(type -P gdircolors dircolors | head -1)"
319 test -n "$dircolors" && {
320 COLORS
=/etc
/DIR_COLORS
321 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
322 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
323 test ! -e "$COLORS" && COLORS
=
324 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
325 test "$UNAME" = "AIX" && COLORS
=
326 eval `$dircolors --sh $COLORS`
330 # enable color ls output if available
332 LS_COMMON
="--color=auto $LS_COMMON"
334 # setup the main ls alias if we've established common args
335 test -n "$LS_COMMON" &&
336 alias ls="command ls $LS_COMMON"
338 # these use the ls aliases above
341 alias ll.
="ls -ld .*"
344 # setup color grep output if available
345 if [ -n "$COLORS" ]; then
348 # For Solaris, use the GNU version of grep for color support
349 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
352 alias grep="command grep --color=always"
355 # older versions of grep only support a singular highlight color
356 export GREP_COLOR
='1;37;42'
357 # newer versions of grep have more flexible color configuration
358 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
361 # --------------------------------------------------------------------
363 # --------------------------------------------------------------------
365 # push SSH public key to another box
368 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
372 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
376 # --------------------------------------------------------------------
377 # PATH MANIPULATION FUNCTIONS
378 # --------------------------------------------------------------------
381 # List path entries of PATH or environment variable <var>.
382 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
384 # Usage: pshift [-n <num>] [<var>]
385 # Shift <num> entries off the front of PATH or environment var <var>.
386 # with the <var> option. Useful: pshift $(pwd)
389 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
390 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
393 # Usage: ppop [-n <num>] [<var>]
394 # Pop <num> entries off the end of PATH or environment variable <var>.
397 [ "$1" = "-n" ] && { n
=$2; shift 2; }
399 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
404 # Usage: prm <path> [<var>]
405 # Remove <path> from PATH or environment variable <var>.
406 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
408 # Usage: punshift <path> [<var>]
409 # Shift <path> onto the beginning of PATH or environment variable <var>.
410 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
412 # Usage: ppush <path> [<var>]
413 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
415 # Usage: puniq [<path>]
416 # Remove duplicate entries from a PATH style value while retaining
417 # the original order. Use PATH if no <path> is given.
420 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
421 # /usr/bin:/usr/local/bin
423 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
424 cut
-f 2- | tr '\n' :
427 # -------------------------------------------------------------------
428 # USER SHELL ENVIRONMENT
429 # -------------------------------------------------------------------
431 # source ~/.shenv now if it exists
435 # condense PATH entries
436 PATH
=$(puniq "$PATH")
437 MANPATH
=$(puniq "$MANPATH")
439 # Use the color prompt by default when interactive
443 # -------------------------------------------------------------------
445 # -------------------------------------------------------------------
447 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
448 # Get current uname and uptime (if exists on this host)
449 # Strip any leading whitespace from uname and uptime commands
450 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
451 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
452 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
454 test -n "$t_uname" && echo $t_uname
455 test -n "$t_uptime" && echo $t_uptime
458 unset t_uname t_uptime
461 # vim: ts=4 sts=4 shiftwidth=4 expandtab