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
123 if [ "$UID" = 0 ]; then
125 PS_C1
="\[\033[1;31m\]" # red
126 PS_C2
="\[\033[0;37m\]" # grey
131 PS_C1
="\[\033[0;32m\]" # green
132 PS_C2
="\[\033[0;37m\]" # grey
135 PS_C1
="\[\033[1;97m\]" # white
136 PS_C2
="\[\033[0;37m\]" # grey
139 PS_C1
="\[\033[1;93m\]" # yellow
140 PS_C2
="\[\033[0;33m\]" # brown
153 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
158 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
162 # ----------------------------------------------------------------------
163 # MACOS X / DARWIN SPECIFIC
164 # ----------------------------------------------------------------------
166 if [ "$UNAME" = Darwin
]; then
167 # put ports on the paths if /opt/local exists
168 test -x /opt
/local -a ! -L /opt
/local && {
171 # setup the PATH and MANPATH
172 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
173 MANPATH
="$PORTS/share/man:$MANPATH"
175 # nice little port alias
176 alias port
="sudo nice -n +18 $PORTS/bin/port"
180 # ----------------------------------------------------------------------
181 # ALIASES / FUNCTIONS
182 # ----------------------------------------------------------------------
184 # alias 'vi' to 'vim' if Vim is installed
191 # disk usage with human sizes and minimal depth
192 alias du1
='du -h --max-depth=1'
193 alias fn
='find . -name'
194 alias hi
='history | tail -20'
196 # ----------------------------------------------------------------------
198 # ----------------------------------------------------------------------
200 test -z "$BASH_COMPLETION" && {
201 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
202 test -n "$PS1" && test $bmajor -gt 1 && {
203 # search for a bash_completion file to source
204 for f
in /usr
/local
/etc
/bash_completion \
205 /usr
/pkg
/etc
/bash_completion \
206 /opt
/local
/etc
/bash_completion \
215 unset bash bmajor bminor
218 # override and disable tilde expansion
224 # ----------------------------------------------------------------------
226 # ----------------------------------------------------------------------
228 # we always pass these to ls(1)
230 ## OS-specific options
232 # "Linux" ) LS_COMMON="--color=auto";;
233 # "Cygwin" ) LS_COMMON="--color=auto";;
234 # "Darwin" ) LS_COMMON="--color=auto";;
237 # if the dircolors utility is available, set that up for ls
238 dircolors
="$(type -P gdircolors dircolors | head -1)"
239 test -n "$dircolors" && {
240 COLORS
=/etc
/DIR_COLORS
241 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
242 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
243 test ! -e "$COLORS" && COLORS
=
244 eval `$dircolors --sh $COLORS`
248 # enable color ls output if available
250 LS_COMMON
="--color=auto $LS_COMMON"
252 # setup the main ls alias if we've established common args
253 test -n "$LS_COMMON" &&
254 alias ls="command ls $LS_COMMON"
256 # these use the ls aliases above
259 alias ll.
="ls -ld .*"
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_rsa.pub
|| ssh-keygen -t rsa
-b 4096
277 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.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