# -*- mode: sh; coding: utf-8 -*- # # Bash session things # if [ -z "$__mdw_bashrc" ]; then __mdw_bashrc=done [ -z "$__mdw_profile" -a -r $HOME/.bash_profile ] && . $HOME/.bash_profile [ -r /etc/bashrc ] && . /etc/bashrc # --- First of all, set up the prompt string --- if [ -t 0 ]; then case "$TERM" in linux*|screen*|xterm*|vt100*|eterm*) bold="\[$(tput bold)\]" unbold="\[$(tput sgr0)\]" nl="\[ \]" ;; *) bold='' unbold='' nl='' ;; esac if (( EUID == 0 )); then left=`echo « | iconv -f utf8 -t //translit` right=`echo » | iconv -f utf8 -t //translit` else case $USER in mdw|mwooding) u="" left="[" right="]" ;; *) u="\\u@" left="{" right="}" ;; esac if [ "$__mdw_tty" = "`tty`" ]; then left="<" right=">" else export __mdw_tty="`tty`" fi fi if [ -z "$SSH_CLIENT" ] && [ "$__mdw_sechost" != "`hostname`" ] then sec_l='(' sec_r=')' fi PS1="$nl$bold$left$sec_l$u\\h$sec_r \\w$right$unbold" PS2="$PS1 $bold>$unbold " fi # is stdin a tty? # --- Pagers are less useful within Emacs --- case "$INSIDE_EMACS" in 22.*,comint) export PAGER=cat ;; esac # --- Little preferences --- notify=1 set -b shopt -u cdable_vars shopt -s cdspell shopt -s checkhash shopt -s checkwinsize shopt -s cmdhist shopt -u dotglob shopt -s expand_aliases shopt -s extglob shopt -s globstar shopt -s gnu_errfmt shopt -s histappend shopt -s histreedit shopt -u histverify shopt -s hostcomplete shopt -s huponexit shopt -s interactive_comments shopt -s lithist shopt -u mailwarn shopt -u nocaseglob shopt -u nullglob shopt -s promptvars shopt -u shift_verbose shopt -s sourcepath HISTCONTROL=ignorespace:erasedups # --- Set the CDPATH --- # # CDPATH=~/src:/usr/src:/usr/lib:/usr/share # dots=.. # i=6 # while (( i > 0 )); do # CDPATH=$CDPATH:$dots # dots=$dots/.. # (( i -= 1 )) # done # CDPATH=$CDPATH:/ # --- Some colour `ls' support --- [ "${TMPDIR+yes}" ] || eval `tmpdir -b` if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then eval `dircolors -b ~/.dircolors` else unset LS_COLORS fi ls () { if [ -t 1 ]; then command ls $LS_OPTIONS ${LS_COLORS+--color=auto} "$@" else command ls "$@" fi } # --- Some colour `grep' support --- export GREP_COLORS="mt=01;31:ms=01;31:mc=031;31:fn=36:ln=36:bn=36:se=34" greplike () { declare grep=$1; shift if [ -t 1 ]; then command $grep ${GREP_COLORS+--color=always} "$@" | mdw-pager else command $grep "$@" fi } alias grep="greplike grep" alias egrep="greplike egrep" alias fgrep="greplike fgrep" alias zgrep="greplike zgrep" # --- Set up some simple aliases --- alias cx='chmod a+x' alias which="command -v" alias rc="rc -l" alias ssync="rsync -e ssh" alias rootly=$__MDW_ROOTLY alias r=rootly alias re="rootly $EDITOR" alias pstree="pstree -hl" alias cdtmp='cd ${TMPDIR-/tmp}' alias pushtmp='pushd ${TMPDIR-/tmp}' alias e="$EDITOR" alias svn="svnwrap svn" alias @="ssh" [ -r /etc/bash_completion ] && . /etc/bash_completion [ -r $HOME/.bash_completion ] && . $HOME/.bash_completion # --- Make `xt' start an xterm, maybe logging into a remote host --- xt () { case "$1" in @*) local remote=${1#@} title shift if [ $# -gt 0 ]; then title="xterm [$remote] $1" else title="xterm [$remote]" fi (xterm -title "$title" -e ssh $remote "$@" &) ;; *) (xterm "$@" &) ;; esac } # --- Turning on and off core dumps --- core () { case "x$1" in xon|xy|xyes) ulimit -Sc `ulimit -Hc` ;; xoff|xn|xno) ulimit -Sc 0 ;; x) local l=`ulimit -Sc` case $l in 0) echo "Core dumps disabled" ;; unlimited) echo "Core dumps enabled" ;; *) echo "Core dump limit is $l blocks" ;; esac ;; *) echo >&2 "usage: core [yn]" return 1 ;; esac } # --- Turning on and off path hacks --- path-add () { local pathvar export dir val case $# in 1) pathvar=PATH dir=$1 export="export PATH";; 2) pathvar=$1 dir=$2 export=:;; *) echo >&2 "Usage: $0 [VAR] DIR";; esac eval "val=\$$pathvar" case ":$val:" in *:"$dir":*) ;; *) val=$dir:$val ;; esac eval "$pathvar=\$val" $export } path-remove () { local pathvar export dir val case $# in 1) pathvar=PATH dir=$1 export="export PATH";; 2) pathvar=$1 dir=$2 export=:;; *) echo >&2 "Usage: $0 [VAR] DIR";; esac eval "val=\$$pathvar" case ":$val:" in :"$dir":) val= ;; :"$dir":*) val=${val#$dir:} ;; *:"$dir":) val=${val%:$dir} ;; *:"$dir":*) val=${val/:$dir:/:} ;; esac eval "$pathvar=\$val" $export } pathhack () { if [ $# -eq 0 ]; then local IFS=: for e in $PATH; do case "$e" in "$HOME/bin/hacks/"*) echo ${e#$HOME/bin/hacks/} ;; esac done return fi local force=nil local path=$PATH while [ $# -gt 0 ]; do arg=$1 case "$arg" in -f | --force) force=t shift continue ;; --) shift break ;; [-+]*) ;; *) break ;; esac hack=${arg#[+-]} dir=$HOME/bin/hacks/$hack [ -d "$dir" ] || { echo "$0: path hack $hack not found" return 1 } case "$arg,$force,:$PATH:" in -*,*,*:"$dir":*) path-remove path "$dir" ;; +*,t,*:"$dir":*) path-remove path "$dir" path-add path "$dir" ;; +*,nil,*:"$dir":*) ;; +*,*) path-add path "$dir" ;; esac shift done if [ $# -eq 0 ]; then PATH=$path export PATH else PATH=$path "$@" fi } # --- Switching security worlds --- world () { local nfast=${NFAST_HOME-/opt/nfast} local kmdata case "$#" in 0) echo "${NFAST_KMDATA#$nfast/kmdata-}" ;; *) if [ -d "$1" ]; then kmdata=$1 elif [ -d "$nfast/kmdata-$1" ]; then kmdata=$nfast/kmdata-$1 else echo >&2 "world: can't find world $1" return 1 fi shift case "$#" in 0) export NFAST_KMDATA=$kmdata ;; *) "$@" ;; esac ;; esac } # --- Fix `man' under Slowaris --- case "$MACHTYPE" in *solaris*) man () { declare -i i=0 declare arg declare -a man for arg; do case "$arg" in [0-9]*) man[i+=1]="-s" ;; esac man[i+=1]="$arg" done command man "${man[@]}" } ;; esac # --- For `root' use -- some simple molly-guards --- if (( UID == 0 )); then alias rm='rm -i' cp='cp -i' mv='mv -i' set -o noclobber fi [ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local" fi