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 if [ "$UNAME" = "Darwin" ]; then
36 test -r /sw
/bin
/init.sh
&&
37 source /sw
/bin
/init.sh
40 # ----------------------------------------------------------------------
42 # ----------------------------------------------------------------------
44 # bring in system bashrc
45 test -r /etc
/bashrc
&&
48 # notify of bg job completion immediately
51 # shell opts. see bash(1) for details
52 shopt -s cdspell
>/dev
/null
2>&1
53 shopt -s extglob
>/dev
/null
2>&1
54 shopt -s histappend
>/dev
/null
2>&1
55 shopt -s hostcomplete
>/dev
/null
2>&1
56 shopt -s interactive_comments
>/dev
/null
2>&1
57 shopt -u mailwarn
>/dev
/null
2>&1
58 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
60 # don't check for new mail
69 # ----------------------------------------------------------------------
71 # ----------------------------------------------------------------------
73 # we want the various sbins on the path along with /usr/local/bin
74 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
75 PATH
="/usr/local/bin:$PATH"
77 # put ~/bin on PATH if you have it
78 test -d "$HOME/bin" &&
79 PATH
="$HOME/bin:$PATH"
81 # ----------------------------------------------------------------------
82 # ENVIRONMENT CONFIGURATION
83 # ----------------------------------------------------------------------
85 # detect interactive shell
87 *i
*) INTERACTIVE
=yes ;;
88 *) unset INTERACTIVE
;;
97 # enable en_US locale w/ utf-8 encodings if not already
99 : ${LANG:="en_US.UTF-8"}
101 : ${LC_CTYPE:="en_US.UTF-8"}
102 : ${LC_ALL:="en_US.UTF-8"}
103 export LANG LANGUAGE LC_CTYPE LC_ALL
105 # ignore backups, CVS directories, python bytecode, vim swap files
106 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
109 HISTCONTROL
=ignoreboth
113 # ----------------------------------------------------------------------
115 # ----------------------------------------------------------------------
117 # See what we have to work with ...
118 HAVE_VIM
=$(command -v vim)
121 test -n "$HAVE_VIM" &&
127 if test -n "$(command -v less)" ; then
129 MANPAGER
="less -FiRs"
134 export PAGER MANPAGER
138 ACK_PAGER_COLOR
="$PAGER"
140 # ----------------------------------------------------------------------
142 # ----------------------------------------------------------------------
144 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
146 if [ "$UID" = 0 ]; then
148 PS_C1
="\[\033[1;31m\]" # red
149 PS_C2
="\[\033[0;37m\]" # grey
154 PS_C1
="\[\033[0;32m\]" # green
155 PS_C2
="\[\033[0;37m\]" # grey
158 PS_C1
="\[\033[1;97m\]" # white
159 PS_C2
="\[\033[0;37m\]" # grey
162 PS_C1
="\[\033[1;96m\]" # cyan
163 PS_C2
="\[\033[0;36m\]" # cyan
166 PS_C1
="\[\033[1;93m\]" # yellow
167 PS_C2
="\[\033[0;33m\]" # brown
180 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
185 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
189 # ----------------------------------------------------------------------
190 # MACOS X / DARWIN SPECIFIC
191 # ----------------------------------------------------------------------
193 if [ "$UNAME" = Darwin
]; then
194 # put ports on the paths if /opt/local exists
195 test -x /opt
/local -a ! -L /opt
/local && {
198 # setup the PATH and MANPATH
199 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
200 MANPATH
="$PORTS/share/man:$MANPATH"
202 # nice little port alias
203 alias port
="sudo nice -n +18 $PORTS/bin/port"
207 # ----------------------------------------------------------------------
208 # ALIASES / FUNCTIONS
209 # ----------------------------------------------------------------------
211 # alias 'vi' to 'vim' if Vim is installed
218 # disk usage with human sizes and minimal depth
219 alias du1
='du -h --max-depth=1'
220 alias fn
='find . -name'
221 alias hi
='history | tail -20'
223 # For Solaris, use GNU versions of grep and sed
224 if [ "$UNAME" = SunOS
]; then
225 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
226 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
229 # Alias csh-style "rebash" to bash equivalent
230 alias rehash
="hash -r"
232 # ----------------------------------------------------------------------
234 # ----------------------------------------------------------------------
236 test -z "$BASH_COMPLETION" && {
237 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
238 test -n "$PS1" && test $bmajor -gt 1 && {
239 # search for a bash_completion file to source
240 for f
in /usr
/local
/etc
/bash_completion \
241 /usr
/pkg
/etc
/bash_completion \
242 /opt
/local
/etc
/bash_completion \
251 unset bash bmajor bminor
254 # override and disable tilde expansion
259 # ----------------------------------------------------------------------
261 # ----------------------------------------------------------------------
263 # we always pass these to ls(1)
265 ## OS-specific options
267 # "Linux" ) LS_COMMON="--color=auto";;
268 # "Cygwin" ) LS_COMMON="--color=auto";;
269 # "Darwin" ) LS_COMMON="--color=auto";;
272 # if the dircolors utility is available, set that up for ls
273 dircolors
="$(type -P gdircolors dircolors | head -1)"
274 test -n "$dircolors" && {
275 COLORS
=/etc
/DIR_COLORS
276 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
277 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
278 test ! -e "$COLORS" && COLORS
=
279 eval `$dircolors --sh $COLORS`
283 # enable color ls output if available
285 LS_COMMON
="--color=auto $LS_COMMON"
287 # setup the main ls alias if we've established common args
288 test -n "$LS_COMMON" &&
289 alias ls="command ls $LS_COMMON"
291 # these use the ls aliases above
294 alias ll.
="ls -ld .*"
297 # setup color grep output if available
298 if [ -n "$COLORS" ]; then
301 # For Solaris, use the GNU version of grep for color support
302 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
305 alias grep="command grep --color=auto"
310 # --------------------------------------------------------------------
312 # --------------------------------------------------------------------
314 # push SSH public key to another box
317 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
321 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
325 # --------------------------------------------------------------------
326 # PATH MANIPULATION FUNCTIONS
327 # --------------------------------------------------------------------
330 # List path entries of PATH or environment variable <var>.
331 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
333 # Usage: pshift [-n <num>] [<var>]
334 # Shift <num> entries off the front of PATH or environment var <var>.
335 # with the <var> option. Useful: pshift $(pwd)
338 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
339 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
342 # Usage: ppop [-n <num>] [<var>]
343 # Pop <num> entries off the end of PATH or environment variable <var>.
346 [ "$1" = "-n" ] && { n
=$2; shift 2; }
348 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
353 # Usage: prm <path> [<var>]
354 # Remove <path> from PATH or environment variable <var>.
355 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
357 # Usage: punshift <path> [<var>]
358 # Shift <path> onto the beginning of PATH or environment variable <var>.
359 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
361 # Usage: ppush <path> [<var>]
362 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
364 # Usage: puniq [<path>]
365 # Remove duplicate entries from a PATH style value while retaining
366 # the original order. Use PATH if no <path> is given.
369 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
370 # /usr/bin:/usr/local/bin
372 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
373 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
376 # -------------------------------------------------------------------
377 # USER SHELL ENVIRONMENT
378 # -------------------------------------------------------------------
380 # source ~/.shenv now if it exists
384 # condense PATH entries
386 MANPATH
=$(puniq $MANPATH)
388 # Use the color prompt by default when interactive
392 # -------------------------------------------------------------------
394 # -------------------------------------------------------------------
396 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
397 # Get current uname and uptime (if exists on this host)
398 # Strip any leading whitespace from uname and uptime commands
399 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
400 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
401 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
403 test -n "$t_uname" && echo $t_uname
404 test -n "$t_uptime" && echo $t_uptime
407 unset t_uname t_uptime
410 # vim: ts=4 sts=4 shiftwidth=4 expandtab