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
20 case $(tput colors 2>&1) in
22 export TERM
=xterm
-color
26 if [ "$UNAME" = "Darwin" ]; then
28 test -r /sw
/bin
/init.sh
&&
29 source /sw
/bin
/init.sh
32 # ----------------------------------------------------------------------
34 # ----------------------------------------------------------------------
36 # bring in system bashrc
37 test -r /etc
/bashrc
&&
40 # notify of bg job completion immediately
43 # shell opts. see bash(1) for details
44 shopt -s cdspell
>/dev
/null
2>&1
45 shopt -s extglob
>/dev
/null
2>&1
46 shopt -s histappend
>/dev
/null
2>&1
47 shopt -s hostcomplete
>/dev
/null
2>&1
48 shopt -s interactive_comments
>/dev
/null
2>&1
49 shopt -u mailwarn
>/dev
/null
2>&1
50 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
52 # don't check for new mail
61 # ----------------------------------------------------------------------
63 # ----------------------------------------------------------------------
65 # we want the various sbins on the path along with /usr/local/bin
66 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
67 PATH
="/usr/local/bin:$PATH"
69 # put ~/bin on PATH if you have it
70 test -d "$HOME/bin" &&
71 PATH
="$HOME/bin:$PATH"
73 # ----------------------------------------------------------------------
74 # ENVIRONMENT CONFIGURATION
75 # ----------------------------------------------------------------------
77 # detect interactive shell
79 *i
*) INTERACTIVE
=yes ;;
80 *) unset INTERACTIVE
;;
89 # enable en_US locale w/ utf-8 encodings if not already
91 : ${LANG:="en_US.UTF-8"}
93 : ${LC_CTYPE:="en_US.UTF-8"}
94 : ${LC_ALL:="en_US.UTF-8"}
95 export LANG LANGUAGE LC_CTYPE LC_ALL
97 # ignore backups, CVS directories, python bytecode, vim swap files
98 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
101 HISTCONTROL
=ignoreboth
105 # ----------------------------------------------------------------------
107 # ----------------------------------------------------------------------
109 # See what we have to work with ...
110 HAVE_VIM
=$(command -v vim)
113 test -n "$HAVE_VIM" &&
119 if test -n "$(command -v less)" ; then
121 MANPAGER
="less -FiRswX"
126 export PAGER MANPAGER
130 ACK_PAGER_COLOR
="$PAGER"
132 # ----------------------------------------------------------------------
134 # ----------------------------------------------------------------------
136 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
138 if [ "$UID" = 0 ]; then
140 PS_C1
="\[\033[1;31m\]" # red
141 PS_C2
="\[\033[0;37m\]" # grey
146 PS_C1
="\[\033[0;32m\]" # green
147 PS_C2
="\[\033[0;37m\]" # grey
150 PS_C1
="\[\033[1;97m\]" # white
151 PS_C2
="\[\033[0;37m\]" # grey
154 PS_C1
="\[\033[1;96m\]" # cyan
155 PS_C2
="\[\033[0;36m\]" # cyan
158 PS_C1
="\[\033[1;93m\]" # yellow
159 PS_C2
="\[\033[0;33m\]" # brown
172 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
177 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
181 # ----------------------------------------------------------------------
182 # MACOS X / DARWIN SPECIFIC
183 # ----------------------------------------------------------------------
185 if [ "$UNAME" = Darwin
]; then
186 # put ports on the paths if /opt/local exists
187 test -x /opt
/local -a ! -L /opt
/local && {
190 # setup the PATH and MANPATH
191 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
192 MANPATH
="$PORTS/share/man:$MANPATH"
194 # nice little port alias
195 alias port
="sudo nice -n +18 $PORTS/bin/port"
199 # ----------------------------------------------------------------------
200 # ALIASES / FUNCTIONS
201 # ----------------------------------------------------------------------
203 # alias 'vi' to 'vim' if Vim is installed
210 # disk usage with human sizes and minimal depth
211 alias du1
='du -h --max-depth=1'
212 alias fn
='find . -name'
213 alias hi
='history | tail -20'
215 # For Solaris, use GNU versions of grep and sed
216 if [ "$UNAME" = SunOS
]; then
217 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
218 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
221 # ----------------------------------------------------------------------
223 # ----------------------------------------------------------------------
225 test -z "$BASH_COMPLETION" && {
226 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
227 test -n "$PS1" && test $bmajor -gt 1 && {
228 # search for a bash_completion file to source
229 for f
in /usr
/local
/etc
/bash_completion \
230 /usr
/pkg
/etc
/bash_completion \
231 /opt
/local
/etc
/bash_completion \
240 unset bash bmajor bminor
243 # override and disable tilde expansion
248 # ----------------------------------------------------------------------
250 # ----------------------------------------------------------------------
252 # we always pass these to ls(1)
254 ## OS-specific options
256 # "Linux" ) LS_COMMON="--color=auto";;
257 # "Cygwin" ) LS_COMMON="--color=auto";;
258 # "Darwin" ) LS_COMMON="--color=auto";;
261 # if the dircolors utility is available, set that up for ls
262 dircolors
="$(type -P gdircolors dircolors | head -1)"
263 test -n "$dircolors" && {
264 COLORS
=/etc
/DIR_COLORS
265 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
266 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
267 test ! -e "$COLORS" && COLORS
=
268 eval `$dircolors --sh $COLORS`
272 # enable color ls output if available
274 LS_COMMON
="--color=auto $LS_COMMON"
276 # setup the main ls alias if we've established common args
277 test -n "$LS_COMMON" &&
278 alias ls="command ls $LS_COMMON"
280 # these use the ls aliases above
283 alias ll.
="ls -ld .*"
286 # setup color grep output if available
287 if [ -n "$COLORS" ]; then
290 # For Solaris, use the GNU version of grep for color support
291 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
294 alias grep="command grep --color=auto"
299 # --------------------------------------------------------------------
301 # --------------------------------------------------------------------
303 # push SSH public key to another box
306 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
310 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
314 # --------------------------------------------------------------------
315 # PATH MANIPULATION FUNCTIONS
316 # --------------------------------------------------------------------
319 # List path entries of PATH or environment variable <var>.
320 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
322 # Usage: pshift [-n <num>] [<var>]
323 # Shift <num> entries off the front of PATH or environment var <var>.
324 # with the <var> option. Useful: pshift $(pwd)
327 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
328 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
331 # Usage: ppop [-n <num>] [<var>]
332 # Pop <num> entries off the end of PATH or environment variable <var>.
335 [ "$1" = "-n" ] && { n
=$2; shift 2; }
337 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
342 # Usage: prm <path> [<var>]
343 # Remove <path> from PATH or environment variable <var>.
344 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
346 # Usage: punshift <path> [<var>]
347 # Shift <path> onto the beginning of PATH or environment variable <var>.
348 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
350 # Usage: ppush <path> [<var>]
351 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
353 # Usage: puniq [<path>]
354 # Remove duplicate entries from a PATH style value while retaining
355 # the original order. Use PATH if no <path> is given.
358 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
359 # /usr/bin:/usr/local/bin
361 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
362 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
365 # -------------------------------------------------------------------
366 # USER SHELL ENVIRONMENT
367 # -------------------------------------------------------------------
369 # source ~/.shenv now if it exists
373 # condense PATH entries
375 MANPATH
=$(puniq $MANPATH)
377 # Use the color prompt by default when interactive
381 # -------------------------------------------------------------------
383 # -------------------------------------------------------------------
385 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
386 # Get current uname and uptime (if exists on this host)
387 # Strip any leading whitespace from uname and uptime commands
388 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
389 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
390 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
392 test -n "$t_uname" && echo $t_uname
393 test -n "$t_uptime" && echo $t_uptime
396 unset t_uname t_uptime
399 # vim: ts=4 sts=4 shiftwidth=4 expandtab