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}
15 : ${INPUTRC=~/.inputrc}
17 # ----------------------------------------------------------------------
19 # ----------------------------------------------------------------------
21 # bring in system bashrc
22 test -r /etc
/bashrc
&&
25 # notify of bg job completion immediately
28 # shell opts. see bash(1) for details
29 shopt -s cdspell
>/dev
/null
2>&1
30 shopt -s extglob
>/dev
/null
2>&1
31 shopt -s histappend
>/dev
/null
2>&1
32 shopt -s hostcomplete
>/dev
/null
2>&1
33 shopt -s interactive_comments
>/dev
/null
2>&1
34 shopt -u mailwarn
>/dev
/null
2>&1
35 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
37 # don't check for new mail
46 # ----------------------------------------------------------------------
48 # ----------------------------------------------------------------------
50 # we want the various sbins on the path along with /usr/local/bin
51 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
52 PATH
="/usr/local/bin:$PATH"
54 # put ~/bin on PATH if you have it
55 test -d "$HOME/bin" &&
56 PATH
="$HOME/bin:$PATH"
58 # ----------------------------------------------------------------------
59 # ENVIRONMENT CONFIGURATION
60 # ----------------------------------------------------------------------
62 # detect interactive shell
64 *i
*) INTERACTIVE
=yes ;;
65 *) unset INTERACTIVE
;;
74 # enable en_US locale w/ utf-8 encodings if not already
76 : ${LANG:="en_US.UTF-8"}
78 : ${LC_CTYPE:="en_US.UTF-8"}
79 : ${LC_ALL:="en_US.UTF-8"}
80 export LANG LANGUAGE LC_CTYPE LC_ALL
82 # ignore backups, CVS directories, python bytecode, vim swap files
83 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
84 HISTCONTROL
=ignoreboth
86 # ----------------------------------------------------------------------
88 # ----------------------------------------------------------------------
90 # See what we have to work with ...
91 HAVE_VIM
=$(command -v vim)
94 test -n "$HAVE_VIM" &&
100 if test -n "$(command -v less)" ; then
102 MANPAGER
="less -FiRswX"
107 export PAGER MANPAGER
109 # ----------------------------------------------------------------------
111 # ----------------------------------------------------------------------
114 GREEN
="\[\033[0;92m\]"
115 BROWN
="\[\033[0;33m\]"
116 GREY
="\[\033[0;37m\]"
117 WHITE
="\[\033[0;97m\]"
118 BLUE
="\[\033[0;94m\]"
119 PS_CLEAR
="\[\033[0m\]"
120 SCREEN_ESC
="\[\033k\033\134\]"
122 if [ "$LOGNAME" = "root" ]; then
142 PS1
="${COLOR1}${P}${PS_CLEAR} "
147 PS1
="[${COLOR1}\u${PS_CLEAR}@${COLOR2}\h${PS_CLEAR}:${COLOR3}\w${PS_CLEAR}]${COLOR1}$P${PS_CLEAR} "
148 PS2
="\[^[[33;1m\]continue \[^[[0m^[[1m\]> "
151 # ----------------------------------------------------------------------
152 # MACOS X / DARWIN SPECIFIC
153 # ----------------------------------------------------------------------
155 if [ "$UNAME" = Darwin
]; then
156 # put ports on the paths if /opt/local exists
157 test -x /opt
/local -a ! -L /opt
/local && {
160 # setup the PATH and MANPATH
161 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
162 MANPATH
="$PORTS/share/man:$MANPATH"
164 # nice little port alias
165 alias port
="sudo nice -n +18 $PORTS/bin/port"
169 # ----------------------------------------------------------------------
170 # ALIASES / FUNCTIONS
171 # ----------------------------------------------------------------------
173 # disk usage with human sizes and minimal depth
174 alias du1
='du -h --max-depth=1'
175 alias fn
='find . -name'
176 alias hi
='history | tail -20'
178 # ----------------------------------------------------------------------
180 # ----------------------------------------------------------------------
182 test -z "$BASH_COMPLETION" && {
183 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
184 test -n "$PS1" && test $bmajor -gt 1 && {
185 # search for a bash_completion file to source
186 for f
in /usr
/local
/etc
/bash_completion \
187 /usr
/pkg
/etc
/bash_completion \
188 /opt
/local
/etc
/bash_completion \
197 unset bash bmajor bminor
200 # override and disable tilde expansion
206 # ----------------------------------------------------------------------
208 # ----------------------------------------------------------------------
210 # we always pass these to ls(1)
211 LS_COMMON
="--color=auto"
213 # if the dircolors utility is available, set that up to
214 dircolors
="$(type -P gdircolors dircolors | head -1)"
215 test -n "$dircolors" && {
216 COLORS
=/etc
/DIR_COLORS
217 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
218 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
219 test ! -e "$COLORS" && COLORS
=
220 eval `$dircolors --sh $COLORS`
224 # setup the main ls alias if we've established common args
225 test -n "$LS_COMMON" &&
226 alias ls="command ls $LS_COMMON"
228 # these use the ls aliases above
232 # --------------------------------------------------------------------
234 # --------------------------------------------------------------------
236 # push SSH public key to another box
239 test -f ~
/.ssh
/id_dsa.pub
|| ssh-keygen -t dsa
243 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_dsa.pub
247 # --------------------------------------------------------------------
248 # PATH MANIPULATION FUNCTIONS
249 # --------------------------------------------------------------------
252 # List path entries of PATH or environment variable <var>.
253 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
255 # Usage: pshift [-n <num>] [<var>]
256 # Shift <num> entries off the front of PATH or environment var <var>.
257 # with the <var> option. Useful: pshift $(pwd)
260 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
261 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
264 # Usage: ppop [-n <num>] [<var>]
265 # Pop <num> entries off the end of PATH or environment variable <var>.
268 [ "$1" = "-n" ] && { n
=$2; shift 2; }
270 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
275 # Usage: prm <path> [<var>]
276 # Remove <path> from PATH or environment variable <var>.
277 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
279 # Usage: punshift <path> [<var>]
280 # Shift <path> onto the beginning of PATH or environment variable <var>.
281 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
283 # Usage: puniq [<path>]
284 # Remove duplicate entries from a PATH style value while retaining
285 # the original order. Use PATH if no <path> is given.
288 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
289 # /usr/bin:/usr/local/bin
291 echo "$1" |tr : '\n' |nl |sort -u -k 2,2 |sort -n |
292 cut
-f 2- |tr '\n' : |sed -e 's/:$//' -e 's/^://'
295 # -------------------------------------------------------------------
296 # USER SHELL ENVIRONMENT
297 # -------------------------------------------------------------------
299 # source ~/.shenv now if it exists
303 # condense PATH entries
305 MANPATH
=$(puniq $MANPATH)
307 # Use the color prompt by default when interactive
311 # vim: ts=4 sts=4 shiftwidth=4 expandtab