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
11 : ${LOGNAME=$(id -un)}
13 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
14 UNAME
=${UNAME/CYGWIN_*/Cygwin}
16 # complete hostnames from this file
17 HOSTFILE
=~
/.ssh
/known_hosts
22 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
23 case $(tput colors 2>&1) in
25 export TERM
=xterm
-color
26 case $(tput colors 2>&1) in
34 if [ "$UNAME" = "Darwin" ]; then
36 test -r /sw
/bin
/init.sh
&&
37 source /sw
/bin
/init.sh
40 # ----------------------------------------------------------------------
42 # ----------------------------------------------------------------------
44 # bring in system bashrc
45 test -r /etc
/bashrc
&&
48 # notify of bg job completion immediately
51 # shell opts. see bash(1) for details
52 shopt -s cdspell
>/dev
/null
2>&1
53 shopt -s extglob
>/dev
/null
2>&1
54 shopt -s histappend
>/dev
/null
2>&1
55 shopt -s hostcomplete
>/dev
/null
2>&1
56 shopt -s interactive_comments
>/dev
/null
2>&1
57 shopt -u mailwarn
>/dev
/null
2>&1
58 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
60 # don't check for new mail
69 # ----------------------------------------------------------------------
71 # ----------------------------------------------------------------------
73 # we want the various sbins on the path along with /usr/local/bin
74 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
75 PATH
="/usr/local/bin:$PATH"
77 # put ~/bin on PATH if exists
78 test -d "$HOME/bin" &&
79 PATH
="$HOME/bin:$PATH"
81 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
83 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
85 # ----------------------------------------------------------------------
86 # ENVIRONMENT CONFIGURATION
87 # ----------------------------------------------------------------------
89 # detect interactive shell
91 *i
*) INTERACTIVE
=yes ;;
92 *) unset INTERACTIVE
;;
101 # setup locale. Try to enable en_US locale w/ utf-8 encodings
102 # (if not already configured), but do graceful fall-back.
103 lclist
=$(locale -a | grep en_US)
104 if test -n "$(echo $lclist | grep UTF-8)"; then
105 : ${LANG:="en_US.UTF-8"}
107 : ${LC_CTYPE:="en_US.UTF-8"}
108 : ${LC_ALL:="en_US.UTF-8"}
109 elif test -n "$(echo $lclist | grep utf8)"; then
110 : ${LANG:="en_US.utf8"}
112 : ${LC_CTYPE:="en_US.utf8"}
113 : ${LC_ALL:="en_US.utf8"}
114 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
115 : ${LANG:="en_US.ISO8859-1"}
117 : ${LC_CTYPE:="en_US.ISO8859-1"}
118 : ${LC_ALL:="en_US.ISO8859-1"}
122 : ${LC_CTYPE:="en_US"}
125 export LANG LANGUAGE LC_CTYPE LC_ALL
128 # ignore backups, CVS directories, python bytecode, vim swap files
129 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
132 HISTCONTROL
=ignoreboth
136 # ----------------------------------------------------------------------
138 # ----------------------------------------------------------------------
140 # See what we have to work with ...
141 HAVE_VIM
=$(command -v vim)
144 test -n "$HAVE_VIM" &&
150 if test -n "$(command -v less)" ; then
159 export PAGER MANPAGER
163 ACK_PAGER_COLOR
="$PAGER"
165 # ----------------------------------------------------------------------
167 # ----------------------------------------------------------------------
169 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
171 if [ "$UID" = 0 ]; then
173 PS_C1
="\[\033[1;31m\]" # red
174 PS_C2
="\[\033[0;37m\]" # grey
179 PS_C1
="\[\033[0;32m\]" # green
180 PS_C2
="\[\033[0;37m\]" # grey
183 PS_C1
="\[\033[1;97m\]" # white
184 PS_C2
="\[\033[0;37m\]" # grey
187 PS_C1
="\[\033[1;96m\]" # cyan
188 PS_C2
="\[\033[0;36m\]" # cyan
191 PS_C1
="\[\033[1;93m\]" # yellow
192 PS_C2
="\[\033[0;33m\]" # brown
205 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
210 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
214 # ----------------------------------------------------------------------
215 # MACOS X / DARWIN SPECIFIC
216 # ----------------------------------------------------------------------
218 if [ "$UNAME" = Darwin
]; then
219 # put ports on the paths if /opt/local exists
220 test -x /opt
/local -a ! -L /opt
/local && {
223 # setup the PATH and MANPATH
224 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
225 MANPATH
="$PORTS/share/man:$MANPATH"
227 # nice little port alias
228 alias port
="sudo nice -n +18 $PORTS/bin/port"
232 # ----------------------------------------------------------------------
233 # ALIASES / FUNCTIONS
234 # ----------------------------------------------------------------------
236 # alias 'vi' to 'vim' if Vim is installed
243 # disk usage with human sizes and minimal depth
244 alias du1
='du -h --max-depth=1'
245 alias fn
='find . -name'
246 alias hi
='history | tail -20'
248 # For Solaris, use GNU versions of grep and sed
249 if [ "$UNAME" = SunOS
]; then
250 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
251 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
254 # Alias csh-style "rebash" to bash equivalent
255 alias rehash
="hash -r"
257 # ----------------------------------------------------------------------
259 # ----------------------------------------------------------------------
261 test -z "$BASH_COMPLETION" && {
262 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
263 test -n "$PS1" && test $bmajor -gt 1 && {
264 # search for a bash_completion file to source
265 for f
in /usr
/local
/etc
/bash_completion \
266 /usr
/pkg
/etc
/bash_completion \
267 /opt
/local
/etc
/bash_completion \
276 unset bash bmajor bminor
279 # override and disable tilde expansion
284 # ----------------------------------------------------------------------
286 # ----------------------------------------------------------------------
288 # we always pass these to ls(1)
290 ## OS-specific options
292 # "Linux" ) LS_COMMON="--color=auto";;
293 # "Cygwin" ) LS_COMMON="--color=auto";;
294 # "Darwin" ) LS_COMMON="--color=auto";;
297 # if the dircolors utility is available, set that up for ls
298 dircolors
="$(type -P gdircolors dircolors | head -1)"
299 test -n "$dircolors" && {
300 COLORS
=/etc
/DIR_COLORS
301 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
302 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
303 test ! -e "$COLORS" && COLORS
=
304 eval `$dircolors --sh $COLORS`
308 # enable color ls output if available
310 LS_COMMON
="--color=auto $LS_COMMON"
312 # setup the main ls alias if we've established common args
313 test -n "$LS_COMMON" &&
314 alias ls="command ls $LS_COMMON"
316 # these use the ls aliases above
319 alias ll.
="ls -ld .*"
322 # setup color grep output if available
323 if [ -n "$COLORS" ]; then
326 # For Solaris, use the GNU version of grep for color support
327 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
330 alias grep="command grep --color=auto"
335 # --------------------------------------------------------------------
337 # --------------------------------------------------------------------
339 # push SSH public key to another box
342 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
346 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
350 # --------------------------------------------------------------------
351 # PATH MANIPULATION FUNCTIONS
352 # --------------------------------------------------------------------
355 # List path entries of PATH or environment variable <var>.
356 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
358 # Usage: pshift [-n <num>] [<var>]
359 # Shift <num> entries off the front of PATH or environment var <var>.
360 # with the <var> option. Useful: pshift $(pwd)
363 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
364 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
367 # Usage: ppop [-n <num>] [<var>]
368 # Pop <num> entries off the end of PATH or environment variable <var>.
371 [ "$1" = "-n" ] && { n
=$2; shift 2; }
373 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
378 # Usage: prm <path> [<var>]
379 # Remove <path> from PATH or environment variable <var>.
380 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
382 # Usage: punshift <path> [<var>]
383 # Shift <path> onto the beginning of PATH or environment variable <var>.
384 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
386 # Usage: ppush <path> [<var>]
387 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
389 # Usage: puniq [<path>]
390 # Remove duplicate entries from a PATH style value while retaining
391 # the original order. Use PATH if no <path> is given.
394 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
395 # /usr/bin:/usr/local/bin
397 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
398 cut
-f 2- | tr '\n' :
401 # -------------------------------------------------------------------
402 # USER SHELL ENVIRONMENT
403 # -------------------------------------------------------------------
405 # source ~/.shenv now if it exists
409 # condense PATH entries
410 PATH
=$(puniq "$PATH")
411 MANPATH
=$(puniq "$MANPATH")
413 # Use the color prompt by default when interactive
417 # -------------------------------------------------------------------
419 # -------------------------------------------------------------------
421 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
422 # Get current uname and uptime (if exists on this host)
423 # Strip any leading whitespace from uname and uptime commands
424 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
425 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
426 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
428 test -n "$t_uname" && echo $t_uname
429 test -n "$t_uptime" && echo $t_uptime
432 unset t_uname t_uptime
435 # vim: ts=4 sts=4 shiftwidth=4 expandtab