X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/f617db13b0685c674817a6c7c1d148da3c07081f..004beb573d8f7434fa42f3eafdf2fd1af0bbcfd7:/bashrc diff --git a/bashrc b/bashrc index 6587800..7f4cd74 100644 --- a/bashrc +++ b/bashrc @@ -1,5 +1,4 @@ -# -# $Id: .bashrc,v 1.6 1996/12/08 20:33:42 mdw Exp $ +# -*- mode: sh; coding: utf-8 -*- # # Bash session things # @@ -15,40 +14,49 @@ __mdw_bashrc=done if [ -t 0 ]; then - if [ "$TERM" = "dumb" ]; then - if (( EUID == 0 )); then PS1="# "; else PS1="\$ "; fi - PS2="> " - PS4="+ " + 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 "$TERM" in - linux*|screen*|xterm*|vt100*) - bold='\[\]' unbold='\[\]' nl='\[ \]' ;; + case $USER in + mdw|mwooding) + u="" left="[" right="]" + ;; *) - bold='' unbold='' nl='' ;; + u="\\u@" left="{" right="}" + ;; esac - - if (( EUID == 0 )); then - left="«" right="»" - elif [ "$__mdw_tty" = "`tty`" ]; then + if [ "$__mdw_tty" = "`tty`" ]; then left="<" right=">" else - left="[" right="]" 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\\h$sec_r \\w$right$unbold" - PS2="$PS1 $bold>$unbold " + 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 @@ -76,7 +84,7 @@ shopt -u shift_verbose shopt -s sourcepath # --- Set the CDPATH --- -# +# # CDPATH=~/src:/usr/src:/usr/lib:/usr/share # dots=.. # i=6 @@ -90,8 +98,7 @@ shopt -s sourcepath # --- Some colour `ls' support --- [ "${TMPDIR+yes}" ] || eval `tmpdir -b` -if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ] && - [ "$TERM" != "dumb" ]; then +if [ -x /usr/bin/dircolors -o -x /usr/local/bin/dircolors ]; then eval `dircolors -b ~/.dircolors` else unset LS_COLORS @@ -105,53 +112,39 @@ ls () { fi } -# --- Setting xterm titles --- -# -# This doesn't work so well any more. :-( - -# if [ -e /usr/lib/bash/xtitle.so ]; then -# enable -f /usr/lib/bash/xtitle.so xtitle -# elif [ -e /usr/local/lib/xtitle.so ]; then -# enable -f /usr/local/lib/xtitle.so xtitle -# elif [ -e $HOME/lib/bash/xtitle.so ]; then -# enable -f $HOME/lib/bash/xtitle.so xtitle -# else -# xtitle () { return 1; } -# fi -xtitle () { return 1; } - -entitle () { - local t="`xtitle -q`" st - xtitle "$t $1" - shift - "$@"; st=$? - xtitle "$t" - return $st +# --- 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=auto} "$@" + else + command $grep "$@" + fi } +alias grep="greplike grep" +alias egrep="greplike egrep" +alias fgrep="greplike fgrep" # --- Set up some simple aliases --- alias cx='chmod a+x' alias which="command -v" alias ssync="rsync -e ssh" -alias rootly="entitle root become -g0 root" +alias rootly=$__MDW_ROOTLY alias r=rootly -alias eh="entitle 'Egham Hills 90210' tf eh" -alias news="entitle Usenet slrn" -alias splitvt='splitvt -t "`xtitle -q || echo xterm` splitvt"' -alias pstree="pstree -Ghl" +alias re="rootly $EDITOR" +alias pstree="pstree -hl" alias cdtmp='cd ${TMPDIR-/tmp}' alias pushtmp='pushd ${TMPDIR-/tmp}' -alias e="sensible-editor" -alias svn=svnwrap - -@ () { - local t="`xtitle -q`" host="$1" - shift - xtitle "$t [$host]" - ssh "$host" "$@" - xtitle "$t" -} +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 --- @@ -198,6 +191,104 @@ core () { 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 +} + # --- Fix `man' under Slowaris --- case "$MACHTYPE" in @@ -223,4 +314,6 @@ if (( UID == 0 )); then set -o noclobber fi +[ -f "$HOME/.bashrc-local" ] && . "$HOME/.bashrc-local" + fi