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 # ----------------------------------------------------------------------
37 # ----------------------------------------------------------------------
39 # bring in system bashrc
40 test -r /etc
/bashrc
&&
43 # notify of bg job completion immediately
46 # shell opts. see bash(1) for details
47 shopt -s cdspell
>/dev
/null
2>&1
48 shopt -s extglob
>/dev
/null
2>&1
49 shopt -s histappend
>/dev
/null
2>&1
50 shopt -s hostcomplete
>/dev
/null
2>&1
51 shopt -s interactive_comments
>/dev
/null
2>&1
52 shopt -u mailwarn
>/dev
/null
2>&1
53 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
55 # don't check for new mail
64 # ----------------------------------------------------------------------
66 # ----------------------------------------------------------------------
68 # we want the various sbin's on the path along with /usr/local/bin
69 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
70 PATH
="/usr/local/bin:$PATH"
72 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
74 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
76 # ~/.rvm/bin on PATH if exists (RVM)
77 test -d "$HOME/.rvm/bin" &&
78 PATH
="$PATH:$HOME/.rvm/bin"
80 # put ~/bin on PATH if exists
81 test -d "$HOME/bin" &&
82 PATH
="$HOME/bin:$PATH"
84 # put ~/sbin on PATH if exists
85 test -d "$HOME/sbin" &&
86 PATH
="$HOME/sbin:$PATH"
88 # ----------------------------------------------------------------------
89 # ENVIRONMENT CONFIGURATION
90 # ----------------------------------------------------------------------
92 # detect interactive shell
94 *i
*) INTERACTIVE
=yes ;;
95 *) unset INTERACTIVE
;;
104 # setup locale. Try to enable en_US locale w/ utf-8 encodings
105 # (if not already configured), but do graceful fall-back.
106 lclist
=$(locale -a | grep en_US)
107 if test -n "$(echo $lclist | grep UTF-8)"; then
108 : ${LANG:="en_US.UTF-8"}
110 : ${LC_CTYPE:="en_US.UTF-8"}
111 : ${LC_ALL:="en_US.UTF-8"}
112 elif test -n "$(echo $lclist | grep utf8)"; then
113 : ${LANG:="en_US.utf8"}
115 : ${LC_CTYPE:="en_US.utf8"}
116 : ${LC_ALL:="en_US.utf8"}
117 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
118 : ${LANG:="en_US.ISO8859-1"}
120 : ${LC_CTYPE:="en_US.ISO8859-1"}
121 : ${LC_ALL:="en_US.ISO8859-1"}
125 : ${LC_CTYPE:="en_US"}
128 export LANG LANGUAGE LC_CTYPE LC_ALL
131 # ignore backups, CVS directories, python bytecode, vim swap files
132 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
135 HISTCONTROL
=ignoreboth
139 # ----------------------------------------------------------------------
141 # ----------------------------------------------------------------------
143 # see what we have to work with ...
144 HAVE_VIM
=$(command -v vim)
147 test -n "$HAVE_VIM" &&
153 if test -n "$(command -v less)" ; then
162 export PAGER MANPAGER
164 # ----------------------------------------------------------------------
166 # ----------------------------------------------------------------------
168 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
170 if [ "$UID" = 0 ]; then
172 PS_C1
="\[\033[1;31m\]" # red
173 PS_C2
="\[\033[0;37m\]" # grey
178 PS_C1
="\[\033[0;32m\]" # green
179 PS_C2
="\[\033[0;37m\]" # grey
182 PS_C1
="\[\033[1;97m\]" # white
183 PS_C2
="\[\033[0;37m\]" # grey
186 PS_C1
="\[\033[1;96m\]" # cyan
187 PS_C2
="\[\033[0;36m\]" # cyan
190 PS_C1
="\[\033[1;93m\]" # yellow
191 PS_C2
="\[\033[0;33m\]" # brown
204 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
209 # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
210 # never show branch info for $HOME (dotfiles) repo.
211 # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
212 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
213 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
214 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
215 test "$(git config --bool bash.hidePrompt)" != "true" &&
216 __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")'
217 export GIT_PS1_SHOWDIRTYSTATE
=1
219 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_GIT}${PS_P}\[\033[0m\] "
223 # ----------------------------------------------------------------------
224 # MACOS X / DARWIN SPECIFIC
225 # ----------------------------------------------------------------------
227 if [ "$UNAME" = Darwin
]; then
228 # put ports on the paths if /opt/local exists
229 test -x /opt
/local -a ! -L /opt
/local && {
232 # setup the PATH and MANPATH
233 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
234 MANPATH
="$PORTS/share/man:$MANPATH"
236 # nice little port alias
237 alias port
="sudo nice -n +18 $PORTS/bin/port"
239 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
240 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
241 # setup the PATH and MANPATH
242 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
243 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
247 # ----------------------------------------------------------------------
248 # ALIASES / FUNCTIONS
249 # ----------------------------------------------------------------------
254 alias ll.
="ls -ld .*"
257 # use 'git diff --no-index' as a prettier 'diff' alternative (if available)
258 test -n "$(type -P git)" && alias diff="git diff --no-index"
260 # alias 'vi' to 'vim' if Vim is installed
267 # disk usage with human sizes and minimal depth
268 alias du1
='du -h --max-depth=1'
269 alias fn
='find . -name'
270 alias hi
='history | tail -20'
272 # for Solaris, use GNU versions of core utils
273 if [ "$UNAME" = SunOS
]; then
274 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
275 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
276 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
279 # alias csh-style "rebash" to bash equivalent
280 alias rehash
="hash -r"
282 # set 'screen' window title
284 printf "\033k%s\033\\" "$@"
288 alias svn
=svn
-wrapper
290 # ----------------------------------------------------------------------
292 # ----------------------------------------------------------------------
294 test -z "$BASH_COMPLETION" && {
295 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
296 test -n "$PS1" && test $bmajor -gt 1 && {
297 # search for a bash_completion file to source
298 for f
in /usr
/local
/etc
/bash_completion \
299 /usr
/pkg
/etc
/bash_completion \
300 /opt
/local
/etc
/bash_completion \
309 unset bash bmajor bminor
312 # override and disable tilde expansion
317 # ----------------------------------------------------------------------
319 # ----------------------------------------------------------------------
321 # we always pass these to ls(1)
324 # if the dircolors utility is available, set that up for ls
325 dircolors
="$(type -P gdircolors dircolors | head -1)"
326 test -n "$dircolors" && {
327 COLORS
=/etc
/DIR_COLORS
328 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
329 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
330 test ! -e "$COLORS" && COLORS
=
331 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
332 test "$UNAME" = "AIX" && COLORS
=
333 eval `$dircolors --sh $COLORS`
337 # enable color ls output if available
339 LS_COMMON
="--color=auto $LS_COMMON"
341 # setup the main ls alias if we've established common args
342 test -n "$LS_COMMON" &&
343 alias ls="command ls $LS_COMMON"
345 # setup color grep output if available
346 if [ -n "$COLORS" ]; then
349 # for Solaris, use the GNU version of grep for color support
350 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
353 alias grep="command grep --color=always"
356 # older versions of grep only support a singular highlight color
357 export GREP_COLOR
='1;37;42'
358 # newer versions of grep have more flexible color configuration
359 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
362 # --------------------------------------------------------------------
364 # --------------------------------------------------------------------
366 # push SSH public key to another box
369 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
373 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
377 # --------------------------------------------------------------------
378 # PATH MANIPULATION FUNCTIONS
379 # --------------------------------------------------------------------
382 # List path entries of PATH or environment variable <var>.
383 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
385 # Usage: pshift [-n <num>] [<var>]
386 # Shift <num> entries off the front of PATH or environment var <var>.
387 # with the <var> option. Useful: pshift $(pwd)
390 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
391 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
394 # Usage: ppop [-n <num>] [<var>]
395 # Pop <num> entries off the end of PATH or environment variable <var>.
398 [ "$1" = "-n" ] && { n
=$2; shift 2; }
400 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
405 # Usage: prm <path> [<var>]
406 # Remove <path> from PATH or environment variable <var>.
407 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
409 # Usage: punshift <path> [<var>]
410 # Shift <path> onto the beginning of PATH or environment variable <var>.
411 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
413 # Usage: ppush <path> [<var>]
414 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
416 # Usage: puniq [<path>]
417 # Remove duplicate entries from a PATH style value while retaining
418 # the original order. Use PATH if no <path> is given.
421 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
422 # /usr/bin:/usr/local/bin
424 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
425 cut
-f 2- | tr '\n' :
428 # -------------------------------------------------------------------
429 # USER SHELL ENVIRONMENT
430 # -------------------------------------------------------------------
432 # source ~/.shenv now if it exists
436 # condense PATH entries
437 PATH
=$(puniq "$PATH")
438 MANPATH
=$(puniq "$MANPATH")
440 # use the color prompt by default when interactive
444 # -------------------------------------------------------------------
446 # -------------------------------------------------------------------
448 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
449 # get current uname and uptime (if exists on this host)
450 # strip any leading whitespace from uname and uptime commands
451 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
452 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
453 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
455 test -n "$t_uname" && echo $t_uname
456 test -n "$t_uptime" && echo $t_uptime
459 unset t_uname t_uptime
462 # vim: ts=4 sts=4 shiftwidth=4 expandtab