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)
10 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
11 UNAME
=${UNAME/CYGWIN_*/Cygwin}
13 # complete hostnames from this file
14 HOSTFILE
=~
/.ssh
/known_hosts
19 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
20 case $(tput colors 2>&1) in
22 export TERM
=xterm
-color
23 case $(tput colors 2>&1) in
31 if [ "$UNAME" = "Darwin" ]; then
33 test -r /sw
/bin
/init.sh
&&
34 source /sw
/bin
/init.sh
37 # ----------------------------------------------------------------------
39 # ----------------------------------------------------------------------
41 # bring in system bashrc
42 test -r /etc
/bashrc
&&
45 # notify of bg job completion immediately
48 # shell opts. see bash(1) for details
49 shopt -s cdspell
>/dev
/null
2>&1
50 shopt -s extglob
>/dev
/null
2>&1
51 shopt -s histappend
>/dev
/null
2>&1
52 shopt -s hostcomplete
>/dev
/null
2>&1
53 shopt -s interactive_comments
>/dev
/null
2>&1
54 shopt -u mailwarn
>/dev
/null
2>&1
55 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
57 # don't check for new mail
66 # ----------------------------------------------------------------------
68 # ----------------------------------------------------------------------
70 # we want the various sbins on the path along with /usr/local/bin
71 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
72 PATH
="/usr/local/bin:$PATH"
74 # put ~/bin on PATH if you have it
75 test -d "$HOME/bin" &&
76 PATH
="$HOME/bin:$PATH"
78 # ----------------------------------------------------------------------
79 # ENVIRONMENT CONFIGURATION
80 # ----------------------------------------------------------------------
82 # detect interactive shell
84 *i
*) INTERACTIVE
=yes ;;
85 *) unset INTERACTIVE
;;
94 # enable en_US locale w/ utf-8 encodings if not already
96 : ${LANG:="en_US.UTF-8"}
98 : ${LC_CTYPE:="en_US.UTF-8"}
99 : ${LC_ALL:="en_US.UTF-8"}
100 export LANG LANGUAGE LC_CTYPE LC_ALL
102 # ignore backups, CVS directories, python bytecode, vim swap files
103 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
106 HISTCONTROL
=ignoreboth
110 # ----------------------------------------------------------------------
112 # ----------------------------------------------------------------------
114 # See what we have to work with ...
115 HAVE_VIM
=$(command -v vim)
118 test -n "$HAVE_VIM" &&
124 if test -n "$(command -v less)" ; then
126 MANPAGER
="less -FiRs"
131 export PAGER MANPAGER
135 ACK_PAGER_COLOR
="$PAGER"
137 # ----------------------------------------------------------------------
139 # ----------------------------------------------------------------------
141 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
143 if [ "$UID" = 0 ]; then
145 PS_C1
="\[\033[1;31m\]" # red
146 PS_C2
="\[\033[0;37m\]" # grey
151 PS_C1
="\[\033[0;32m\]" # green
152 PS_C2
="\[\033[0;37m\]" # grey
155 PS_C1
="\[\033[1;97m\]" # white
156 PS_C2
="\[\033[0;37m\]" # grey
159 PS_C1
="\[\033[1;96m\]" # cyan
160 PS_C2
="\[\033[0;36m\]" # cyan
163 PS_C1
="\[\033[1;93m\]" # yellow
164 PS_C2
="\[\033[0;33m\]" # brown
177 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
182 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
186 # ----------------------------------------------------------------------
187 # MACOS X / DARWIN SPECIFIC
188 # ----------------------------------------------------------------------
190 if [ "$UNAME" = Darwin
]; then
191 # put ports on the paths if /opt/local exists
192 test -x /opt
/local -a ! -L /opt
/local && {
195 # setup the PATH and MANPATH
196 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
197 MANPATH
="$PORTS/share/man:$MANPATH"
199 # nice little port alias
200 alias port
="sudo nice -n +18 $PORTS/bin/port"
204 # ----------------------------------------------------------------------
205 # ALIASES / FUNCTIONS
206 # ----------------------------------------------------------------------
208 # alias 'vi' to 'vim' if Vim is installed
215 # disk usage with human sizes and minimal depth
216 alias du1
='du -h --max-depth=1'
217 alias fn
='find . -name'
218 alias hi
='history | tail -20'
220 # For Solaris, use GNU versions of grep and sed
221 if [ "$UNAME" = SunOS
]; then
222 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
223 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
226 # Alias csh-style "rebash" to bash equivalent
227 alias rehash
="hash -r"
229 # ----------------------------------------------------------------------
231 # ----------------------------------------------------------------------
233 test -z "$BASH_COMPLETION" && {
234 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
235 test -n "$PS1" && test $bmajor -gt 1 && {
236 # search for a bash_completion file to source
237 for f
in /usr
/local
/etc
/bash_completion \
238 /usr
/pkg
/etc
/bash_completion \
239 /opt
/local
/etc
/bash_completion \
248 unset bash bmajor bminor
251 # override and disable tilde expansion
256 # ----------------------------------------------------------------------
258 # ----------------------------------------------------------------------
260 # we always pass these to ls(1)
262 ## OS-specific options
264 # "Linux" ) LS_COMMON="--color=auto";;
265 # "Cygwin" ) LS_COMMON="--color=auto";;
266 # "Darwin" ) LS_COMMON="--color=auto";;
269 # if the dircolors utility is available, set that up for ls
270 dircolors
="$(type -P gdircolors dircolors | head -1)"
271 test -n "$dircolors" && {
272 COLORS
=/etc
/DIR_COLORS
273 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
274 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
275 test ! -e "$COLORS" && COLORS
=
276 eval `$dircolors --sh $COLORS`
280 # enable color ls output if available
282 LS_COMMON
="--color=auto $LS_COMMON"
284 # setup the main ls alias if we've established common args
285 test -n "$LS_COMMON" &&
286 alias ls="command ls $LS_COMMON"
288 # these use the ls aliases above
291 alias ll.
="ls -ld .*"
294 # setup color grep output if available
295 if [ -n "$COLORS" ]; then
298 # For Solaris, use the GNU version of grep for color support
299 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
302 alias grep="command grep --color=auto"
307 # --------------------------------------------------------------------
309 # --------------------------------------------------------------------
311 # push SSH public key to another box
314 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
318 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
322 # --------------------------------------------------------------------
323 # PATH MANIPULATION FUNCTIONS
324 # --------------------------------------------------------------------
327 # List path entries of PATH or environment variable <var>.
328 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
330 # Usage: pshift [-n <num>] [<var>]
331 # Shift <num> entries off the front of PATH or environment var <var>.
332 # with the <var> option. Useful: pshift $(pwd)
335 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
336 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
339 # Usage: ppop [-n <num>] [<var>]
340 # Pop <num> entries off the end of PATH or environment variable <var>.
343 [ "$1" = "-n" ] && { n
=$2; shift 2; }
345 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
350 # Usage: prm <path> [<var>]
351 # Remove <path> from PATH or environment variable <var>.
352 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
354 # Usage: punshift <path> [<var>]
355 # Shift <path> onto the beginning of PATH or environment variable <var>.
356 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
358 # Usage: ppush <path> [<var>]
359 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
361 # Usage: puniq [<path>]
362 # Remove duplicate entries from a PATH style value while retaining
363 # the original order. Use PATH if no <path> is given.
366 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
367 # /usr/bin:/usr/local/bin
369 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
370 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
373 # -------------------------------------------------------------------
374 # USER SHELL ENVIRONMENT
375 # -------------------------------------------------------------------
377 # source ~/.shenv now if it exists
381 # condense PATH entries
383 MANPATH
=$(puniq $MANPATH)
385 # Use the color prompt by default when interactive
389 # -------------------------------------------------------------------
391 # -------------------------------------------------------------------
393 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
394 # Get current uname and uptime (if exists on this host)
395 # Strip any leading whitespace from uname and uptime commands
396 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
397 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
398 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
400 test -n "$t_uname" && echo $t_uname
401 test -n "$t_uptime" && echo $t_uptime
404 unset t_uname t_uptime
407 # vim: ts=4 sts=4 shiftwidth=4 expandtab