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 sbin's 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 /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
79 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
81 # put ~/bin on PATH if exists
82 test -d "$HOME/bin" &&
83 PATH
="$HOME/bin:$PATH"
85 # put ~/sbin on PATH if exists
86 test -d "$HOME/sbin" &&
87 PATH
="$HOME/sbin:$PATH"
89 # ----------------------------------------------------------------------
90 # ENVIRONMENT CONFIGURATION
91 # ----------------------------------------------------------------------
93 # detect interactive shell
95 *i
*) INTERACTIVE
=yes ;;
96 *) unset INTERACTIVE
;;
105 # enable en_US locale w/ utf-8 encodings if not already
107 : ${LANG:="en_US.UTF-8"}
109 : ${LC_CTYPE:="en_US.UTF-8"}
110 : ${LC_ALL:="en_US.UTF-8"}
111 export LANG LANGUAGE LC_CTYPE LC_ALL
113 # ignore backups, CVS directories, python bytecode, vim swap files
114 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
117 HISTCONTROL
=ignoreboth
121 # ----------------------------------------------------------------------
123 # ----------------------------------------------------------------------
125 # See what we have to work with ...
126 HAVE_VIM
=$(command -v vim)
129 test -n "$HAVE_VIM" &&
135 if test -n "$(command -v less)" ; then
144 export PAGER MANPAGER
148 ACK_PAGER_COLOR
="$PAGER"
150 # ----------------------------------------------------------------------
152 # ----------------------------------------------------------------------
154 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
156 if [ "$UID" = 0 ]; then
158 PS_C1
="\[\033[1;31m\]" # red
159 PS_C2
="\[\033[0;37m\]" # grey
164 PS_C1
="\[\033[0;32m\]" # green
165 PS_C2
="\[\033[0;37m\]" # grey
168 PS_C1
="\[\033[1;97m\]" # white
169 PS_C2
="\[\033[0;37m\]" # grey
172 PS_C1
="\[\033[1;96m\]" # cyan
173 PS_C2
="\[\033[0;36m\]" # cyan
176 PS_C1
="\[\033[1;93m\]" # yellow
177 PS_C2
="\[\033[0;33m\]" # brown
190 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
195 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
199 # ----------------------------------------------------------------------
200 # MACOS X / DARWIN SPECIFIC
201 # ----------------------------------------------------------------------
203 if [ "$UNAME" = Darwin
]; then
204 # put ports on the paths if /opt/local exists
205 test -x /opt
/local -a ! -L /opt
/local && {
208 # setup the PATH and MANPATH
209 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
210 MANPATH
="$PORTS/share/man:$MANPATH"
212 # nice little port alias
213 alias port
="sudo nice -n +18 $PORTS/bin/port"
217 # ----------------------------------------------------------------------
218 # ALIASES / FUNCTIONS
219 # ----------------------------------------------------------------------
221 # alias 'vi' to 'vim' if Vim is installed
228 # disk usage with human sizes and minimal depth
229 alias du1
='du -h --max-depth=1'
230 alias fn
='find . -name'
231 alias hi
='history | tail -20'
233 # For Solaris, use GNU versions of grep and sed
234 if [ "$UNAME" = SunOS
]; then
235 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
236 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
239 # Alias csh-style "rebash" to bash equivalent
240 alias rehash
="hash -r"
242 # ----------------------------------------------------------------------
244 # ----------------------------------------------------------------------
246 test -z "$BASH_COMPLETION" && {
247 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
248 test -n "$PS1" && test $bmajor -gt 1 && {
249 # search for a bash_completion file to source
250 for f
in /usr
/local
/etc
/bash_completion \
251 /usr
/pkg
/etc
/bash_completion \
252 /opt
/local
/etc
/bash_completion \
261 unset bash bmajor bminor
264 # override and disable tilde expansion
269 # ----------------------------------------------------------------------
271 # ----------------------------------------------------------------------
273 # we always pass these to ls(1)
275 ## OS-specific options
277 # "Linux" ) LS_COMMON="--color=auto";;
278 # "Cygwin" ) LS_COMMON="--color=auto";;
279 # "Darwin" ) LS_COMMON="--color=auto";;
282 # if the dircolors utility is available, set that up for ls
283 dircolors
="$(type -P gdircolors dircolors | head -1)"
284 test -n "$dircolors" && {
285 COLORS
=/etc
/DIR_COLORS
286 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
287 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
288 test ! -e "$COLORS" && COLORS
=
289 eval `$dircolors --sh $COLORS`
293 # enable color ls output if available
295 LS_COMMON
="--color=auto $LS_COMMON"
297 # setup the main ls alias if we've established common args
298 test -n "$LS_COMMON" &&
299 alias ls="command ls $LS_COMMON"
301 # these use the ls aliases above
304 alias ll.
="ls -ld .*"
307 # setup color grep output if available
308 if [ -n "$COLORS" ]; then
311 # For Solaris, use the GNU version of grep for color support
312 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
315 alias grep="command grep --color=always"
318 # older versions of grep only support a singular highlight color
319 export GREP_COLOR
='1;37;42'
320 # newer versions of grep have more flexible color configuration
321 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
324 # --------------------------------------------------------------------
326 # --------------------------------------------------------------------
328 # push SSH public key to another box
331 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
335 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
339 # --------------------------------------------------------------------
340 # PATH MANIPULATION FUNCTIONS
341 # --------------------------------------------------------------------
344 # List path entries of PATH or environment variable <var>.
345 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
347 # Usage: pshift [-n <num>] [<var>]
348 # Shift <num> entries off the front of PATH or environment var <var>.
349 # with the <var> option. Useful: pshift $(pwd)
352 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
353 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
356 # Usage: ppop [-n <num>] [<var>]
357 # Pop <num> entries off the end of PATH or environment variable <var>.
360 [ "$1" = "-n" ] && { n
=$2; shift 2; }
362 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
367 # Usage: prm <path> [<var>]
368 # Remove <path> from PATH or environment variable <var>.
369 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
371 # Usage: punshift <path> [<var>]
372 # Shift <path> onto the beginning of PATH or environment variable <var>.
373 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
375 # Usage: ppush <path> [<var>]
376 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
378 # Usage: puniq [<path>]
379 # Remove duplicate entries from a PATH style value while retaining
380 # the original order. Use PATH if no <path> is given.
383 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
384 # /usr/bin:/usr/local/bin
386 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
387 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
390 # -------------------------------------------------------------------
391 # USER SHELL ENVIRONMENT
392 # -------------------------------------------------------------------
394 # source ~/.shenv now if it exists
398 # condense PATH entries
399 PATH
=$(puniq "$PATH")
400 MANPATH
=$(puniq "$MANPATH")
402 # Use the color prompt by default when interactive
406 # -------------------------------------------------------------------
408 # -------------------------------------------------------------------
410 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
411 # Get current uname and uptime (if exists on this host)
412 # Strip any leading whitespace from uname and uptime commands
413 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
414 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
415 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
417 test -n "$t_uname" && echo $t_uname
418 test -n "$t_uptime" && echo $t_uptime
421 unset t_uname t_uptime
424 # vim: ts=4 sts=4 shiftwidth=4 expandtab