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 # make sure $MANPATH has some sane defaults
69 : ${MANPATH="/usr/share/man"}
70 test -d "/usr/share/man" && MANPATH
="/usr/share/man:$MANPATH"
72 # include the various sbin's along with /usr/local/bin
73 PATH
="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
74 PATH
="/usr/local/bin:$PATH"
76 # use $HOME specific bin and sbin
77 test -d "$HOME/bin" && PATH
="$HOME/bin:$PATH"
78 test -d "$HOME/sbin" && PATH
="$HOME/sbin:$PATH"
81 test -d "/opt/local" && PATH
="/opt/local/sbin:/opt/local/bin:$PATH"
82 test -d "/opt/local/man" && MANPATH
="/opt/local/man:$MANPATH"
84 test -d "/opt/custom" && PATH
="/opt/custom/sbin:/opt/custom/bin:$PATH"
85 test -d "/opt/custom/man" && MANPATH
="/opt/custom/man:$MANPATH"
87 test -d "/smartdc" && PATH
="/smartdc/bin:/opt/smartdc/bin:/opt/smartdc/agents/bin:$PATH"
88 test -d "/smartdc/man" && MANPATH
="/smartdc/man:$MANPATH"
89 # SmartOS native binaries, for OS/LX zones
90 test -d "/native" && PATH
="$PATH:/native/usr/sbin:/native/usr/bin:/native/sbin:/native/bin"
91 test -d "/native/usr/share/man" && MANPATH
="$MANPATH:/native/usr/share/man"
94 test -d "$HOME/.rvm/bin" && PATH
="$PATH:$HOME/.rvm/bin"
97 test -d "/usr/local/share/golang" && export GOPATH
=/usr
/local
/share
/golang
98 test -n "$GOPATH" && PATH
="$PATH:$GOPATH/bin"
100 # ----------------------------------------------------------------------
101 # ENVIRONMENT CONFIGURATION
102 # ----------------------------------------------------------------------
104 # detect interactive shell
106 *i
*) INTERACTIVE
=yes ;;
107 *) unset INTERACTIVE
;;
116 # enable en_US locale w/ utf-8 encodings if not already
118 : ${LANG:="en_US.UTF-8"}
120 : ${LC_CTYPE:="en_US.UTF-8"}
121 : ${LC_ALL:="en_US.UTF-8"}
122 export LANG LANGUAGE LC_CTYPE LC_ALL
124 # ignore backups, CVS directories, python bytecode, vim swap files
125 FIGNORE
="~:CVS:#:.pyc:.swp:.swa:apache-solr-*"
128 HISTCONTROL
=ignoreboth
132 # ----------------------------------------------------------------------
134 # ----------------------------------------------------------------------
136 # see what we have to work with ...
137 HAVE_VIM
=$(command -v vim)
140 test -n "$HAVE_VIM" &&
146 if test -n "$(command -v less)" ; then
155 export PAGER MANPAGER
157 # ----------------------------------------------------------------------
159 # ----------------------------------------------------------------------
161 # http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
163 if [ "$UID" = 0 ]; then
165 PS_C1
="\[\033[1;31m\]" # red
166 PS_C2
="\[\033[0;37m\]" # grey
171 PS_C1
="\[\033[0;32m\]" # green
172 PS_C2
="\[\033[0;37m\]" # grey
175 PS_C1
="\[\033[1;97m\]" # white
176 PS_C2
="\[\033[0;37m\]" # grey
179 PS_C1
="\[\033[1;96m\]" # cyan
180 PS_C2
="\[\033[0;36m\]" # cyan
183 PS_C1
="\[\033[1;93m\]" # yellow
184 PS_C2
="\[\033[0;33m\]" # brown
197 PS1
="${PS_C1}${PS_P}\[\033[0m\] "
202 # if git and the git bash_completion scripts are installed, use __git_ps1() to show current branch info.
203 # never show branch info for $HOME (dotfiles) repo.
204 # use the following to exclude a given repo: `git config --local --bool --add bash.hidePrompt true`
205 if [ -n "$(type -P git)" -a "$(type -t __git_ps1)" = "function" ]; then
206 PS_GIT
='$(test -n "$(__git_ps1 %s)" &&
207 test "$(git rev-parse --show-toplevel)" != "$HOME" &&
208 test "$(git config --bool bash.hidePrompt)" != "true" &&
209 __git_ps1 "{\[\033[0;40;36m\]%s\[\033[0;90m\]}")'
210 export GIT_PS1_SHOWDIRTYSTATE
=1
212 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\] "
216 # ----------------------------------------------------------------------
217 # MACOS X / DARWIN SPECIFIC
218 # ----------------------------------------------------------------------
220 if [ "$UNAME" = Darwin
]; then
221 # put ports on the paths if /opt/local exists
222 test -x /opt
/local -a ! -L /opt
/local && {
225 # setup the PATH and MANPATH
226 PATH
="$PORTS/bin:$PORTS/sbin:$PATH"
227 MANPATH
="$PORTS/share/man:$MANPATH"
229 # nice little port alias
230 alias port
="sudo nice -n +18 $PORTS/bin/port"
232 # put coreutils on the paths if /usr/local/opt/coreutils/libexec exists
233 test -x /usr
/local
/opt
/coreutils
/libexec
-a ! -L /usr
/local
/opt
/coreutils
/libexec
&& {
234 # setup the PATH and MANPATH
235 PATH
="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
236 MANPATH
="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
240 # ----------------------------------------------------------------------
242 # ----------------------------------------------------------------------
244 if [ "$UNAME" = SunOS
]; then
245 # use GNU versions of core utils
246 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep"
247 test -x /usr
/gnu
/bin
/sed && alias sed="/usr/gnu/bin/sed"
248 test -x /usr
/gnu
/bin
/awk && alias awk="/usr/gnu/bin/awk"
251 # ----------------------------------------------------------------------
252 # ALIASES / FUNCTIONS
253 # ----------------------------------------------------------------------
258 alias ll.
="ls -ld .*"
261 # use 'git diff --no-index' as a prettier 'diff' alternative (if available)
262 test -n "$(type -P git)" && alias diff="git diff --no-index"
264 # alias 'vi' to 'vim' if Vim is installed
271 # disk usage with human sizes and minimal depth
272 alias du1
='du -h --max-depth=1'
273 alias fn
='find . -name'
274 alias hi
='history | tail -20'
276 # alias csh-style "rebash" to bash equivalent
277 alias rehash
="hash -r"
279 # set 'screen' window title
281 printf "\033k%s\033\\" "$@"
283 # set 'xterm' window title
285 printf "\033]0;%s\007" "$@"
289 alias svn
=svn
-wrapper
291 # ----------------------------------------------------------------------
293 # ----------------------------------------------------------------------
295 test -z "$BASH_COMPLETION" && {
296 bash
=${BASH_VERSION%.*}; bmajor
=${bash%.*}; bminor
=${bash#*.}
297 test -n "$PS1" && test $bmajor -gt 1 && {
298 # search for a bash_completion file to source
299 for f
in /usr
/local
/etc
/bash_completion \
300 /usr
/pkg
/etc
/bash_completion \
301 /opt
/local
/etc
/bash_completion \
302 /etc
/bash_completion \
303 /etc
/bash
/bash_completion
311 unset bash bmajor bminor
314 # restore some key environment variables which may have been unset
315 # by bash_completion script
317 : ${LOGNAME=$(id -un)}
320 # override and disable tilde expansion
325 # ----------------------------------------------------------------------
327 # ----------------------------------------------------------------------
329 # we always pass these to ls(1)
332 # if the dircolors utility is available, set that up for ls
333 dircolors
="$(type -P gdircolors dircolors | head -1)"
334 test -n "$dircolors" && {
335 COLORS
=/etc
/DIR_COLORS
336 test -e "/etc/DIR_COLORS.$TERM" && COLORS
="/etc/DIR_COLORS.$TERM"
337 test -e "$HOME/.dircolors" && COLORS
="$HOME/.dircolors"
338 test ! -e "$COLORS" && COLORS
=
339 eval `$dircolors --sh $COLORS`
343 # enable color ls output if available
345 LS_COMMON
="--color=auto $LS_COMMON"
347 # setup the main ls alias if we've established common args
348 test -n "$LS_COMMON" &&
349 alias ls="command ls $LS_COMMON"
351 # setup color grep output if available
352 if [ -n "$COLORS" ]; then
355 test -x /usr
/gnu
/bin
/grep && alias grep="/usr/gnu/bin/grep --color=always"
356 test -x /opt
/local
/bin
/grep && alias grep="/opt/local/bin/grep --color=always"
359 alias grep="command grep --color=always"
362 # older versions of grep only support a singular highlight color
363 export GREP_COLOR
='1;37;42'
364 # newer versions of grep have more flexible color configuration
365 export GREP_COLORS
='fn=36:ln=1;33:ms=1;37;42'
368 # --------------------------------------------------------------------
370 # --------------------------------------------------------------------
372 # push SSH public key to another box
375 test -f ~
/.ssh
/id_rsa.pub
|| ssh-keygen -t rsa
-b 4096
379 ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~
/.ssh
/id_rsa.pub
383 # --------------------------------------------------------------------
384 # PATH MANIPULATION FUNCTIONS
385 # --------------------------------------------------------------------
388 # List path entries of PATH or environment variable <var>.
389 pls
() { eval echo \$
${1:-PATH} |tr : '\n'; }
391 # Usage: pshift [-n <num>] [<var>]
392 # Shift <num> entries off the front of PATH or environment var <var>.
393 # with the <var> option. Useful: pshift $(pwd)
396 [ "$1" = "-n" ] && { n
=$(( $2 + 1 )); shift 2; }
397 eval "${1:-PATH}='$(pls |tail -n +$n |tr '\n' :)'"
400 # Usage: ppop [-n <num>] [<var>]
401 # Pop <num> entries off the end of PATH or environment variable <var>.
404 [ "$1" = "-n" ] && { n
=$2; shift 2; }
406 do eval "${1:-PATH}='\${${1:-PATH}%:*}'"
411 # Usage: prm <path> [<var>]
412 # Remove <path> from PATH or environment variable <var>.
413 prm
() { eval "${2:-PATH}='$(pls $2 |grep -v "^$1\$" |tr '\n' :)'"; }
415 # Usage: punshift <path> [<var>]
416 # Shift <path> onto the beginning of PATH or environment variable <var>.
417 punshift
() { eval "${2:-PATH}='$1:$(eval echo \$${2:-PATH})'"; }
419 # Usage: ppush <path> [<var>]
420 ppush
() { eval "${2:-PATH}='$(eval echo \$${2:-PATH})':$1"; }
422 # Usage: puniq [<path>]
423 # Remove duplicate entries from a PATH style value while retaining
424 # the original order. Use PATH if no <path> is given.
427 # $ puniq /usr/bin:/usr/local/bin:/usr/bin
428 # /usr/bin:/usr/local/bin
430 echo "$1" | tr : '\n' | nl | sort -u -k 2,2 | sort -n |
431 cut
-f 2- | tr '\n' : | sed -e 's/:$//' -e 's/^://'
434 # -------------------------------------------------------------------
435 # USER SHELL ENVIRONMENT
436 # -------------------------------------------------------------------
438 # source ~/.shenv now if it exists
442 # condense PATH entries
443 PATH
=$(puniq "$PATH")
444 MANPATH
=$(puniq "$MANPATH")
446 # use the color prompt by default when interactive
451 export FZF_DEFAULT_COMMAND
='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,*.swp,.venv}/*" 2> /dev/null'
452 export FZF_DEFAULT_OPTS
='--bind J:down,K:up --reverse --ansi --multi'
454 # -------------------------------------------------------------------
456 # -------------------------------------------------------------------
458 test -n "$INTERACTIVE" -a -n "$LOGIN" && {
459 # get current uname and uptime (if exists on this host)
460 # strip any leading whitespace from uname and uptime commands
461 t_uname
="$(test -n "`type -P uname`" && uname -npsr | sed -e 's/^\s+//')"
462 t_uptime
="$(test -n "`type -P uptime`" && uptime | sed -e 's/^\s+//')"
463 if [ -n "$t_uname" ] || [ -n "$t_uptime" ]; then
465 test -n "$t_uname" && echo $t_uname
466 test -n "$t_uptime" && echo $t_uptime
469 unset t_uname t_uptime
472 # vim: ts=4 sts=4 shiftwidth=4 expandtab
473 # vim: foldmethod=expr foldexpr=autofolds#foldexpr(v\:lnum,'sh') foldtext=autofolds#foldtext() foldlevel=2