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-*"
99 HISTCONTROL
=ignoreboth
101 # ----------------------------------------------------------------------
103 # ----------------------------------------------------------------------
105 # See what we have to work with ...
106 HAVE_VIM
=$(command -v vim)
109 test -n "$HAVE_VIM" &&
115 if test -n "$(command -v less)" ; then
117 MANPAGER
="less -FiRswX"
122 export PAGER MANPAGER
124 # ----------------------------------------------------------------------
126 # ----------------------------------------------------------------------
128 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
130 if [ "$UID" = 0 ]; then
132 PS_C1
="\[\033[1;31m\]" # red
133 PS_C2
="\[\033[0;37m\]" # grey
138 PS_C1
="\[\033[0;32m\]" # green
139 PS_C2
="\[\033[0;37m\]" # grey
142 PS_C1
="\[\033[1;97m\]" # white
143 PS_C2
="\[\033[0;37m\]" # grey
146 PS_C1
="\[\033[1;96m\]" # cyan
147 PS_C2
="\[\033[0;36m\]" # cyan
150 PS_C1
="\[\033[1;93m\]" # yellow
151 PS_C2
="\[\033[0;33m\]" # brown
164 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
169 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
173 # ----------------------------------------------------------------------
174 # MACOS X / DARWIN SPECIFIC
175 # ----------------------------------------------------------------------
177 if [ "$UNAME" = Darwin
]; then
178 # put ports on the paths if /opt/local exists
179 test -x /opt
/local -a ! -L /opt
/local && {
182 # setup the PATH and MANPATH
183 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
184 MANPATH
="$PORTS/share/man:$MANPATH"
186 # nice little port alias
187 alias port
="sudo nice -n +18 $PORTS/bin/port"
191 # ----------------------------------------------------------------------
192 # ALIASES / FUNCTIONS
193 # ----------------------------------------------------------------------
195 # alias 'vi' to 'vim' if Vim is installed
202 # disk usage with human sizes and minimal depth
203 alias du1
='du -h --max-depth=1'
204 alias fn
='find . -name'
205 alias hi
='history | tail -20'
207 # For Solaris, use GNU versions of grep and sed
208 if [ "$UNAME" = SunOS
]; then
209 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
210 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
213 # ----------------------------------------------------------------------
215 # ----------------------------------------------------------------------
217 test -z "$BASH_COMPLETION" && {
218 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
219 test -n "$PS1" && test $bmajor -gt 1 && {
220 # search for a bash_completion file to source
221 for f
in /usr
/local
/etc
/bash_completion \
222 /usr
/pkg
/etc
/bash_completion \
223 /opt
/local
/etc
/bash_completion \
232 unset bash bmajor bminor
235 # override and disable tilde expansion
241 # ----------------------------------------------------------------------
243 # ----------------------------------------------------------------------
245 # we always pass these to ls(1)
247 ## OS-specific options
249 # "Linux" ) LS_COMMON="--color=auto";;
250 # "Cygwin" ) LS_COMMON="--color=auto";;
251 # "Darwin" ) LS_COMMON="--color=auto";;
254 # if the dircolors utility is available, set that up for ls
255 dircolors
="$(type -P gdircolors dircolors | head -1)"
256 test -n "$dircolors" && {
257 COLORS
=/etc
/DIR_COLORS
258 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
259 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
260 test ! -e "$COLORS" && COLORS
=
261 eval `$dircolors --sh $COLORS`
265 # enable color ls output if available
267 LS_COMMON
="--color=auto $LS_COMMON"
269 # setup the main ls alias if we've established common args
270 test -n "$LS_COMMON" &&
271 alias ls="command ls $LS_COMMON"
273 # these use the ls aliases above
276 alias ll.
="ls -ld .*"
279 # setup color grep output if available
280 if [ -n "$COLORS" ]; then
283 # For Solaris, use the GNU version of grep for color support
284 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=auto"
287 alias grep="command grep --color=auto"
292 # --------------------------------------------------------------------
294 # --------------------------------------------------------------------
296 # push SSH public key to another box
299 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
303 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
307 # --------------------------------------------------------------------
308 # PATH MANIPULATION FUNCTIONS
309 # --------------------------------------------------------------------
312 # List path entries of PATH or environment variable <var>.
313 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
315 # Usage: pshift [-n <num>] [<var>]
316 # Shift <num> entries off the front of PATH or environment var <var>.
317 # with the <var> option. Useful: pshift $(pwd)
320 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
321 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
324 # Usage: ppop [-n <num>] [<var>]
325 # Pop <num> entries off the end of PATH or environment variable <var>.
328 [ "$1" = "-n" ] && { n
=$2; shift 2; }
330 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
335 # Usage: prm <path> [<var>]
336 # Remove <path> from PATH or environment variable <var>.
337 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
339 # Usage: punshift <path> [<var>]
340 # Shift <path> onto the beginning of PATH or environment variable <var>.
341 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
343 # Usage: puniq [<path>]
344 # Remove duplicate entries from a PATH style value while retaining
345 # the original order. Use PATH if no <path> is given.
348 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
349 # /usr/bin:/usr/local/bin
351 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
352 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
355 # -------------------------------------------------------------------
356 # USER SHELL ENVIRONMENT
357 # -------------------------------------------------------------------
359 # source ~/.shenv now if it exists
363 # condense PATH entries
365 MANPATH
=$(puniq $MANPATH)
367 # Use the color prompt by default when interactive
371 # vim: ts=4 sts=4 shiftwidth=4 expandtab