2 # ~/.bashrc: executed by bash(1) for non-login shells.
3 # A basically sane bash environment.
5 # ----------------------------------------------------------------------
7 # ----------------------------------------------------------------------
9 # short-circuit for non-interactive sessions
10 [ -z "$PS1" ] && return
14 : ${LOGNAME=$(id -un)}
16 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
17 UNAME
=${UNAME/CYGWIN_*/Cygwin}
19 # complete hostnames from this file
20 HOSTFILE
=~
/.ssh
/known_hosts
25 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
26 case $(tput colors 2>&1) in
28 export TERM
=xterm
-color
29 case $(tput colors 2>&1) in
37 # ----------------------------------------------------------------------
39 # ----------------------------------------------------------------------
41 # notify of bg job completion immediately
44 # shell opts. see bash(1) for details
45 shopt -s cdspell
>/dev
/null
2>&1
46 shopt -s checkjobs
>/dev
/null
2>&1
47 shopt -s checkwinsize
>/dev
/null
2>&1
48 shopt -s extglob
>/dev
/null
2>&1
49 shopt -s histappend
>/dev
/null
2>&1
50 shopt -s hostcomplete
>/dev
/null
2>&1
51 shopt -s interactive_comments
>/dev
/null
2>&1
52 shopt -u mailwarn
>/dev
/null
2>&1
53 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
55 # don't check for new mail
64 # ----------------------------------------------------------------------
66 # ----------------------------------------------------------------------
68 # include the various sbin's along with /usr/local/bin
69 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
70 PATH
="/usr/local/bin:$PATH"
72 # use $HOME specific bin and sbin
73 test -d "$HOME/bin" && PATH
="$HOME/bin:$PATH"
74 test -d "$HOME/sbin" && PATH
="$HOME/sbin:$PATH"
77 test -d "/opt/local" && PATH
="/opt/local/sbin:/opt/local/bin:$PATH"
79 test -d "/opt/custom" && PATH
="/opt/custom/sbin:/opt/custom/bin:$PATH"
81 test -d "/smartdc" && PATH
="/smartdc/bin:/opt/smartdc/bin:/opt/smartdc/agents/bin:$PATH"
82 # SmartOS native binaries, for OS/LX zones
83 test -d "/native" && PATH
="$PATH:/native/usr/sbin:/native/usr/bin:/native/sbin:/native/bin"
86 test -d "$HOME/.rvm/bin" && PATH
="$PATH:$HOME/.rvm/bin"
89 test -d "/usr/local/share/golang" && export GOPATH
=/usr
/local
/share
/golang
90 test -n "$GOPATH" && PATH
="$PATH:$GOPATH/bin"
92 # ----------------------------------------------------------------------
93 # ENVIRONMENT CONFIGURATION
94 # ----------------------------------------------------------------------
96 # detect interactive shell
98 *i
*) INTERACTIVE
=yes ;;
99 *) unset INTERACTIVE
;;
108 # enable en_US locale w/ utf-8 encodings if not already
110 : ${LANG:="en_US.UTF-8"}
112 : ${LC_CTYPE:="en_US.UTF-8"}
113 : ${LC_ALL:="en_US.UTF-8"}
114 export LANG LANGUAGE LC_CTYPE LC_ALL
116 # ignore backups, CVS directories, python bytecode, vim swap files
117 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
120 HISTCONTROL
=ignoreboth
124 # ----------------------------------------------------------------------
126 # ----------------------------------------------------------------------
128 # see what we have to work with ...
129 HAVE_VIM
=$(command -v vim)
132 test -n "$HAVE_VIM" &&
138 if test -n "$(command -v less)" ; then
147 export PAGER MANPAGER
149 # ----------------------------------------------------------------------
151 # ----------------------------------------------------------------------
153 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
155 if [ "$UID" = 0 ]; then
157 PS_C1
="\[\033[1;31m\]" # red
158 PS_C2
="\[\033[0;37m\]" # grey
163 PS_C1
="\[\033[0;32m\]" # green
164 PS_C2
="\[\033[0;37m\]" # grey
167 PS_C1
="\[\033[1;97m\]" # white
168 PS_C2
="\[\033[0;37m\]" # grey
171 PS_C1
="\[\033[1;96m\]" # cyan
172 PS_C2
="\[\033[0;36m\]" # cyan
175 PS_C1
="\[\033[1;93m\]" # yellow
176 PS_C2
="\[\033[0;33m\]" # brown
189 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
194 # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
195 # never show branch info for $HOME (dotfiles) repo.
196 # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
197 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
198 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
199 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
200 test "$(git config --bool bash.hidePrompt)" != "true" &&
201 __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")'
202 export GIT_PS1_SHOWDIRTYSTATE
=1
204 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\] "
208 # ----------------------------------------------------------------------
209 # MACOS X / DARWIN SPECIFIC
210 # ----------------------------------------------------------------------
212 if [ "$UNAME" = Darwin
]; then
213 # put ports on the paths if /opt/local exists
214 test -x /opt
/local -a ! -L /opt
/local && {
217 # setup the PATH and MANPATH
218 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
219 MANPATH
="$PORTS/share/man:$MANPATH"
221 # nice little port alias
222 alias port
="sudo nice -n +18 $PORTS/bin/port"
224 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
225 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
226 # setup the PATH and MANPATH
227 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
228 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
232 # ----------------------------------------------------------------------
234 # ----------------------------------------------------------------------
236 if [ "$UNAME" = SunOS
]; then
237 # use GNU versions of core utils
238 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
239 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
240 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
243 MANPATH
="/usr/share/man:/smartdc/man:/opt/smartdc/man:/opt/local/man:/opt/custom/man:$MANPATH"
246 # ----------------------------------------------------------------------
247 # ALIASES / FUNCTIONS
248 # ----------------------------------------------------------------------
253 alias ll.
="ls -ld .*"
256 # use 'git diff --no-index' as a prettier 'diff' alternative (if available)
257 test -n "$(type -P git)" && alias diff="git diff --no-index"
259 # alias 'vi' to 'vim' if Vim is installed
266 # disk usage with human sizes and minimal depth
267 alias du1
='du -h --max-depth=1'
268 alias fn
='find . -name'
269 alias hi
='history | tail -20'
271 # alias csh-style "rebash" to bash equivalent
272 alias rehash
="hash -r"
274 # set 'screen' window title
276 printf "\033k%s\033\\" "$@"
278 # set 'xterm' window title
280 printf "\033]0;%s\007" "$@"
284 alias svn
=svn
-wrapper
286 # ----------------------------------------------------------------------
288 # ----------------------------------------------------------------------
290 test -z "$BASH_COMPLETION" && {
291 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
292 test -n "$PS1" && test $bmajor -gt 1 && {
293 # search for a bash_completion file to source
294 for f
in /usr
/local
/etc
/bash_completion \
295 /usr
/pkg
/etc
/bash_completion \
296 /opt
/local
/etc
/bash_completion \
297 /etc
/bash_completion \
298 /etc
/bash
/bash_completion
306 unset bash bmajor bminor
309 # restore some key environment variables which may have been unset
310 # by bash_completion script
312 : ${LOGNAME=$(id -un)}
315 # override and disable tilde expansion
320 # ----------------------------------------------------------------------
322 # ----------------------------------------------------------------------
324 # we always pass these to ls(1)
327 # if the dircolors utility is available, set that up for ls
328 dircolors
="$(type -P gdircolors dircolors | head -1)"
329 test -n "$dircolors" && {
330 COLORS
=/etc
/DIR_COLORS
331 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
332 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
333 test ! -e "$COLORS" && COLORS
=
334 eval `$dircolors --sh $COLORS`
338 # enable color ls output if available
340 LS_COMMON
="--color=auto $LS_COMMON"
342 # setup the main ls alias if we've established common args
343 test -n "$LS_COMMON" &&
344 alias ls="command ls $LS_COMMON"
346 # setup color grep output if available
347 if [ -n "$COLORS" ]; then
350 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
351 test -x /opt
/local
/bin
/grep && alias grep="/opt/local/bin/grep --color=always"
354 alias grep="command grep --color=always"
357 # older versions of grep only support a singular highlight color
358 export GREP_COLOR
='1;37;42'
359 # newer versions of grep have more flexible color configuration
360 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
363 # --------------------------------------------------------------------
365 # --------------------------------------------------------------------
367 # push SSH public key to another box
370 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
374 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
378 # --------------------------------------------------------------------
379 # PATH MANIPULATION FUNCTIONS
380 # --------------------------------------------------------------------
383 # List path entries of PATH or environment variable <var>.
384 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
386 # Usage: pshift [-n <num>] [<var>]
387 # Shift <num> entries off the front of PATH or environment var <var>.
388 # with the <var> option. Useful: pshift $(pwd)
391 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
392 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
395 # Usage: ppop [-n <num>] [<var>]
396 # Pop <num> entries off the end of PATH or environment variable <var>.
399 [ "$1" = "-n" ] && { n
=$2; shift 2; }
401 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
406 # Usage: prm <path> [<var>]
407 # Remove <path> from PATH or environment variable <var>.
408 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
410 # Usage: punshift <path> [<var>]
411 # Shift <path> onto the beginning of PATH or environment variable <var>.
412 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
414 # Usage: ppush <path> [<var>]
415 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
417 # Usage: puniq [<path>]
418 # Remove duplicate entries from a PATH style value while retaining
419 # the original order. Use PATH if no <path> is given.
422 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
423 # /usr/bin:/usr/local/bin
425 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
426 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
429 # -------------------------------------------------------------------
430 # USER SHELL ENVIRONMENT
431 # -------------------------------------------------------------------
433 # source ~/.shenv now if it exists
437 # condense PATH entries
438 PATH
=$(puniq "$PATH")
439 MANPATH
=$(puniq "$MANPATH")
441 # use the color prompt by default when interactive
446 export FZF_DEFAULT_COMMAND
='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,*.swp,.venv}/*" 2> /dev/null'
447 export FZF_DEFAULT_OPTS
='--bind J:down,K:up --reverse --ansi --multi'
449 # -------------------------------------------------------------------
451 # -------------------------------------------------------------------
453 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
454 # get current uname and uptime (if exists on this host)
455 # strip any leading whitespace from uname and uptime commands
456 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
457 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
458 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
460 test -n "$t_uname" && echo $t_uname
461 test -n "$t_uptime" && echo $t_uptime
464 unset t_uname t_uptime
467 # vim: ts=4 sts=4 shiftwidth=4 expandtab
468 # vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2