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 # notify of bg job completion immediately
42 # shell opts. see bash(1) for details
43 shopt -s cdspell
>/dev
/null
2>&1
44 shopt -s checkjobs
>/dev
/null
2>&1
45 shopt -s checkwinsize
>/dev
/null
2>&1
46 shopt -s extglob
>/dev
/null
2>&1
47 shopt -s histappend
>/dev
/null
2>&1
48 shopt -s hostcomplete
>/dev
/null
2>&1
49 shopt -s interactive_comments
>/dev
/null
2>&1
50 shopt -u mailwarn
>/dev
/null
2>&1
51 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
53 # don't check for new mail
62 # ----------------------------------------------------------------------
64 # ----------------------------------------------------------------------
66 # we want the various sbin's on the path along with /usr/local/bin
67 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
68 PATH
="/usr/local/bin:$PATH"
70 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
72 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
74 # ~/.rvm/bin on PATH if exists (RVM)
75 test -d "$HOME/.rvm/bin" &&
76 PATH
="$PATH:$HOME/.rvm/bin"
78 # put ~/bin on PATH if exists
79 test -d "$HOME/bin" &&
80 PATH
="$HOME/bin:$PATH"
82 # put ~/sbin on PATH if exists
83 test -d "$HOME/sbin" &&
84 PATH
="$HOME/sbin:$PATH"
86 # ----------------------------------------------------------------------
87 # ENVIRONMENT CONFIGURATION
88 # ----------------------------------------------------------------------
90 # detect interactive shell
92 *i
*) INTERACTIVE
=yes ;;
93 *) unset INTERACTIVE
;;
102 # setup locale. Try to enable en_US locale w/ utf-8 encodings
103 # (if not already configured), but do graceful fall-back.
104 lclist
=$(locale -a | grep en_US)
105 if test -n "$(echo $lclist | grep UTF-8)"; then
106 : ${LANG:="en_US.UTF-8"}
108 : ${LC_CTYPE:="en_US.UTF-8"}
109 : ${LC_ALL:="en_US.UTF-8"}
110 elif test -n "$(echo $lclist | grep utf8)"; then
111 : ${LANG:="en_US.utf8"}
113 : ${LC_CTYPE:="en_US.utf8"}
114 : ${LC_ALL:="en_US.utf8"}
115 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
116 : ${LANG:="en_US.ISO8859-1"}
118 : ${LC_CTYPE:="en_US.ISO8859-1"}
119 : ${LC_ALL:="en_US.ISO8859-1"}
123 : ${LC_CTYPE:="en_US"}
126 export LANG LANGUAGE LC_CTYPE LC_ALL
129 # ignore backups, CVS directories, python bytecode, vim swap files
130 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
133 HISTCONTROL
=ignoreboth
137 # ----------------------------------------------------------------------
139 # ----------------------------------------------------------------------
141 # see what we have to work with ...
142 HAVE_VIM
=$(command -v vim)
145 test -n "$HAVE_VIM" &&
151 if test -n "$(command -v less)" ; then
160 export PAGER MANPAGER
162 # ----------------------------------------------------------------------
164 # ----------------------------------------------------------------------
166 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
168 if [ "$UID" = 0 ]; then
170 PS_C1
="\[\033[1;31m\]" # red
171 PS_C2
="\[\033[0;37m\]" # grey
176 PS_C1
="\[\033[0;32m\]" # green
177 PS_C2
="\[\033[0;37m\]" # grey
180 PS_C1
="\[\033[1;97m\]" # white
181 PS_C2
="\[\033[0;37m\]" # grey
184 PS_C1
="\[\033[1;96m\]" # cyan
185 PS_C2
="\[\033[0;36m\]" # cyan
188 PS_C1
="\[\033[1;93m\]" # yellow
189 PS_C2
="\[\033[0;33m\]" # brown
202 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
207 # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
208 # never show branch info for $HOME (dotfiles) repo.
209 # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
210 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
211 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
212 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
213 test "$(git config --bool bash.hidePrompt)" != "true" &&
214 __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")'
215 export GIT_PS1_SHOWDIRTYSTATE
=1
217 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\] "
221 # ----------------------------------------------------------------------
222 # MACOS X / DARWIN SPECIFIC
223 # ----------------------------------------------------------------------
225 if [ "$UNAME" = Darwin
]; then
226 # put ports on the paths if /opt/local exists
227 test -x /opt
/local -a ! -L /opt
/local && {
230 # setup the PATH and MANPATH
231 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
232 MANPATH
="$PORTS/share/man:$MANPATH"
234 # nice little port alias
235 alias port
="sudo nice -n +18 $PORTS/bin/port"
237 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
238 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
239 # setup the PATH and MANPATH
240 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
241 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
245 # ----------------------------------------------------------------------
246 # ALIASES / FUNCTIONS
247 # ----------------------------------------------------------------------
252 alias ll.
="ls -ld .*"
255 # use 'git diff --no-index' as a prettier 'diff' alternative (if available)
256 test -n "$(type -P git)" && alias diff="git diff --no-index"
258 # alias 'vi' to 'vim' if Vim is installed
265 # disk usage with human sizes and minimal depth
266 alias du1
='du -h --max-depth=1'
267 alias fn
='find . -name'
268 alias hi
='history | tail -20'
270 # for Solaris, use GNU versions of core utils
271 if [ "$UNAME" = SunOS
]; then
272 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
273 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
274 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
277 # alias csh-style "rebash" to bash equivalent
278 alias rehash
="hash -r"
280 # set 'screen' window title
282 printf "\033k%s\033\\" "$@"
286 alias svn
=svn
-wrapper
288 # ----------------------------------------------------------------------
290 # ----------------------------------------------------------------------
292 test -z "$BASH_COMPLETION" && {
293 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
294 test -n "$PS1" && test $bmajor -gt 1 && {
295 # search for a bash_completion file to source
296 for f
in /usr
/local
/etc
/bash_completion \
297 /usr
/pkg
/etc
/bash_completion \
298 /opt
/local
/etc
/bash_completion \
307 unset bash bmajor bminor
310 # override and disable tilde expansion
315 # ----------------------------------------------------------------------
317 # ----------------------------------------------------------------------
319 # we always pass these to ls(1)
322 # if the dircolors utility is available, set that up for ls
323 dircolors
="$(type -P gdircolors dircolors | head -1)"
324 test -n "$dircolors" && {
325 COLORS
=/etc
/DIR_COLORS
326 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
327 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
328 test ! -e "$COLORS" && COLORS
=
329 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
330 test "$UNAME" = "AIX" && COLORS
=
331 eval `$dircolors --sh $COLORS`
335 # enable color ls output if available
337 LS_COMMON
="--color=auto $LS_COMMON"
339 # setup the main ls alias if we've established common args
340 test -n "$LS_COMMON" &&
341 alias ls="command ls $LS_COMMON"
343 # setup color grep output if available
344 if [ -n "$COLORS" ]; then
347 # for Solaris, use the GNU version of grep for color support
348 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
351 alias grep="command grep --color=always"
354 # older versions of grep only support a singular highlight color
355 export GREP_COLOR
='1;37;42'
356 # newer versions of grep have more flexible color configuration
357 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
360 # --------------------------------------------------------------------
362 # --------------------------------------------------------------------
364 # push SSH public key to another box
367 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
371 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
375 # --------------------------------------------------------------------
376 # PATH MANIPULATION FUNCTIONS
377 # --------------------------------------------------------------------
380 # List path entries of PATH or environment variable <var>.
381 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
383 # Usage: pshift [-n <num>] [<var>]
384 # Shift <num> entries off the front of PATH or environment var <var>.
385 # with the <var> option. Useful: pshift $(pwd)
388 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
389 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
392 # Usage: ppop [-n <num>] [<var>]
393 # Pop <num> entries off the end of PATH or environment variable <var>.
396 [ "$1" = "-n" ] && { n
=$2; shift 2; }
398 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
403 # Usage: prm <path> [<var>]
404 # Remove <path> from PATH or environment variable <var>.
405 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
407 # Usage: punshift <path> [<var>]
408 # Shift <path> onto the beginning of PATH or environment variable <var>.
409 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
411 # Usage: ppush <path> [<var>]
412 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
414 # Usage: puniq [<path>]
415 # Remove duplicate entries from a PATH style value while retaining
416 # the original order. Use PATH if no <path> is given.
419 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
420 # /usr/bin:/usr/local/bin
422 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
423 cut
-f 2- | tr '\n' :
426 # -------------------------------------------------------------------
427 # USER SHELL ENVIRONMENT
428 # -------------------------------------------------------------------
430 # source ~/.shenv now if it exists
434 # condense PATH entries
435 PATH
=$(puniq "$PATH")
436 MANPATH
=$(puniq "$MANPATH")
438 # use the color prompt by default when interactive
442 # -------------------------------------------------------------------
444 # -------------------------------------------------------------------
446 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
447 # get current uname and uptime (if exists on this host)
448 # strip any leading whitespace from uname and uptime commands
449 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
450 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
451 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
453 test -n "$t_uname" && echo $t_uname
454 test -n "$t_uptime" && echo $t_uptime
457 unset t_uname t_uptime
460 # vim: ts=4 sts=4 shiftwidth=4 expandtab