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 # ----------------------------------------------------------------------
36 # ----------------------------------------------------------------------
38 # bring in system bashrc
39 test -r /etc
/bashrc
&&
42 # notify of bg job completion immediately
45 # shell opts. see bash(1) for details
46 shopt -s cdspell
>/dev
/null
2>&1
47 shopt -s extglob
>/dev
/null
2>&1
48 shopt -s histappend
>/dev
/null
2>&1
49 shopt -s hostcomplete
>/dev
/null
2>&1
50 shopt -s interactive_comments
>/dev
/null
2>&1
51 shopt -u mailwarn
>/dev
/null
2>&1
52 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
54 # don't check for new mail
63 # ----------------------------------------------------------------------
65 # ----------------------------------------------------------------------
67 # we want the various sbin's on the path along with /usr/local/bin
68 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
69 PATH
="/usr/local/bin:$PATH"
71 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
73 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
75 # ~/.rvm/bin on PATH if exists (RVM)
76 test -d "$HOME/.rvm/bin" &&
77 PATH
="$PATH:$HOME/.rvm/bin"
79 # put ~/bin on PATH if exists
80 test -d "$HOME/bin" &&
81 PATH
="$HOME/bin:$PATH"
83 # put ~/sbin on PATH if exists
84 test -d "$HOME/sbin" &&
85 PATH
="$HOME/sbin:$PATH"
87 # ----------------------------------------------------------------------
88 # ENVIRONMENT CONFIGURATION
89 # ----------------------------------------------------------------------
91 # detect interactive shell
93 *i
*) INTERACTIVE
=yes ;;
94 *) unset INTERACTIVE
;;
103 # enable en_US locale w/ utf-8 encodings if not already
105 : ${LANG:="en_US.UTF-8"}
107 : ${LC_CTYPE:="en_US.UTF-8"}
108 : ${LC_ALL:="en_US.UTF-8"}
109 export LANG LANGUAGE LC_CTYPE LC_ALL
111 # ignore backups, CVS directories, python bytecode, vim swap files
112 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
115 HISTCONTROL
=ignoreboth
119 # ----------------------------------------------------------------------
121 # ----------------------------------------------------------------------
123 # See what we have to work with ...
124 HAVE_VIM
=$(command -v vim)
127 test -n "$HAVE_VIM" &&
133 if test -n "$(command -v less)" ; then
142 export PAGER MANPAGER
146 ACK_PAGER_COLOR
="$PAGER"
148 # ----------------------------------------------------------------------
150 # ----------------------------------------------------------------------
152 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
154 if [ "$UID" = 0 ]; then
156 PS_C1
="\[\033[1;31m\]" # red
157 PS_C2
="\[\033[0;37m\]" # grey
162 PS_C1
="\[\033[0;32m\]" # green
163 PS_C2
="\[\033[0;37m\]" # grey
166 PS_C1
="\[\033[1;97m\]" # white
167 PS_C2
="\[\033[0;37m\]" # grey
170 PS_C1
="\[\033[1;96m\]" # cyan
171 PS_C2
="\[\033[0;36m\]" # cyan
174 PS_C1
="\[\033[1;93m\]" # yellow
175 PS_C2
="\[\033[0;33m\]" # brown
188 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
193 # If git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
194 # Never show branch info for $HOME (dotfiles) repo.
195 # Use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
196 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
197 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
198 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
199 test "$(git config --bool bash.hidePrompt)" != "true" &&
200 __git_ps1 "{\[\033[0;100m\]%s\[\033[0;90m\]}")'
201 export GIT_PS1_SHOWDIRTYSTATE
=1
203 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\] "
207 # ----------------------------------------------------------------------
208 # MACOS X / DARWIN SPECIFIC
209 # ----------------------------------------------------------------------
211 if [ "$UNAME" = Darwin
]; then
212 # put ports on the paths if /opt/local exists
213 test -x /opt
/local -a ! -L /opt
/local && {
216 # setup the PATH and MANPATH
217 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
218 MANPATH
="$PORTS/share/man:$MANPATH"
220 # nice little port alias
221 alias port
="sudo nice -n +18 $PORTS/bin/port"
223 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
224 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
225 # setup the PATH and MANPATH
226 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
227 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
231 # ----------------------------------------------------------------------
232 # ALIASES / FUNCTIONS
233 # ----------------------------------------------------------------------
235 # alias 'vi' to 'vim' if Vim is installed
242 # disk usage with human sizes and minimal depth
243 alias du1
='du -h --max-depth=1'
244 alias fn
='find . -name'
245 alias hi
='history | tail -20'
247 # For Solaris, use GNU versions of core utils
248 if [ "$UNAME" = SunOS
]; then
249 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
250 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
251 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
254 # Alias csh-style "rebash" to bash equivalent
255 alias rehash
="hash -r"
257 # ----------------------------------------------------------------------
259 # ----------------------------------------------------------------------
261 test -z "$BASH_COMPLETION" && {
262 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
263 test -n "$PS1" && test $bmajor -gt 1 && {
264 # search for a bash_completion file to source
265 for f
in /usr
/local
/etc
/bash_completion \
266 /usr
/pkg
/etc
/bash_completion \
267 /opt
/local
/etc
/bash_completion \
276 unset bash bmajor bminor
279 # override and disable tilde expansion
284 # ----------------------------------------------------------------------
286 # ----------------------------------------------------------------------
288 # we always pass these to ls(1)
290 ## OS-specific options
292 # "Linux" ) LS_COMMON="--color=auto";;
293 # "Cygwin" ) LS_COMMON="--color=auto";;
294 # "Darwin" ) LS_COMMON="--color=auto";;
297 # if the dircolors utility is available, set that up for ls
298 dircolors
="$(type -P gdircolors dircolors | head -1)"
299 test -n "$dircolors" && {
300 COLORS
=/etc
/DIR_COLORS
301 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
302 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
303 test ! -e "$COLORS" && COLORS
=
304 eval `$dircolors --sh $COLORS`
308 # enable color ls output if available
310 LS_COMMON
="--color=auto $LS_COMMON"
312 # setup the main ls alias if we've established common args
313 test -n "$LS_COMMON" &&
314 alias ls="command ls $LS_COMMON"
316 # these use the ls aliases above
319 alias ll.
="ls -ld .*"
322 # setup color grep output if available
323 if [ -n "$COLORS" ]; then
326 # For Solaris, use the GNU version of grep for color support
327 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
330 alias grep="command grep --color=always"
333 # older versions of grep only support a singular highlight color
334 export GREP_COLOR
='1;37;42'
335 # newer versions of grep have more flexible color configuration
336 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
339 # --------------------------------------------------------------------
341 # --------------------------------------------------------------------
343 # push SSH public key to another box
346 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
350 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
354 # --------------------------------------------------------------------
355 # PATH MANIPULATION FUNCTIONS
356 # --------------------------------------------------------------------
359 # List path entries of PATH or environment variable <var>.
360 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
362 # Usage: pshift [-n <num>] [<var>]
363 # Shift <num> entries off the front of PATH or environment var <var>.
364 # with the <var> option. Useful: pshift $(pwd)
367 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
368 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
371 # Usage: ppop [-n <num>] [<var>]
372 # Pop <num> entries off the end of PATH or environment variable <var>.
375 [ "$1" = "-n" ] && { n
=$2; shift 2; }
377 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
382 # Usage: prm <path> [<var>]
383 # Remove <path> from PATH or environment variable <var>.
384 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
386 # Usage: punshift <path> [<var>]
387 # Shift <path> onto the beginning of PATH or environment variable <var>.
388 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
390 # Usage: ppush <path> [<var>]
391 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
393 # Usage: puniq [<path>]
394 # Remove duplicate entries from a PATH style value while retaining
395 # the original order. Use PATH if no <path> is given.
398 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
399 # /usr/bin:/usr/local/bin
401 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
402 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
405 # -------------------------------------------------------------------
406 # USER SHELL ENVIRONMENT
407 # -------------------------------------------------------------------
409 # source ~/.shenv now if it exists
413 # condense PATH entries
414 PATH
=$(puniq "$PATH")
415 MANPATH
=$(puniq "$MANPATH")
417 # Use the color prompt by default when interactive
421 # -------------------------------------------------------------------
423 # -------------------------------------------------------------------
425 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
426 # Get current uname and uptime (if exists on this host)
427 # Strip any leading whitespace from uname and uptime commands
428 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
429 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
430 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
432 test -n "$t_uname" && echo $t_uname
433 test -n "$t_uptime" && echo $t_uptime
436 unset t_uname t_uptime
439 # vim: ts=4 sts=4 shiftwidth=4 expandtab