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 # ----------------------------------------------------------------------
8 # ----------------------------------------------------------------------
10 # short-circuit for non-interactive sessions
11 [ -z "$PS1" ] && return
14 PATH
="/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:$PATH"
16 : ${LOGNAME=$(id -un)}
18 # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
19 UNAME
=${UNAME/CYGWIN_*/Cygwin}
21 # complete hostnames from this file
22 HOSTFILE
=~
/.ssh
/known_hosts
27 # if current $TERM isn't valid, fall-back to TERM=xterm-color or TERM=xterm
28 case $(tput colors 2>&1) in
30 export TERM
=xterm
-color
31 case $(tput colors 2>&1) in
39 # ----------------------------------------------------------------------
41 # ----------------------------------------------------------------------
43 # notify of bg job completion immediately
46 # shell opts. see bash(1) for details
47 shopt -s cdspell
>/dev
/null
2>&1
48 shopt -s checkjobs
>/dev
/null
2>&1
49 shopt -s checkwinsize
>/dev
/null
2>&1
50 shopt -s extglob
>/dev
/null
2>&1
51 shopt -s histappend
>/dev
/null
2>&1
52 shopt -s hostcomplete
>/dev
/null
2>&1
53 shopt -s interactive_comments
>/dev
/null
2>&1
54 shopt -u mailwarn
>/dev
/null
2>&1
55 shopt -s no_empty_cmd_completion
>/dev
/null
2>&1
57 # don't check for new mail
66 # ----------------------------------------------------------------------
68 # ----------------------------------------------------------------------
70 # include the various sbin's along with /usr/local/bin
71 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
72 PATH
="/usr/local/bin:$PATH"
74 # use $HOME specific bin and sbin
75 test -d "$HOME/bin" && PATH
="$HOME/bin:$PATH"
76 test -d "$HOME/sbin" && PATH
="$HOME/sbin:$PATH"
79 test -d "/opt/local" && PATH
="/opt/local/sbin:/opt/local/bin:$PATH"
81 test -d "/opt/custom" && PATH
="/opt/custom/sbin:/opt/custom/bin:$PATH"
83 test -d "/smartdc" && PATH
="/smartdc/bin:/opt/smartdc/bin:/opt/smartdc/agents/bin:$PATH"
84 # SmartOS native binaries, for OS/LX zones
85 test -d "/native" && PATH
="$PATH:/native/usr/sbin:/native/usr/bin:/native/sbin:/native/bin"
88 test -d "$HOME/.rvm/bin" && PATH
="$PATH:$HOME/.rvm/bin"
91 test -d "/usr/local/share/golang" && export GOPATH
=/usr
/local
/share
/golang
92 test -n "$GOPATH" && PATH
="$PATH:$GOPATH/bin"
94 # ----------------------------------------------------------------------
95 # ENVIRONMENT CONFIGURATION
96 # ----------------------------------------------------------------------
98 # detect interactive shell
100 *i
*) INTERACTIVE
=yes ;;
101 *) unset INTERACTIVE
;;
110 # setup locale. Try to enable en_US locale w/ utf-8 encodings
111 # (if not already configured), but do graceful fall-back.
112 lclist
=$(locale -a | grep en_US)
113 if test -n "$(echo $lclist | grep UTF-8)"; then
114 : ${LANG:="en_US.UTF-8"}
116 : ${LC_CTYPE:="en_US.UTF-8"}
117 : ${LC_ALL:="en_US.UTF-8"}
118 elif test -n "$(echo $lclist | grep utf8)"; then
119 : ${LANG:="en_US.utf8"}
121 : ${LC_CTYPE:="en_US.utf8"}
122 : ${LC_ALL:="en_US.utf8"}
123 elif test -n "$(echo $lclist | grep ISO8859-1)"; then
124 : ${LANG:="en_US.ISO8859-1"}
126 : ${LC_CTYPE:="en_US.ISO8859-1"}
127 : ${LC_ALL:="en_US.ISO8859-1"}
131 : ${LC_CTYPE:="en_US"}
134 export LANG LANGUAGE LC_CTYPE LC_ALL
137 # ignore backups, CVS directories, python bytecode, vim swap files
138 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
141 HISTCONTROL
=ignoreboth
145 # ----------------------------------------------------------------------
147 # ----------------------------------------------------------------------
149 # see what we have to work with ...
150 HAVE_VIM
=$(command -v vim)
153 test -n "$HAVE_VIM" &&
159 if test -n "$(command -v less)" ; then
168 export PAGER MANPAGER
170 # ----------------------------------------------------------------------
172 # ----------------------------------------------------------------------
174 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
176 if [ "$UID" = 0 ]; then
178 PS_C1
="\[\033[1;31m\]" # red
179 PS_C2
="\[\033[0;37m\]" # grey
184 PS_C1
="\[\033[0;32m\]" # green
185 PS_C2
="\[\033[0;37m\]" # grey
188 PS_C1
="\[\033[1;97m\]" # white
189 PS_C2
="\[\033[0;37m\]" # grey
192 PS_C1
="\[\033[1;96m\]" # cyan
193 PS_C2
="\[\033[0;36m\]" # cyan
196 PS_C1
="\[\033[1;93m\]" # yellow
197 PS_C2
="\[\033[0;33m\]" # brown
210 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
215 # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
216 # never show branch info for $HOME (dotfiles) repo.
217 # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
218 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
219 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
220 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
221 test "$(git config --bool bash.hidePrompt)" != "true" &&
222 __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")'
223 export GIT_PS1_SHOWDIRTYSTATE
=1
225 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\] "
229 # ----------------------------------------------------------------------
230 # MACOS X / DARWIN SPECIFIC
231 # ----------------------------------------------------------------------
233 if [ "$UNAME" = Darwin
]; then
234 # put ports on the paths if /opt/local exists
235 test -x /opt
/local -a ! -L /opt
/local && {
238 # setup the PATH and MANPATH
239 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
240 MANPATH
="$PORTS/share/man:$MANPATH"
242 # nice little port alias
243 alias port
="sudo nice -n +18 $PORTS/bin/port"
245 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
246 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
247 # setup the PATH and MANPATH
248 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
249 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
253 # ----------------------------------------------------------------------
255 # ----------------------------------------------------------------------
257 if [ "$UNAME" = SunOS
]; then
258 # use GNU versions of core utils
259 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
260 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
261 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
262 test -x /usr
/xpg
4/bin
/sed && alias sed="/usr/xpg4/bin/sed"
263 test -x /usr
/xpg
4/bin
/awk && alias awk="/usr/xpg4/bin/awk"
266 MANPATH
="/usr/share/man:/smartdc/man:/opt/smartdc/man:/opt/local/man:/opt/custom/man:$MANPATH"
269 # ----------------------------------------------------------------------
270 # ALIASES / FUNCTIONS
271 # ----------------------------------------------------------------------
276 alias ll.
="ls -ld .*"
279 # use 'git diff --no-index' as a prettier 'diff' alternative (if available)
280 test -n "$(type -P git)" && alias diff="git diff --no-index"
282 # alias 'vi' to 'vim' if Vim is installed
289 # disk usage with human sizes and minimal depth
290 alias du1
='du -h --max-depth=1'
291 alias fn
='find . -name'
292 alias hi
='history | tail -20'
294 # alias csh-style "rebash" to bash equivalent
295 alias rehash
="hash -r"
297 # set 'screen' window title
299 printf "\033k%s\033\\" "$@"
301 # set 'xterm' window title
303 printf "\033]0;%s\007" "$@"
307 alias svn
=svn
-wrapper
309 # ----------------------------------------------------------------------
311 # ----------------------------------------------------------------------
313 test -z "$BASH_COMPLETION" && {
314 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
315 test -n "$PS1" && test $bmajor -gt 1 && {
316 # search for a bash_completion file to source
317 for f
in /usr
/local
/etc
/bash_completion \
318 /usr
/pkg
/etc
/bash_completion \
319 /opt
/local
/etc
/bash_completion \
320 /etc
/bash_completion \
321 /etc
/bash
/bash_completion
329 unset bash bmajor bminor
332 # restore some key environment variables which may have been unset
333 # by bash_completion script
335 : ${LOGNAME=$(id -un)}
338 # override and disable tilde expansion
343 # ----------------------------------------------------------------------
345 # ----------------------------------------------------------------------
347 # we always pass these to ls(1)
350 # if the dircolors utility is available, set that up for ls
351 dircolors
="$(type -P gdircolors dircolors | head -1)"
352 test -n "$dircolors" && {
353 COLORS
=/etc
/DIR_COLORS
354 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
355 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
356 test ! -e "$COLORS" && COLORS
=
357 # AIX (vx-track) has dircolors(1) but ls(1) doesn't support --color arg
358 test "$UNAME" = "AIX" && COLORS
=
359 eval `$dircolors --sh $COLORS`
363 # enable color ls output if available
365 LS_COMMON
="--color=auto $LS_COMMON"
367 # setup the main ls alias if we've established common args
368 test -n "$LS_COMMON" &&
369 alias ls="command ls $LS_COMMON"
371 # setup color grep output if available
372 if [ -n "$COLORS" ]; then
375 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
376 test -x /opt
/local
/bin
/grep && alias grep="/opt/local/bin/grep --color=always"
379 alias grep="command grep --color=always"
382 # older versions of grep only support a singular highlight color
383 export GREP_COLOR
='1;37;42'
384 # newer versions of grep have more flexible color configuration
385 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
388 # --------------------------------------------------------------------
390 # --------------------------------------------------------------------
392 # push SSH public key to another box
395 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
399 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
403 # --------------------------------------------------------------------
404 # PATH MANIPULATION FUNCTIONS
405 # --------------------------------------------------------------------
408 # List path entries of PATH or environment variable <var>.
409 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
411 # Usage: pshift [-n <num>] [<var>]
412 # Shift <num> entries off the front of PATH or environment var <var>.
413 # with the <var> option. Useful: pshift $(pwd)
416 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
417 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
420 # Usage: ppop [-n <num>] [<var>]
421 # Pop <num> entries off the end of PATH or environment variable <var>.
424 [ "$1" = "-n" ] && { n
=$2; shift 2; }
426 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
431 # Usage: prm <path> [<var>]
432 # Remove <path> from PATH or environment variable <var>.
433 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
435 # Usage: punshift <path> [<var>]
436 # Shift <path> onto the beginning of PATH or environment variable <var>.
437 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
439 # Usage: ppush <path> [<var>]
440 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
442 # Usage: puniq [<path>]
443 # Remove duplicate entries from a PATH style value while retaining
444 # the original order. Use PATH if no <path> is given.
447 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
448 # /usr/bin:/usr/local/bin
450 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
451 cut
-f 2- | tr '\n' :
454 # -------------------------------------------------------------------
455 # USER SHELL ENVIRONMENT
456 # -------------------------------------------------------------------
458 # source ~/.shenv now if it exists
462 # condense PATH entries
463 PATH
=$(puniq "$PATH")
464 MANPATH
=$(puniq "$MANPATH")
466 # use the color prompt by default when interactive
471 export FZF_DEFAULT_COMMAND
='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,*.swp,.venv}/*" 2> /dev/null'
472 export FZF_DEFAULT_OPTS
='--bind J:down,K:up --reverse --ansi --multi'
474 # -------------------------------------------------------------------
476 # -------------------------------------------------------------------
478 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
479 # get current uname and uptime (if exists on this host)
480 # strip any leading whitespace from uname and uptime commands
481 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
482 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
483 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
485 test -n "$t_uname" && echo $t_uname
486 test -n "$t_uptime" && echo $t_uptime
489 unset t_uname t_uptime
492 # vim: ts=4 sts=4 shiftwidth=4 expandtab
493 # vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2