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)
11 # complete hostnames from this file
12 HOSTFILE
=~
/.ssh
/known_hosts
17 if [ "$UNAME" = "Darwin" ]; then
19 test -r /sw
/bin
/init.sh
&& source /sw
/bin
/init.sh
22 # ----------------------------------------------------------------------
24 # ----------------------------------------------------------------------
26 # bring in system bashrc
27 test -r /etc
/bashrc
&&
30 # notify of bg job completion immediately
33 # shell opts. see bash(1) for details
34 shopt -s cdspell
>/dev
/null
2>&1
35 shopt -s extglob
>/dev
/null
2>&1
36 shopt -s histappend
>/dev
/null
2>&1
37 shopt -s hostcomplete
>/dev
/null
2>&1
38 shopt -s interactive_comments
>/dev
/null
2>&1
39 shopt -u mailwarn
>/dev
/null
2>&1
40 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
42 # don't check for new mail
51 # ----------------------------------------------------------------------
53 # ----------------------------------------------------------------------
55 # we want the various sbins on the path along with /usr/local/bin
56 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
57 PATH
="/usr/local/bin:$PATH"
59 # put ~/bin on PATH if you have it
60 test -d "$HOME/bin" &&
61 PATH
="$HOME/bin:$PATH"
63 # ----------------------------------------------------------------------
64 # ENVIRONMENT CONFIGURATION
65 # ----------------------------------------------------------------------
67 # detect interactive shell
69 *i
*) INTERACTIVE
=yes ;;
70 *) unset INTERACTIVE
;;
79 # enable en_US locale w/ utf-8 encodings if not already
81 : ${LANG:="en_US.UTF-8"}
83 : ${LC_CTYPE:="en_US.UTF-8"}
84 : ${LC_ALL:="en_US.UTF-8"}
85 export LANG LANGUAGE LC_CTYPE LC_ALL
87 # ignore backups, CVS directories, python bytecode, vim swap files
88 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
89 HISTCONTROL
=ignoreboth
91 # ----------------------------------------------------------------------
93 # ----------------------------------------------------------------------
95 # See what we have to work with ...
96 HAVE_VIM
=$(command -v vim)
99 test -n "$HAVE_VIM" &&
105 if test -n "$(command -v less)" ; then
107 MANPAGER
="less -FiRswX"
112 export PAGER MANPAGER
114 # ----------------------------------------------------------------------
116 # ----------------------------------------------------------------------
119 GREEN
="\[\033[0;92m\]"
120 BROWN
="\[\033[0;33m\]"
121 GREY
="\[\033[0;37m\]"
122 WHITE
="\[\033[0;97m\]"
123 BLUE
="\[\033[0;94m\]"
124 PS_CLEAR
="\[\033[0m\]"
125 SCREEN_ESC
="\[\033k\033\134\]"
127 if [ "$LOGNAME" = "root" ]; then
147 PS1
="${COLOR1}${P}${PS_CLEAR} "
152 PS1
="[${COLOR1}\u${PS_CLEAR}@${COLOR2}\h${PS_CLEAR}:${COLOR3}\w${PS_CLEAR}]${COLOR1}${P}${PS_CLEAR} "
153 PS2
="\[^[[33;1m\]continue \[^[[0m^[[1m\]> "
156 # ----------------------------------------------------------------------
157 # MACOS X / DARWIN SPECIFIC
158 # ----------------------------------------------------------------------
160 if [ "$UNAME" = Darwin
]; then
161 # put ports on the paths if /opt/local exists
162 test -x /opt
/local -a ! -L /opt
/local && {
165 # setup the PATH and MANPATH
166 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
167 MANPATH
="$PORTS/share/man:$MANPATH"
169 # nice little port alias
170 alias port
="sudo nice -n +18 $PORTS/bin/port"
174 # ----------------------------------------------------------------------
175 # ALIASES / FUNCTIONS
176 # ----------------------------------------------------------------------
178 # alias 'vi' to 'vim' if Vim is installed
185 # disk usage with human sizes and minimal depth
186 alias du1
='du -h --max-depth=1'
187 alias fn
='find . -name'
188 alias hi
='history | tail -20'
190 # ----------------------------------------------------------------------
192 # ----------------------------------------------------------------------
194 test -z "$BASH_COMPLETION" && {
195 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
196 test -n "$PS1" && test $bmajor -gt 1 && {
197 # search for a bash_completion file to source
198 for f
in /usr
/local
/etc
/bash_completion \
199 /usr
/pkg
/etc
/bash_completion \
200 /opt
/local
/etc
/bash_completion \
209 unset bash bmajor bminor
212 # override and disable tilde expansion
218 # ----------------------------------------------------------------------
220 # ----------------------------------------------------------------------
222 # we always pass these to ls(1)
223 LS_COMMON
="--color=auto"
225 # if the dircolors utility is available, set that up to
226 dircolors
="$(type -P gdircolors dircolors | head -1)"
227 test -n "$dircolors" && {
228 COLORS
=/etc
/DIR_COLORS
229 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
230 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
231 test ! -e "$COLORS" && COLORS
=
232 eval `$dircolors --sh $COLORS`
236 # setup the main ls alias if we've established common args
237 test -n "$LS_COMMON" &&
238 alias ls="command ls $LS_COMMON"
240 # these use the ls aliases above
244 # --------------------------------------------------------------------
246 # --------------------------------------------------------------------
248 # push SSH public key to another box
251 test -f ~
/.ssh
/id_dsa.pub
|| ssh-keygen -t dsa
255 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_dsa.pub
259 # --------------------------------------------------------------------
260 # PATH MANIPULATION FUNCTIONS
261 # --------------------------------------------------------------------
264 # List path entries of PATH or environment variable <var>.
265 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
267 # Usage: pshift [-n <num>] [<var>]
268 # Shift <num> entries off the front of PATH or environment var <var>.
269 # with the <var> option. Useful: pshift $(pwd)
272 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
273 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
276 # Usage: ppop [-n <num>] [<var>]
277 # Pop <num> entries off the end of PATH or environment variable <var>.
280 [ "$1" = "-n" ] && { n
=$2; shift 2; }
282 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
287 # Usage: prm <path> [<var>]
288 # Remove <path> from PATH or environment variable <var>.
289 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
291 # Usage: punshift <path> [<var>]
292 # Shift <path> onto the beginning of PATH or environment variable <var>.
293 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
295 # Usage: puniq [<path>]
296 # Remove duplicate entries from a PATH style value while retaining
297 # the original order. Use PATH if no <path> is given.
300 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
301 # /usr/bin:/usr/local/bin
303 echo "$1" |tr : '\n' |nl |sort -u -k 2,2 |sort -n |
304 cut
-f 2- |tr '\n' : |sed -e 's/:$//' -e 's/^://'
307 # -------------------------------------------------------------------
308 # USER SHELL ENVIRONMENT
309 # -------------------------------------------------------------------
311 # source ~/.shenv now if it exists
315 # condense PATH entries
317 MANPATH
=$(puniq $MANPATH)
319 # Use the color prompt by default when interactive
323 # vim: ts=4 sts=4 shiftwidth=4 expandtab