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 [ "$UNAME" = "Darwin" ]; then
21 test -r /sw
/bin
/init.sh
&&
22 source /sw
/bin
/init.sh
25 # ----------------------------------------------------------------------
27 # ----------------------------------------------------------------------
29 # bring in system bashrc
30 test -r /etc
/bashrc
&&
33 # notify of bg job completion immediately
36 # shell opts. see bash(1) for details
37 shopt -s cdspell
>/dev
/null
2>&1
38 shopt -s extglob
>/dev
/null
2>&1
39 shopt -s histappend
>/dev
/null
2>&1
40 shopt -s hostcomplete
>/dev
/null
2>&1
41 shopt -s interactive_comments
>/dev
/null
2>&1
42 shopt -u mailwarn
>/dev
/null
2>&1
43 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
45 # don't check for new mail
54 # ----------------------------------------------------------------------
56 # ----------------------------------------------------------------------
58 # we want the various sbins on the path along with /usr/local/bin
59 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
60 PATH
="/usr/local/bin:$PATH"
62 # put ~/bin on PATH if you have it
63 test -d "$HOME/bin" &&
64 PATH
="$HOME/bin:$PATH"
66 # ----------------------------------------------------------------------
67 # ENVIRONMENT CONFIGURATION
68 # ----------------------------------------------------------------------
70 # detect interactive shell
72 *i
*) INTERACTIVE
=yes ;;
73 *) unset INTERACTIVE
;;
82 # enable en_US locale w/ utf-8 encodings if not already
84 : ${LANG:="en_US.UTF-8"}
86 : ${LC_CTYPE:="en_US.UTF-8"}
87 : ${LC_ALL:="en_US.UTF-8"}
88 export LANG LANGUAGE LC_CTYPE LC_ALL
90 # ignore backups, CVS directories, python bytecode, vim swap files
91 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
92 HISTCONTROL
=ignoreboth
94 # ----------------------------------------------------------------------
96 # ----------------------------------------------------------------------
98 # See what we have to work with ...
99 HAVE_VIM
=$(command -v vim)
102 test -n "$HAVE_VIM" &&
108 if test -n "$(command -v less)" ; then
110 MANPAGER
="less -FiRswX"
115 export PAGER MANPAGER
117 # ----------------------------------------------------------------------
119 # ----------------------------------------------------------------------
121 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
122 SGR_RED
="\[\033[1;31m\]"
123 SGR_GREEN
="\[\033[0;32m\]"
124 SGR_BROWN
="\[\033[0;33m\]"
125 SGR_YELLOW
="\[\033[1;33m\]"
126 SGR_GREY
="\[\033[0;37m\]"
127 SGR_WHITE
="\[\033[1;37m\]"
128 SGR_BLUE
="\[\033[1;34m\]"
129 SGR_RESET
="\[\033[0m\]"
131 if [ "$UID" = 0 ]; then
133 PS_COLOR1
="${SGR_RED}"
137 if [ "$UNAME" = "Cygwin" ]; then
138 PS_COLOR1
="${SGR_GREEN}"
141 PS_COLOR1
="${SGR_BROWN}"
142 PS_COLOR2
="${SGR_YELLOW}"
155 PS1
="${PS_COLOR1}${PS_P}${SGR_RESET} "
160 PS1
="[${PS_COLOR1}\u@\h${SGR_RESET}:${PS_COLOR2}\w${SGR_RESET}]${PS_P} "
164 # ----------------------------------------------------------------------
165 # MACOS X / DARWIN SPECIFIC
166 # ----------------------------------------------------------------------
168 if [ "$UNAME" = Darwin
]; then
169 # put ports on the paths if /opt/local exists
170 test -x /opt
/local -a ! -L /opt
/local && {
173 # setup the PATH and MANPATH
174 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
175 MANPATH
="$PORTS/share/man:$MANPATH"
177 # nice little port alias
178 alias port
="sudo nice -n +18 $PORTS/bin/port"
182 # ----------------------------------------------------------------------
183 # ALIASES / FUNCTIONS
184 # ----------------------------------------------------------------------
186 # alias 'vi' to 'vim' if Vim is installed
193 # disk usage with human sizes and minimal depth
194 alias du1
='du -h --max-depth=1'
195 alias fn
='find . -name'
196 alias hi
='history | tail -20'
198 # ----------------------------------------------------------------------
200 # ----------------------------------------------------------------------
202 test -z "$BASH_COMPLETION" && {
203 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
204 test -n "$PS1" && test $bmajor -gt 1 && {
205 # search for a bash_completion file to source
206 for f
in /usr
/local
/etc
/bash_completion \
207 /usr
/pkg
/etc
/bash_completion \
208 /opt
/local
/etc
/bash_completion \
217 unset bash bmajor bminor
220 # override and disable tilde expansion
226 # ----------------------------------------------------------------------
228 # ----------------------------------------------------------------------
230 # we always pass these to ls(1)
232 ## OS-specific options
234 # "Linux" ) LS_COMMON="--color=auto";;
235 # "Cygwin" ) LS_COMMON="--color=auto";;
236 # "Darwin" ) LS_COMMON="--color=auto";;
239 # if the dircolors utility is available, set that up for ls
240 dircolors
="$(type -P gdircolors dircolors | head -1)"
241 test -n "$dircolors" && {
242 COLORS
=/etc
/DIR_COLORS
243 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
244 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
245 test ! -e "$COLORS" && COLORS
=
246 eval `$dircolors --sh $COLORS`
250 # enable color ls output if available
252 LS_COMMON
="--color=auto $LS_COMMON"
254 # setup the main ls alias if we've established common args
255 test -n "$LS_COMMON" &&
256 alias ls="command ls $LS_COMMON"
258 # these use the ls aliases above
262 # setup color grep output if available
264 alias grep="command grep --color=auto"
266 # --------------------------------------------------------------------
268 # --------------------------------------------------------------------
270 # push SSH public key to another box
273 test -f ~
/.ssh
/id_dsa.pub
|| ssh-keygen -t dsa
277 ssh $_host 'cat >> ~/.ssh/authorized_keys2' < ~
/.ssh
/id_dsa.pub
281 # --------------------------------------------------------------------
282 # PATH MANIPULATION FUNCTIONS
283 # --------------------------------------------------------------------
286 # List path entries of PATH or environment variable <var>.
287 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
289 # Usage: pshift [-n <num>] [<var>]
290 # Shift <num> entries off the front of PATH or environment var <var>.
291 # with the <var> option. Useful: pshift $(pwd)
294 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
295 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
298 # Usage: ppop [-n <num>] [<var>]
299 # Pop <num> entries off the end of PATH or environment variable <var>.
302 [ "$1" = "-n" ] && { n
=$2; shift 2; }
304 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
309 # Usage: prm <path> [<var>]
310 # Remove <path> from PATH or environment variable <var>.
311 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
313 # Usage: punshift <path> [<var>]
314 # Shift <path> onto the beginning of PATH or environment variable <var>.
315 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
317 # Usage: puniq [<path>]
318 # Remove duplicate entries from a PATH style value while retaining
319 # the original order. Use PATH if no <path> is given.
322 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
323 # /usr/bin:/usr/local/bin
325 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
326 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
329 # -------------------------------------------------------------------
330 # USER SHELL ENVIRONMENT
331 # -------------------------------------------------------------------
333 # source ~/.shenv now if it exists
337 # condense PATH entries
339 MANPATH
=$(puniq $MANPATH)
341 # Use the color prompt by default when interactive
345 # vim: ts=4 sts=4 shiftwidth=4 expandtab