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 # ----------------------------------------------------------------------
228 # ----------------------------------------------------------------------
230 test -z "$BASH_COMPLETION" && {
231 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
232 test -n "$PS1" && test $bmajor -gt 1 && {
233 # search for a bash_completion file to source
234 for f
in /usr
/local
/etc
/bash_completion \
235 /usr
/pkg
/etc
/bash_completion \
236 /opt
/local
/etc
/bash_completion \
245 unset bash bmajor bminor
248 # override and disable tilde expansion
253 # ----------------------------------------------------------------------
255 # ----------------------------------------------------------------------
257 # we always pass these to ls(1)
259 ## OS-specific options
261 # "Linux" ) LS_COMMON="--color=auto";;
262 # "Cygwin" ) LS_COMMON="--color=auto";;
263 # "Darwin" ) LS_COMMON="--color=auto";;
266 # if the dircolors utility is available, set that up for ls
267 dircolors
="$(type -P gdircolors dircolors | head -1)"
268 test -n "$dircolors" && {
269 COLORS
=/etc
/DIR_COLORS
270 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
271 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
272 test ! -e "$COLORS" && COLORS
=
273 eval `$dircolors --sh $COLORS`
277 # enable color ls output if available
279 LS_COMMON
="--color=auto $LS_COMMON"
281 # setup the main ls alias if we've established common args
282 test -n "$LS_COMMON" &&
283 alias ls="command ls $LS_COMMON"
285 # these use the ls aliases above
288 alias ll.
="ls -ld .*"
291 # setup color grep output if available
292 if [ -n "$COLORS" ]; then
295 # For Solaris, use the GNU version of grep for color support
296 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
299 alias grep="command grep --color=auto"
304 # --------------------------------------------------------------------
306 # --------------------------------------------------------------------
308 # push SSH public key to another box
311 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
315 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
319 # --------------------------------------------------------------------
320 # PATH MANIPULATION FUNCTIONS
321 # --------------------------------------------------------------------
324 # List path entries of PATH or environment variable <var>.
325 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
327 # Usage: pshift [-n <num>] [<var>]
328 # Shift <num> entries off the front of PATH or environment var <var>.
329 # with the <var> option. Useful: pshift $(pwd)
332 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
333 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
336 # Usage: ppop [-n <num>] [<var>]
337 # Pop <num> entries off the end of PATH or environment variable <var>.
340 [ "$1" = "-n" ] && { n
=$2; shift 2; }
342 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
347 # Usage: prm <path> [<var>]
348 # Remove <path> from PATH or environment variable <var>.
349 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
351 # Usage: punshift <path> [<var>]
352 # Shift <path> onto the beginning of PATH or environment variable <var>.
353 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
355 # Usage: ppush <path> [<var>]
356 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
358 # Usage: puniq [<path>]
359 # Remove duplicate entries from a PATH style value while retaining
360 # the original order. Use PATH if no <path> is given.
363 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
364 # /usr/bin:/usr/local/bin
366 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
367 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
370 # -------------------------------------------------------------------
371 # USER SHELL ENVIRONMENT
372 # -------------------------------------------------------------------
374 # source ~/.shenv now if it exists
378 # condense PATH entries
380 MANPATH
=$(puniq $MANPATH)
382 # Use the color prompt by default when interactive
386 # -------------------------------------------------------------------
388 # -------------------------------------------------------------------
390 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
391 # Get current uname and uptime (if exists on this host)
392 # Strip any leading whitespace from uname and uptime commands
393 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
394 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
395 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
397 test -n "$t_uname" && echo $t_uname
398 test -n "$t_uptime" && echo $t_uptime
401 unset t_uname t_uptime
404 # vim: ts=4 sts=4 shiftwidth=4 expandtab