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 sbins 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 ~/bin on PATH if exists
79 test -d "$HOME/bin" &&
80 PATH
="$HOME/bin:$PATH"
82 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
84 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
86 # ----------------------------------------------------------------------
87 # ENVIRONMENT CONFIGURATION
88 # ----------------------------------------------------------------------
90 # detect interactive shell
92 *i
*) INTERACTIVE
=yes ;;
93 *) unset INTERACTIVE
;;
102 # setup locale. Try to enable en_US locale w/ utf-8 encodings
103 # (if not already configured), but do graceful fall-back.
104 lclist
=$(locale -a | grep en_US)
105 if test -n "$(echo $lclist | grep UTF-8)"; then
106 : ${LANG:="en_US.UTF-8"}
108 : ${LC_CTYPE:="en_US.UTF-8"}
109 : ${LC_ALL:="en_US.UTF-8"}
110 elif test -n "$(echo $lclist | grep utf8)"; then
111 : ${LANG:="en_US.utf8"}
113 : ${LC_CTYPE:="en_US.utf8"}
114 : ${LC_ALL:="en_US.utf8"}
115 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
116 : ${LANG:="en_US.ISO8859-1"}
118 : ${LC_CTYPE:="en_US.ISO8859-1"}
119 : ${LC_ALL:="en_US.ISO8859-1"}
123 : ${LC_CTYPE:="en_US"}
126 export LANG LANGUAGE LC_CTYPE LC_ALL
129 # ignore backups, CVS directories, python bytecode, vim swap files
130 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
133 HISTCONTROL
=ignoreboth
137 # ----------------------------------------------------------------------
139 # ----------------------------------------------------------------------
141 # See what we have to work with ...
142 HAVE_VIM
=$(command -v vim)
145 test -n "$HAVE_VIM" &&
151 if test -n "$(command -v less)" ; then
160 export PAGER MANPAGER
164 ACK_PAGER_COLOR
="$PAGER"
166 # ----------------------------------------------------------------------
168 # ----------------------------------------------------------------------
170 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
172 if [ "$UID" = 0 ]; then
174 PS_C1
="\[\033[1;31m\]" # red
175 PS_C2
="\[\033[0;37m\]" # grey
180 PS_C1
="\[\033[0;32m\]" # green
181 PS_C2
="\[\033[0;37m\]" # grey
184 PS_C1
="\[\033[1;97m\]" # white
185 PS_C2
="\[\033[0;37m\]" # grey
188 PS_C1
="\[\033[1;96m\]" # cyan
189 PS_C2
="\[\033[0;36m\]" # cyan
192 PS_C1
="\[\033[1;93m\]" # yellow
193 PS_C2
="\[\033[0;33m\]" # brown
206 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
211 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
215 # ----------------------------------------------------------------------
216 # MACOS X / DARWIN SPECIFIC
217 # ----------------------------------------------------------------------
219 if [ "$UNAME" = Darwin
]; then
220 # put ports on the paths if /opt/local exists
221 test -x /opt
/local -a ! -L /opt
/local && {
224 # setup the PATH and MANPATH
225 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
226 MANPATH
="$PORTS/share/man:$MANPATH"
228 # nice little port alias
229 alias port
="sudo nice -n +18 $PORTS/bin/port"
233 # ----------------------------------------------------------------------
234 # ALIASES / FUNCTIONS
235 # ----------------------------------------------------------------------
237 # alias 'vi' to 'vim' if Vim is installed
244 # disk usage with human sizes and minimal depth
245 alias du1
='du -h --max-depth=1'
246 alias fn
='find . -name'
247 alias hi
='history | tail -20'
249 # For Solaris, use GNU versions of grep and sed
250 if [ "$UNAME" = SunOS
]; then
251 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
252 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
255 # Alias csh-style "rebash" to bash equivalent
256 alias rehash
="hash -r"
258 # ----------------------------------------------------------------------
260 # ----------------------------------------------------------------------
262 test -z "$BASH_COMPLETION" && {
263 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
264 test -n "$PS1" && test $bmajor -gt 1 && {
265 # search for a bash_completion file to source
266 for f
in /usr
/local
/etc
/bash_completion \
267 /usr
/pkg
/etc
/bash_completion \
268 /opt
/local
/etc
/bash_completion \
277 unset bash bmajor bminor
280 # override and disable tilde expansion
285 # ----------------------------------------------------------------------
287 # ----------------------------------------------------------------------
289 # we always pass these to ls(1)
291 ## OS-specific options
293 # "Linux" ) LS_COMMON="--color=auto";;
294 # "Cygwin" ) LS_COMMON="--color=auto";;
295 # "Darwin" ) LS_COMMON="--color=auto";;
298 # if the dircolors utility is available, set that up for ls
299 dircolors
="$(type -P gdircolors dircolors | head -1)"
300 test -n "$dircolors" && {
301 COLORS
=/etc
/DIR_COLORS
302 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
303 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
304 test ! -e "$COLORS" && COLORS
=
305 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
306 test "$UNAME" = "AIX" && COLORS
=
307 eval `$dircolors --sh $COLORS`
311 # enable color ls output if available
313 LS_COMMON
="--color=auto $LS_COMMON"
315 # setup the main ls alias if we've established common args
316 test -n "$LS_COMMON" &&
317 alias ls="command ls $LS_COMMON"
319 # these use the ls aliases above
322 alias ll.
="ls -ld .*"
325 # setup color grep output if available
326 if [ -n "$COLORS" ]; then
329 # For Solaris, use the GNU version of grep for color support
330 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
333 alias grep="command grep --color=always"
336 # older versions of grep only support a singular highlight color
337 export GREP_COLOR
='1;37;42'
338 # newer versions of grep have more flexible color configuration
339 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
342 # --------------------------------------------------------------------
344 # --------------------------------------------------------------------
346 # push SSH public key to another box
349 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
353 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
357 # --------------------------------------------------------------------
358 # PATH MANIPULATION FUNCTIONS
359 # --------------------------------------------------------------------
362 # List path entries of PATH or environment variable <var>.
363 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
365 # Usage: pshift [-n <num>] [<var>]
366 # Shift <num> entries off the front of PATH or environment var <var>.
367 # with the <var> option. Useful: pshift $(pwd)
370 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
371 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
374 # Usage: ppop [-n <num>] [<var>]
375 # Pop <num> entries off the end of PATH or environment variable <var>.
378 [ "$1" = "-n" ] && { n
=$2; shift 2; }
380 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
385 # Usage: prm <path> [<var>]
386 # Remove <path> from PATH or environment variable <var>.
387 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
389 # Usage: punshift <path> [<var>]
390 # Shift <path> onto the beginning of PATH or environment variable <var>.
391 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
393 # Usage: ppush <path> [<var>]
394 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
396 # Usage: puniq [<path>]
397 # Remove duplicate entries from a PATH style value while retaining
398 # the original order. Use PATH if no <path> is given.
401 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
402 # /usr/bin:/usr/local/bin
404 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
405 cut
-f 2- | tr '\n' :
408 # -------------------------------------------------------------------
409 # USER SHELL ENVIRONMENT
410 # -------------------------------------------------------------------
412 # source ~/.shenv now if it exists
416 # condense PATH entries
417 PATH
=$(puniq "$PATH")
418 MANPATH
=$(puniq "$MANPATH")
420 # Use the color prompt by default when interactive
424 # -------------------------------------------------------------------
426 # -------------------------------------------------------------------
428 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
429 # Get current uname and uptime (if exists on this host)
430 # Strip any leading whitespace from uname and uptime commands
431 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
432 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
433 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
435 test -n "$t_uname" && echo $t_uname
436 test -n "$t_uptime" && echo $t_uptime
439 unset t_uname t_uptime
442 # vim: ts=4 sts=4 shiftwidth=4 expandtab