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;96m\]" # cyan
140 PS_C2
="\[\033[0;36m\]" # cyan
143 PS_C1
="\[\033[1;93m\]" # yellow
144 PS_C2
="\[\033[0;33m\]" # brown
157 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
162 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_P}\[\033[0m\] "
166 # ----------------------------------------------------------------------
167 # MACOS X / DARWIN SPECIFIC
168 # ----------------------------------------------------------------------
170 if [ "$UNAME" = Darwin
]; then
171 # put ports on the paths if /opt/local exists
172 test -x /opt
/local -a ! -L /opt
/local && {
175 # setup the PATH and MANPATH
176 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
177 MANPATH
="$PORTS/share/man:$MANPATH"
179 # nice little port alias
180 alias port
="sudo nice -n +18 $PORTS/bin/port"
184 # ----------------------------------------------------------------------
185 # ALIASES / FUNCTIONS
186 # ----------------------------------------------------------------------
188 # alias 'vi' to 'vim' if Vim is installed
195 # disk usage with human sizes and minimal depth
196 alias du1
='du -h --max-depth=1'
197 alias fn
='find . -name'
198 alias hi
='history | tail -20'
200 # ----------------------------------------------------------------------
202 # ----------------------------------------------------------------------
204 test -z "$BASH_COMPLETION" && {
205 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
206 test -n "$PS1" && test $bmajor -gt 1 && {
207 # search for a bash_completion file to source
208 for f
in /usr
/local
/etc
/bash_completion \
209 /usr
/pkg
/etc
/bash_completion \
210 /opt
/local
/etc
/bash_completion \
219 unset bash bmajor bminor
222 # override and disable tilde expansion
228 # ----------------------------------------------------------------------
230 # ----------------------------------------------------------------------
232 # we always pass these to ls(1)
234 ## OS-specific options
236 # "Linux" ) LS_COMMON="--color=auto";;
237 # "Cygwin" ) LS_COMMON="--color=auto";;
238 # "Darwin" ) LS_COMMON="--color=auto";;
241 # if the dircolors utility is available, set that up for ls
242 dircolors
="$(type -P gdircolors dircolors | head -1)"
243 test -n "$dircolors" && {
244 COLORS
=/etc
/DIR_COLORS
245 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
246 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
247 test ! -e "$COLORS" && COLORS
=
248 eval `$dircolors --sh $COLORS`
252 # enable color ls output if available
254 LS_COMMON
="--color=auto $LS_COMMON"
256 # setup the main ls alias if we've established common args
257 test -n "$LS_COMMON" &&
258 alias ls="command ls $LS_COMMON"
260 # these use the ls aliases above
263 alias ll.
="ls -ld .*"
266 # setup color grep output if available
268 alias grep="command grep --color=auto"
270 # --------------------------------------------------------------------
272 # --------------------------------------------------------------------
274 # push SSH public key to another box
277 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
281 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
285 # --------------------------------------------------------------------
286 # PATH MANIPULATION FUNCTIONS
287 # --------------------------------------------------------------------
290 # List path entries of PATH or environment variable <var>.
291 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
293 # Usage: pshift [-n <num>] [<var>]
294 # Shift <num> entries off the front of PATH or environment var <var>.
295 # with the <var> option. Useful: pshift $(pwd)
298 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
299 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
302 # Usage: ppop [-n <num>] [<var>]
303 # Pop <num> entries off the end of PATH or environment variable <var>.
306 [ "$1" = "-n" ] && { n
=$2; shift 2; }
308 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
313 # Usage: prm <path> [<var>]
314 # Remove <path> from PATH or environment variable <var>.
315 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
317 # Usage: punshift <path> [<var>]
318 # Shift <path> onto the beginning of PATH or environment variable <var>.
319 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
321 # Usage: puniq [<path>]
322 # Remove duplicate entries from a PATH style value while retaining
323 # the original order. Use PATH if no <path> is given.
326 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
327 # /usr/bin:/usr/local/bin
329 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
330 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
333 # -------------------------------------------------------------------
334 # USER SHELL ENVIRONMENT
335 # -------------------------------------------------------------------
337 # source ~/.shenv now if it exists
341 # condense PATH entries
343 MANPATH
=$(puniq $MANPATH)
345 # Use the color prompt by default when interactive
349 # vim: ts=4 sts=4 shiftwidth=4 expandtab