User:Cdemarco/.bashrc

From WPLUG
Revision as of 14:58, 11 December 2008 by Cdemarco (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
# First things first: Where are we?
if [ $(uname) == "Darwin" ]; then
    PLATFORM=MAC
else
    PLATFORM=LINUX
fi


# # ## ### ##### ######## ############# #####################
# source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
# For later use...
qwhich() {
    which >/dev/null 2>&1
}
if [ "$PS1" ] && [ $TERM != "emacs" ] && [ -x /usr/bin/tput ] && \
    [ "x`tput kbs`" != "x" ]; then 
        # Fix the annoyance whereby 'xemacs -nw' can't invoke help...
        stty ek
        # Fix backspace/delete
             stty erase ^H
             stty erase `tput kbs`
fi
# PROMPT_COMMAND doesn't work at console
case $TERM in
    "linux" | "dumb" | "emacs")
        true
        ;;
    *)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
        ;;
esac


# # ## ### ##### ######## ############# #####################
# Set PS1
use_color=false
safe_term=${TERM//[^[:alnum:]]/.}       # sanitize TERM
if  -f /etc/DIR_COLORS  ; then
        grep -q "^TERM ${safe_term}" /etc/DIR_COLORS && use_color=true
elif type -p dircolors >/dev/null ; then
        if dircolors --print-database | grep -q "^TERM ${safe_term}" ; then
                use_color=true
        fi
fi
if ${use_color} ; then
    COLORS=(30 32 33 34 35 36 37)
    n=$(($RANDOM % ${#COLORS[*]}))
    b=$(($RANDOM % 2))
    if [[ ${EUID} == 0 ]] ; then
        PS1='\[\033[01;31m\]$(returncode)\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
    else
        PS1='\[\033[${b};31m\]$(returncode)'"\[\033[01;${COLORS[n]}m\]\u@\h \[\033[01;34m\]\w \$ \[\033[00m\]"
    fi
else
    if [[ ${EUID} == 0 ]] ; then
        # show root@ when we don't have colors
        PS1='$(returncode)\u@\h \W \$ '
    else
        PS1='$(returncode)\u@\h \w \$ '
    fi
fi
# Bell too loud?  Too ugly?
if [ $TERM == "linux" ] ; then
    setterm -blength 5 -bfreq 100
fi


if [ $(qwhich lesspipe) ]; then
    eval $(lesspipe) # [1]
fi
umask 0077


# # ## ### ##### ######## ############# #####################
# env variables
if [ -a /proc/cpuinfo ]; then
    export CONCURRENCY_LEVEL=$(($(grep -c processor /proc/cpuinfo) * 2 + 1))
    export MAKEOPTS="-j${CONCURRENCY_LEVEL}"
fi
export PAGER="less -R"
if [ $UID -eq 0 ]; then
#    EDITOR="xemacs -nw"
    EDITOR="emacs -nw"
else
#    EDITOR="gnuclient -nw"
    EDITOR="emacs -nw"
fi
VISUAL=$EDITOR
export EDITOR VISUAL
export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
export PYTHONSTARTUP="$HOME/.pythonrc.py"
export PYTHONPATH="/$HOME/lib"
export LOCALE=en_us
export LANG=C
export PATH=$PATH:$HOME/bin:/sbin:/usr/sbin
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export GREP_COLOR='01;33'
unset USERNAME
export JAVA_HOME=/usr
export LESS_TERMCAP_mb=$'\e[01;31m'
export LESS_TERMCAP_md=$'\e[01;31m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;44;33m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_us=$'\e[01;32m'
export LESS_TERMCAP_ue=$'\e[0m' 


# # ## ### ##### ######## ############# #####################
# aliases
if [ $PLATFORM == "MAC" ]; then
    alias ls='ls -Fh'
    alias sl='ls -Fh'
else 
    case $TERM in
    "emacs" | "dumb")
            alias ls='ls --color=no -Fh'
            alias sl='ls --color=no -Fh'
        ;;
    *)
            alias ls='ls --color=yes -Fh'
            alias sl='ls --color=yes -Fh'
        ;;
    esac
fi
alias ipgrep='egrep -o "(([0-9]{1,3}\.){3}[0-9]{1,3})"'
alias rot13='tr A-Za-z N-ZA-Mn-za-m'
alias ssh='ssh -v'
alias dirs='dirs -l -p'
alias pushd='pushd >/dev/null'
alias popd='popd >/dev/null'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias enscript='enscript -B --font=Courier6'
alias his='history'
alias hgrep='his | grep'
alias cg='egrep -v "^($|space:*#|;)" '
alias pysh='ipython -p sh'
grep  --color=yes 1 /bin/true  >/dev/null 2>&1
if ! [ $? -gt 0 ] && [ $TERM != 'dumb' ]; then
    alias grep='grep --color=yes'
fi
alias less='less -R' # better than -r
alias dircounts='for d in `find . -maxdepth 1 -type d`; do
    [ $d == '.' ] && continue
    find $d -type f | wc -l | perl -pe 'chomp';
    echo " $d"; done | sort -n'
alias dirsizes='find . -maxdepth 1 -type d -name mnt -prune -o -exec du -sk \{\} \; | sort -n'
[ $(qwhich vim ) ] && alias vi='vim'


# # ## ### ##### ######## ############# #####################
# functions
if [ $(qwhich gksu) ]; then
    true
else
    gksu() {
        sudo bash -c "export DISPLAY=:0.0; $1"
    }
fi
function returncode {  # [1]
  returncode=$?
    if [ $returncode != 0 ]; then
        echo "[$returncode]"
    else
        echo ""
    fi
}
function em { 
    /usr/bin/emacs -nw $*
}
function eml {
    em "-l ~/.emacs.d/$*"
}
function otf {
    H=$1
    echo "pinging..."
    answer=$(ping -c 3 $H 2>&1)
    if [ $? -eq 0 ]; then
        echo "$answer"
        return 0
    fi
    echo "arpinging..."
    answer=$(arping -c 3 $H 2>&1)
    if [ $? -eq 0 ]; then
        echo "$answer"
        return 0
    fi
    echo "portscanning..."
    answer=$(sudo scanrand $H:all 2>&1)
    if [ "${answer}foo" != "foo" ]; then
        echo "$answer"
        return 0
    fi
    echo "$H is not alive."
    return 1
}
walkback() {
    f=$1
    n=$m
    m=$(($m - 1))
    svn diff -r${m}:${n} $f
}
findword() {
    for f in \
        $(find . -type f | \
        grep -v .svn); do \
        file $f | grep -q text && grep -iH $1 $f; \
        done
}