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 # enable en_US locale w/ utf-8 encodings if not already
103 : ${LANG:="en_US.UTF-8"}
105 : ${LC_CTYPE:="en_US.UTF-8"}
106 : ${LC_ALL:="en_US.UTF-8"}
107 export LANG LANGUAGE LC_CTYPE LC_ALL
109 # ignore backups, CVS directories, python bytecode, vim swap files
110 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
113 HISTCONTROL
=ignoreboth
117 # ----------------------------------------------------------------------
119 # ----------------------------------------------------------------------
121 # See what we have to work with ...
122 HAVE_VIM
=$(command -v vim)
125 test -n "$HAVE_VIM" &&
131 if test -n "$(command -v less)" ; then
140 export PAGER MANPAGER
144 ACK_PAGER_COLOR
="$PAGER"
146 # ----------------------------------------------------------------------
148 # ----------------------------------------------------------------------
150 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
152 if [ "$UID" = 0 ]; then
154 PS_C1
="\[\033[1;31m\]" # red
155 PS_C2
="\[\033[0;37m\]" # grey
160 PS_C1
="\[\033[0;32m\]" # green
161 PS_C2
="\[\033[0;37m\]" # grey
164 PS_C1
="\[\033[1;97m\]" # white
165 PS_C2
="\[\033[0;37m\]" # grey
168 PS_C1
="\[\033[1;96m\]" # cyan
169 PS_C2
="\[\033[0;36m\]" # cyan
172 PS_C1
="\[\033[1;93m\]" # yellow
173 PS_C2
="\[\033[0;33m\]" # brown
186 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
191 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
195 # ----------------------------------------------------------------------
196 # MACOS X / DARWIN SPECIFIC
197 # ----------------------------------------------------------------------
199 if [ "$UNAME" = Darwin
]; then
200 # put ports on the paths if /opt/local exists
201 test -x /opt
/local -a ! -L /opt
/local && {
204 # setup the PATH and MANPATH
205 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
206 MANPATH
="$PORTS/share/man:$MANPATH"
208 # nice little port alias
209 alias port
="sudo nice -n +18 $PORTS/bin/port"
213 # ----------------------------------------------------------------------
214 # ALIASES / FUNCTIONS
215 # ----------------------------------------------------------------------
217 # alias 'vi' to 'vim' if Vim is installed
224 # disk usage with human sizes and minimal depth
225 alias du1
='du -h --max-depth=1'
226 alias fn
='find . -name'
227 alias hi
='history | tail -20'
229 # For Solaris, use GNU versions of grep and sed
230 if [ "$UNAME" = SunOS
]; then
231 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
232 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
235 # Alias csh-style "rebash" to bash equivalent
236 alias rehash
="hash -r"
238 # ----------------------------------------------------------------------
240 # ----------------------------------------------------------------------
242 test -z "$BASH_COMPLETION" && {
243 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
244 test -n "$PS1" && test $bmajor -gt 1 && {
245 # search for a bash_completion file to source
246 for f
in /usr
/local
/etc
/bash_completion \
247 /usr
/pkg
/etc
/bash_completion \
248 /opt
/local
/etc
/bash_completion \
257 unset bash bmajor bminor
260 # override and disable tilde expansion
265 # ----------------------------------------------------------------------
267 # ----------------------------------------------------------------------
269 # we always pass these to ls(1)
271 ## OS-specific options
273 # "Linux" ) LS_COMMON="--color=auto";;
274 # "Cygwin" ) LS_COMMON="--color=auto";;
275 # "Darwin" ) LS_COMMON="--color=auto";;
278 # if the dircolors utility is available, set that up for ls
279 dircolors
="$(type -P gdircolors dircolors | head -1)"
280 test -n "$dircolors" && {
281 COLORS
=/etc
/DIR_COLORS
282 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
283 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
284 test ! -e "$COLORS" && COLORS
=
285 eval `$dircolors --sh $COLORS`
289 # enable color ls output if available
291 LS_COMMON
="--color=auto $LS_COMMON"
293 # setup the main ls alias if we've established common args
294 test -n "$LS_COMMON" &&
295 alias ls="command ls $LS_COMMON"
297 # these use the ls aliases above
300 alias ll.
="ls -ld .*"
303 # setup color grep output if available
304 if [ -n "$COLORS" ]; then
307 # For Solaris, use the GNU version of grep for color support
308 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
311 alias grep="command grep --color=auto"
316 # --------------------------------------------------------------------
318 # --------------------------------------------------------------------
320 # push SSH public key to another box
323 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
327 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
331 # --------------------------------------------------------------------
332 # PATH MANIPULATION FUNCTIONS
333 # --------------------------------------------------------------------
336 # List path entries of PATH or environment variable <var>.
337 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
339 # Usage: pshift [-n <num>] [<var>]
340 # Shift <num> entries off the front of PATH or environment var <var>.
341 # with the <var> option. Useful: pshift $(pwd)
344 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
345 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
348 # Usage: ppop [-n <num>] [<var>]
349 # Pop <num> entries off the end of PATH or environment variable <var>.
352 [ "$1" = "-n" ] && { n
=$2; shift 2; }
354 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
359 # Usage: prm <path> [<var>]
360 # Remove <path> from PATH or environment variable <var>.
361 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
363 # Usage: punshift <path> [<var>]
364 # Shift <path> onto the beginning of PATH or environment variable <var>.
365 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
367 # Usage: ppush <path> [<var>]
368 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
370 # Usage: puniq [<path>]
371 # Remove duplicate entries from a PATH style value while retaining
372 # the original order. Use PATH if no <path> is given.
375 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
376 # /usr/bin:/usr/local/bin
378 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
379 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
382 # -------------------------------------------------------------------
383 # USER SHELL ENVIRONMENT
384 # -------------------------------------------------------------------
386 # source ~/.shenv now if it exists
390 # condense PATH entries
391 PATH
=$(puniq "$PATH")
392 MANPATH
=$(puniq "$MANPATH")
394 # Use the color prompt by default when interactive
398 # -------------------------------------------------------------------
400 # -------------------------------------------------------------------
402 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
403 # Get current uname and uptime (if exists on this host)
404 # Strip any leading whitespace from uname and uptime commands
405 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
406 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
407 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
409 test -n "$t_uname" && echo $t_uname
410 test -n "$t_uptime" && echo $t_uptime
413 unset t_uname t_uptime
416 # vim: ts=4 sts=4 shiftwidth=4 expandtab