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)
6 # short-circuit for non-interactive sessions
7 [ -z "$PS1" ] && return
11 : ${LOGNAME=$(id -un)}
13 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
14 UNAME
=${UNAME/CYGWIN_*/Cygwin}
16 # complete hostnames from this file
17 HOSTFILE
=~
/.ssh
/known_hosts
22 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
23 case $(tput colors 2>&1) in
25 export TERM
=xterm
-color
26 case $(tput colors 2>&1) in
34 if [ "$UNAME" = "Darwin" ]; then
36 test -r /sw
/bin
/init.sh
&&
37 source /sw
/bin
/init.sh
40 # ----------------------------------------------------------------------
42 # ----------------------------------------------------------------------
44 # bring in system bashrc
45 test -r /etc
/bashrc
&&
48 # notify of bg job completion immediately
51 # shell opts. see bash(1) for details
52 shopt -s cdspell
>/dev
/null
2>&1
53 shopt -s extglob
>/dev
/null
2>&1
54 shopt -s histappend
>/dev
/null
2>&1
55 shopt -s hostcomplete
>/dev
/null
2>&1
56 shopt -s interactive_comments
>/dev
/null
2>&1
57 shopt -u mailwarn
>/dev
/null
2>&1
58 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
60 # don't check for new mail
69 # ----------------------------------------------------------------------
71 # ----------------------------------------------------------------------
73 # we want the various sbin's on the path along with /usr/local/bin
74 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
75 PATH
="/usr/local/bin:$PATH"
77 # put /opt/csw/* on PATH if exists (OpenCSW Solaris packages)
79 PATH
="/opt/csw/sbin:/opt/csw/bin:$PATH"
81 # put ~/bin on PATH if exists
82 test -d "$HOME/bin" &&
83 PATH
="$HOME/bin:$PATH"
85 # put ~/sbin on PATH if exists
86 test -d "$HOME/sbin" &&
87 PATH
="$HOME/sbin:$PATH"
89 # ----------------------------------------------------------------------
90 # ENVIRONMENT CONFIGURATION
91 # ----------------------------------------------------------------------
93 # detect interactive shell
95 *i
*) INTERACTIVE
=yes ;;
96 *) unset INTERACTIVE
;;
105 # enable en_US locale w/ utf-8 encodings if not already
107 : ${LANG:="en_US.UTF-8"}
109 : ${LC_CTYPE:="en_US.UTF-8"}
110 : ${LC_ALL:="en_US.UTF-8"}
111 export LANG LANGUAGE LC_CTYPE LC_ALL
113 # ignore backups, CVS directories, python bytecode, vim swap files
114 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
117 HISTCONTROL
=ignoreboth
121 # ----------------------------------------------------------------------
123 # ----------------------------------------------------------------------
125 # See what we have to work with ...
126 HAVE_VIM
=$(command -v vim)
129 test -n "$HAVE_VIM" &&
135 if test -n "$(command -v less)" ; then
144 export PAGER MANPAGER
148 ACK_PAGER_COLOR
="$PAGER"
150 # ----------------------------------------------------------------------
152 # ----------------------------------------------------------------------
154 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
156 if [ "$UID" = 0 ]; then
158 PS_C1
="\[\033[1;31m\]" # red
159 PS_C2
="\[\033[0;37m\]" # grey
164 PS_C1
="\[\033[0;32m\]" # green
165 PS_C2
="\[\033[0;37m\]" # grey
168 PS_C1
="\[\033[1;97m\]" # white
169 PS_C2
="\[\033[0;37m\]" # grey
172 PS_C1
="\[\033[1;96m\]" # cyan
173 PS_C2
="\[\033[0;36m\]" # cyan
176 PS_C1
="\[\033[1;93m\]" # yellow
177 PS_C2
="\[\033[0;33m\]" # brown
190 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
195 # If git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
196 # Never show branch info for $HOME (dotfiles) repo.
197 # Use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
198 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
199 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
200 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
201 test "$(git config --bool bash.hidePrompt)" != "true" &&
202 __git_ps1 "{\[\033[0;100m\]%s\[\033[0;90m\]}")'
203 export GIT_PS1_SHOWDIRTYSTATE
=1
205 PS1
="\[\033[0;90m\][${PS_C1}\u@\h\[\033[0m\]\[\033[0;90m\]:${PS_C2}\w\[\033[0;90m\]]${PS_GIT}${PS_P}\[\033[0m\] "
209 # ----------------------------------------------------------------------
210 # MACOS X / DARWIN SPECIFIC
211 # ----------------------------------------------------------------------
213 if [ "$UNAME" = Darwin
]; then
214 # put ports on the paths if /opt/local exists
215 test -x /opt
/local -a ! -L /opt
/local && {
218 # setup the PATH and MANPATH
219 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
220 MANPATH
="$PORTS/share/man:$MANPATH"
222 # nice little port alias
223 alias port
="sudo nice -n +18 $PORTS/bin/port"
227 # ----------------------------------------------------------------------
228 # ALIASES / FUNCTIONS
229 # ----------------------------------------------------------------------
231 # alias 'vi' to 'vim' if Vim is installed
238 # disk usage with human sizes and minimal depth
239 alias du1
='du -h --max-depth=1'
240 alias fn
='find . -name'
241 alias hi
='history | tail -20'
243 # For Solaris, use GNU versions of grep and sed
244 if [ "$UNAME" = SunOS
]; then
245 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
246 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
249 # Alias csh-style "rebash" to bash equivalent
250 alias rehash
="hash -r"
252 # ----------------------------------------------------------------------
254 # ----------------------------------------------------------------------
256 test -z "$BASH_COMPLETION" && {
257 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
258 test -n "$PS1" && test $bmajor -gt 1 && {
259 # search for a bash_completion file to source
260 for f
in /usr
/local
/etc
/bash_completion \
261 /usr
/pkg
/etc
/bash_completion \
262 /opt
/local
/etc
/bash_completion \
271 unset bash bmajor bminor
274 # override and disable tilde expansion
279 # ----------------------------------------------------------------------
281 # ----------------------------------------------------------------------
283 # we always pass these to ls(1)
285 ## OS-specific options
287 # "Linux" ) LS_COMMON="--color=auto";;
288 # "Cygwin" ) LS_COMMON="--color=auto";;
289 # "Darwin" ) LS_COMMON="--color=auto";;
292 # if the dircolors utility is available, set that up for ls
293 dircolors
="$(type -P gdircolors dircolors | head -1)"
294 test -n "$dircolors" && {
295 COLORS
=/etc
/DIR_COLORS
296 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
297 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
298 test ! -e "$COLORS" && COLORS
=
299 eval `$dircolors --sh $COLORS`
303 # enable color ls output if available
305 LS_COMMON
="--color=auto $LS_COMMON"
307 # setup the main ls alias if we've established common args
308 test -n "$LS_COMMON" &&
309 alias ls="command ls $LS_COMMON"
311 # these use the ls aliases above
314 alias ll.
="ls -ld .*"
317 # setup color grep output if available
318 if [ -n "$COLORS" ]; then
321 # For Solaris, use the GNU version of grep for color support
322 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
325 alias grep="command grep --color=always"
328 # older versions of grep only support a singular highlight color
329 export GREP_COLOR
='1;37;42'
330 # newer versions of grep have more flexible color configuration
331 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
334 # --------------------------------------------------------------------
336 # --------------------------------------------------------------------
338 # push SSH public key to another box
341 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
345 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
349 # --------------------------------------------------------------------
350 # PATH MANIPULATION FUNCTIONS
351 # --------------------------------------------------------------------
354 # List path entries of PATH or environment variable <var>.
355 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
357 # Usage: pshift [-n <num>] [<var>]
358 # Shift <num> entries off the front of PATH or environment var <var>.
359 # with the <var> option. Useful: pshift $(pwd)
362 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
363 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
366 # Usage: ppop [-n <num>] [<var>]
367 # Pop <num> entries off the end of PATH or environment variable <var>.
370 [ "$1" = "-n" ] && { n
=$2; shift 2; }
372 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
377 # Usage: prm <path> [<var>]
378 # Remove <path> from PATH or environment variable <var>.
379 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
381 # Usage: punshift <path> [<var>]
382 # Shift <path> onto the beginning of PATH or environment variable <var>.
383 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
385 # Usage: ppush <path> [<var>]
386 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
388 # Usage: puniq [<path>]
389 # Remove duplicate entries from a PATH style value while retaining
390 # the original order. Use PATH if no <path> is given.
393 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
394 # /usr/bin:/usr/local/bin
396 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
397 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
400 # -------------------------------------------------------------------
401 # USER SHELL ENVIRONMENT
402 # -------------------------------------------------------------------
404 # source ~/.shenv now if it exists
408 # condense PATH entries
409 PATH
=$(puniq "$PATH")
410 MANPATH
=$(puniq "$MANPATH")
412 # Use the color prompt by default when interactive
416 # -------------------------------------------------------------------
418 # -------------------------------------------------------------------
420 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
421 # Get current uname and uptime (if exists on this host)
422 # Strip any leading whitespace from uname and uptime commands
423 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
424 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
425 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
427 test -n "$t_uname" && echo $t_uname
428 test -n "$t_uptime" && echo $t_uptime
431 unset t_uname t_uptime
434 # vim: ts=4 sts=4 shiftwidth=4 expandtab