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 # put ~/bin on PATH if exists
83 test -d "$HOME/bin" &&
84 PATH
="$HOME/bin:$PATH"
86 # put ~/sbin on PATH if exists
87 test -d "$HOME/sbin" &&
88 PATH
="$HOME/sbin:$PATH"
90 # ----------------------------------------------------------------------
91 # ENVIRONMENT CONFIGURATION
92 # ----------------------------------------------------------------------
94 # detect interactive shell
96 *i
*) INTERACTIVE
=yes ;;
97 *) unset INTERACTIVE
;;
106 # setup locale. Try to enable en_US locale w/ utf-8 encodings
107 # (if not already configured), but do graceful fall-back.
108 lclist
=$(locale -a | grep en_US)
109 if test -n "$(echo $lclist | grep UTF-8)"; then
110 : ${LANG:="en_US.UTF-8"}
112 : ${LC_CTYPE:="en_US.UTF-8"}
113 : ${LC_ALL:="en_US.UTF-8"}
114 elif test -n "$(echo $lclist | grep utf8)"; then
115 : ${LANG:="en_US.utf8"}
117 : ${LC_CTYPE:="en_US.utf8"}
118 : ${LC_ALL:="en_US.utf8"}
119 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
120 : ${LANG:="en_US.ISO8859-1"}
122 : ${LC_CTYPE:="en_US.ISO8859-1"}
123 : ${LC_ALL:="en_US.ISO8859-1"}
127 : ${LC_CTYPE:="en_US"}
130 export LANG LANGUAGE LC_CTYPE LC_ALL
133 # ignore backups, CVS directories, python bytecode, vim swap files
134 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
137 HISTCONTROL
=ignoreboth
141 # ----------------------------------------------------------------------
143 # ----------------------------------------------------------------------
145 # See what we have to work with ...
146 HAVE_VIM
=$(command -v vim)
149 test -n "$HAVE_VIM" &&
155 if test -n "$(command -v less)" ; then
164 export PAGER MANPAGER
168 ACK_PAGER_COLOR
="$PAGER"
170 # ----------------------------------------------------------------------
172 # ----------------------------------------------------------------------
174 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
176 if [ "$UID" = 0 ]; then
178 PS_C1
="\[\033[1;31m\]" # red
179 PS_C2
="\[\033[0;37m\]" # grey
184 PS_C1
="\[\033[0;32m\]" # green
185 PS_C2
="\[\033[0;37m\]" # grey
188 PS_C1
="\[\033[1;97m\]" # white
189 PS_C2
="\[\033[0;37m\]" # grey
192 PS_C1
="\[\033[1;96m\]" # cyan
193 PS_C2
="\[\033[0;36m\]" # cyan
196 PS_C1
="\[\033[1;93m\]" # yellow
197 PS_C2
="\[\033[0;33m\]" # brown
210 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
215 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
219 # ----------------------------------------------------------------------
220 # MACOS X / DARWIN SPECIFIC
221 # ----------------------------------------------------------------------
223 if [ "$UNAME" = Darwin
]; then
224 # put ports on the paths if /opt/local exists
225 test -x /opt
/local -a ! -L /opt
/local && {
228 # setup the PATH and MANPATH
229 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
230 MANPATH
="$PORTS/share/man:$MANPATH"
232 # nice little port alias
233 alias port
="sudo nice -n +18 $PORTS/bin/port"
237 # ----------------------------------------------------------------------
238 # ALIASES / FUNCTIONS
239 # ----------------------------------------------------------------------
241 # alias 'vi' to 'vim' if Vim is installed
248 # disk usage with human sizes and minimal depth
249 alias du1
='du -h --max-depth=1'
250 alias fn
='find . -name'
251 alias hi
='history | tail -20'
253 # For Solaris, use GNU versions of grep and sed
254 if [ "$UNAME" = SunOS
]; then
255 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
256 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
259 # Alias csh-style "rebash" to bash equivalent
260 alias rehash
="hash -r"
262 # ----------------------------------------------------------------------
264 # ----------------------------------------------------------------------
266 test -z "$BASH_COMPLETION" && {
267 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
268 test -n "$PS1" && test $bmajor -gt 1 && {
269 # search for a bash_completion file to source
270 for f
in /usr
/local
/etc
/bash_completion \
271 /usr
/pkg
/etc
/bash_completion \
272 /opt
/local
/etc
/bash_completion \
281 unset bash bmajor bminor
284 # override and disable tilde expansion
289 # ----------------------------------------------------------------------
291 # ----------------------------------------------------------------------
293 # we always pass these to ls(1)
295 ## OS-specific options
297 # "Linux" ) LS_COMMON="--color=auto";;
298 # "Cygwin" ) LS_COMMON="--color=auto";;
299 # "Darwin" ) LS_COMMON="--color=auto";;
302 # if the dircolors utility is available, set that up for ls
303 dircolors
="$(type -P gdircolors dircolors | head -1)"
304 test -n "$dircolors" && {
305 COLORS
=/etc
/DIR_COLORS
306 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
307 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
308 test ! -e "$COLORS" && COLORS
=
309 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
310 test "$UNAME" = "AIX" && COLORS
=
311 eval `$dircolors --sh $COLORS`
315 # enable color ls output if available
317 LS_COMMON
="--color=auto $LS_COMMON"
319 # setup the main ls alias if we've established common args
320 test -n "$LS_COMMON" &&
321 alias ls="command ls $LS_COMMON"
323 # these use the ls aliases above
326 alias ll.
="ls -ld .*"
329 # setup color grep output if available
330 if [ -n "$COLORS" ]; then
333 # For Solaris, use the GNU version of grep for color support
334 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
337 alias grep="command grep --color=always"
340 # older versions of grep only support a singular highlight color
341 export GREP_COLOR
='1;37;42'
342 # newer versions of grep have more flexible color configuration
343 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
346 # --------------------------------------------------------------------
348 # --------------------------------------------------------------------
350 # push SSH public key to another box
353 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
357 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
361 # --------------------------------------------------------------------
362 # PATH MANIPULATION FUNCTIONS
363 # --------------------------------------------------------------------
366 # List path entries of PATH or environment variable <var>.
367 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
369 # Usage: pshift [-n <num>] [<var>]
370 # Shift <num> entries off the front of PATH or environment var <var>.
371 # with the <var> option. Useful: pshift $(pwd)
374 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
375 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
378 # Usage: ppop [-n <num>] [<var>]
379 # Pop <num> entries off the end of PATH or environment variable <var>.
382 [ "$1" = "-n" ] && { n
=$2; shift 2; }
384 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
389 # Usage: prm <path> [<var>]
390 # Remove <path> from PATH or environment variable <var>.
391 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
393 # Usage: punshift <path> [<var>]
394 # Shift <path> onto the beginning of PATH or environment variable <var>.
395 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
397 # Usage: ppush <path> [<var>]
398 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
400 # Usage: puniq [<path>]
401 # Remove duplicate entries from a PATH style value while retaining
402 # the original order. Use PATH if no <path> is given.
405 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
406 # /usr/bin:/usr/local/bin
408 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
409 cut
-f 2- | tr '\n' :
412 # -------------------------------------------------------------------
413 # USER SHELL ENVIRONMENT
414 # -------------------------------------------------------------------
416 # source ~/.shenv now if it exists
420 # condense PATH entries
421 PATH
=$(puniq "$PATH")
422 MANPATH
=$(puniq "$MANPATH")
424 # Use the color prompt by default when interactive
428 # -------------------------------------------------------------------
430 # -------------------------------------------------------------------
432 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
433 # Get current uname and uptime (if exists on this host)
434 # Strip any leading whitespace from uname and uptime commands
435 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
436 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
437 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
439 test -n "$t_uname" && echo $t_uname
440 test -n "$t_uptime" && echo $t_uptime
443 unset t_uname t_uptime
446 # vim: ts=4 sts=4 shiftwidth=4 expandtab