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
133 MANPAGER
="less -FiRs"
138 export PAGER MANPAGER
142 ACK_PAGER_COLOR
="$PAGER"
144 # ----------------------------------------------------------------------
146 # ----------------------------------------------------------------------
148 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
150 if [ "$UID" = 0 ]; then
152 PS_C1
="\[\033[1;31m\]" # red
153 PS_C2
="\[\033[0;37m\]" # grey
158 PS_C1
="\[\033[0;32m\]" # green
159 PS_C2
="\[\033[0;37m\]" # grey
162 PS_C1
="\[\033[1;97m\]" # white
163 PS_C2
="\[\033[0;37m\]" # grey
166 PS_C1
="\[\033[1;96m\]" # cyan
167 PS_C2
="\[\033[0;36m\]" # cyan
170 PS_C1
="\[\033[1;93m\]" # yellow
171 PS_C2
="\[\033[0;33m\]" # brown
184 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
189 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
193 # ----------------------------------------------------------------------
194 # MACOS X / DARWIN SPECIFIC
195 # ----------------------------------------------------------------------
197 if [ "$UNAME" = Darwin
]; then
198 # put ports on the paths if /opt/local exists
199 test -x /opt
/local -a ! -L /opt
/local && {
202 # setup the PATH and MANPATH
203 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
204 MANPATH
="$PORTS/share/man:$MANPATH"
206 # nice little port alias
207 alias port
="sudo nice -n +18 $PORTS/bin/port"
211 # ----------------------------------------------------------------------
212 # ALIASES / FUNCTIONS
213 # ----------------------------------------------------------------------
215 # alias 'vi' to 'vim' if Vim is installed
222 # disk usage with human sizes and minimal depth
223 alias du1
='du -h --max-depth=1'
224 alias fn
='find . -name'
225 alias hi
='history | tail -20'
227 # For Solaris, use GNU versions of grep and sed
228 if [ "$UNAME" = SunOS
]; then
229 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
230 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
233 # Alias csh-style "rebash" to bash equivalent
234 alias rehash
="hash -r"
236 # ----------------------------------------------------------------------
238 # ----------------------------------------------------------------------
240 test -z "$BASH_COMPLETION" && {
241 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
242 test -n "$PS1" && test $bmajor -gt 1 && {
243 # search for a bash_completion file to source
244 for f
in /usr
/local
/etc
/bash_completion \
245 /usr
/pkg
/etc
/bash_completion \
246 /opt
/local
/etc
/bash_completion \
255 unset bash bmajor bminor
258 # override and disable tilde expansion
263 # ----------------------------------------------------------------------
265 # ----------------------------------------------------------------------
267 # we always pass these to ls(1)
269 ## OS-specific options
271 # "Linux" ) LS_COMMON="--color=auto";;
272 # "Cygwin" ) LS_COMMON="--color=auto";;
273 # "Darwin" ) LS_COMMON="--color=auto";;
276 # if the dircolors utility is available, set that up for ls
277 dircolors
="$(type -P gdircolors dircolors | head -1)"
278 test -n "$dircolors" && {
279 COLORS
=/etc
/DIR_COLORS
280 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
281 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
282 test ! -e "$COLORS" && COLORS
=
283 eval `$dircolors --sh $COLORS`
287 # enable color ls output if available
289 LS_COMMON
="--color=auto $LS_COMMON"
291 # setup the main ls alias if we've established common args
292 test -n "$LS_COMMON" &&
293 alias ls="command ls $LS_COMMON"
295 # these use the ls aliases above
298 alias ll.
="ls -ld .*"
301 # setup color grep output if available
302 if [ -n "$COLORS" ]; then
305 # For Solaris, use the GNU version of grep for color support
306 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
309 alias grep="command grep --color=auto"
314 # --------------------------------------------------------------------
316 # --------------------------------------------------------------------
318 # push SSH public key to another box
321 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
325 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
329 # --------------------------------------------------------------------
330 # PATH MANIPULATION FUNCTIONS
331 # --------------------------------------------------------------------
334 # List path entries of PATH or environment variable <var>.
335 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
337 # Usage: pshift [-n <num>] [<var>]
338 # Shift <num> entries off the front of PATH or environment var <var>.
339 # with the <var> option. Useful: pshift $(pwd)
342 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
343 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
346 # Usage: ppop [-n <num>] [<var>]
347 # Pop <num> entries off the end of PATH or environment variable <var>.
350 [ "$1" = "-n" ] && { n
=$2; shift 2; }
352 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
357 # Usage: prm <path> [<var>]
358 # Remove <path> from PATH or environment variable <var>.
359 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
361 # Usage: punshift <path> [<var>]
362 # Shift <path> onto the beginning of PATH or environment variable <var>.
363 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
365 # Usage: ppush <path> [<var>]
366 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
368 # Usage: puniq [<path>]
369 # Remove duplicate entries from a PATH style value while retaining
370 # the original order. Use PATH if no <path> is given.
373 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
374 # /usr/bin:/usr/local/bin
376 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
377 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
380 # -------------------------------------------------------------------
381 # USER SHELL ENVIRONMENT
382 # -------------------------------------------------------------------
384 # source ~/.shenv now if it exists
388 # condense PATH entries
389 PATH
=$(puniq "$PATH")
390 MANPATH
=$(puniq "$MANPATH")
392 # Use the color prompt by default when interactive
396 # -------------------------------------------------------------------
398 # -------------------------------------------------------------------
400 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
401 # Get current uname and uptime (if exists on this host)
402 # Strip any leading whitespace from uname and uptime commands
403 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
404 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
405 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
407 test -n "$t_uname" && echo $t_uname
408 test -n "$t_uptime" && echo $t_uptime
411 unset t_uname t_uptime
414 # vim: ts=4 sts=4 shiftwidth=4 expandtab