.bashrc
author Adam Gomaa <code@adam.gomaa.us>
Tue Aug 04 10:18:35 2009 -0400
changeset 315 2713a9b2fc0a
parent 313 224cfedb0c81
child 324 5054a55f7c37
permissions -rw-r--r--
Fix a typo.
     1 # ~/.bashrc: executed by bash(1) for non-login shells.
     2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
     3 # for examples
     4 umask 022
     5 
     6 export DOTROOT=$HOME/var/srv/hg.gomaa.us/dotfiles
     7 
     8 add_to_pythonpath()
     9 {
    10     if [ ! -d $1 ]; then
    11         return
    12     fi
    13     if ! echo $PYTHONPATH | /bin/egrep -q "(^|:)$1($|:)" ; then
    14         if [ "$2" = "after" ] ; then
    15             PYTHONPATH=$PYTHONPATH:$1
    16         else
    17             PYTHONPATH=$1:$PYTHONPATH
    18         fi
    19     fi
    20 }
    21 add_to_path()
    22 {
    23     if [ ! -d $1 ]; then
    24         return
    25     fi
    26     if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
    27         if [ "$2" = "after" ] ; then
    28             PATH=$PATH:$1
    29         else
    30             PATH=$1:$PATH
    31         fi
    32     fi
    33 }
    34 PYTHON_VERSION=`python -V 2>&1 | awk '{print $2}' | awk -F . '{print $1"."$2}'`
    35 export PYTHONPATH
    36 export PATH
    37 add_to_pythonpath ~/var/lib/python$PYTHON_VERSION/site-packages
    38 add_to_pythonpath ~/.local/lib/python$PYTHON_VERSION/site-packages
    39 add_to_pythonpath ~/.local/lib
    40 add_to_pythonpath $DOTROOT/python
    41 add_to_path /usr/local/sbin
    42 add_to_path /usr/sbin
    43 add_to_path /sbin
    44 add_to_path ~/.bin
    45 add_to_path ~/.local/bin
    46 add_to_path ~/var/bin
    47 add_to_path $DOTROOT/bin
    48 add_to_path ~/.ec2/bin
    49 add_to_path /usr/local/bin
    50 add_to_path /usr/bin
    51 add_to_path /bin
    52 add_to_path /usr/games
    53 export TEXINPUTS=$TEXINPUTS:~/.lib/tex:~/share/tex:.:~/.lib/tex:~/share/tex:.:~/.lib/tex:~/share/tex:.:~/.lib/tex:~/share/tex
    54 export PYTHONSTARTUP=~/.pythonrc.py
    55 # Syntax-highlighting less. 
    56 LESS='-R'; export LESS
    57 export LESSOPEN="| lesspipe %s"
    58 
    59 export WORKON_HOME=$HOME/.virtualenvs
    60 
    61 fuzzyfind()
    62 {
    63     local base=$1
    64     local fname=$2
    65     local path=$base/$fname
    66 
    67     if [ -d $path ] 
    68     then
    69         export FUZZYFIND_PATH=$path
    70         return 0
    71     else
    72         path=$base/*$2*
    73         # This is probably me revealing my lack of bash-fu.
    74         if [ -d $path ] 
    75             then
    76             export FUZZYFIND_PATH=$path
    77             return 0
    78             else
    79             return 1
    80         fi
    81     fi
    82 }
    83 
    84 fuzzyfind-frontend()
    85 {
    86     fuzzyfind $1 $2
    87     if [ "$?" -eq "0" ]; then 
    88         if [ "$TERM" = "screen" ]; then
    89             # Set the title to whatever project I'm working on, if in
    90             # screen.
    91             screen -X title $2
    92         fi
    93         local new_path=$FUZZYFIND_PATH
    94         unset FUZZYFIND_PATH
    95         cd $new_path
    96     else
    97         echo "Unable to find $1/$2 or similar"
    98     fi
    99 }
   100 
   101 src()
   102 {
   103     fuzzyfind-frontend ~/var/srv $1
   104 }
   105 
   106 greppy()
   107 {
   108     grep --color="auto" -Ri --include="*.py" $1 ./
   109 }
   110 
   111 
   112 # Seems like loop time.
   113 
   114 if [ -f ~/.bash_local ]; then
   115     . ~/.bash_local
   116 fi
   117 
   118 if [ -f ~/.bash_aliases ]; then
   119     . ~/.bash_aliases
   120 fi
   121 
   122 if [ -f $DOTROOT/.bash.d/mercurial_completion ]; then
   123     . $DOTROOT/.bash.d/mercurial_completion
   124 fi
   125 
   126 if [ -f $DOTROOT/.bash.d/virtualenvwrapper_bashrc ]; then
   127     . $DOTROOT/.bash.d/virtualenvwrapper_bashrc
   128 fi
   129 
   130 
   131 
   132 # If not running interactively, don't do any more. 
   133 [ -z "$PS1" ] && return
   134 
   135 # don't put duplicate lines in the history, and ignore same sucessive entries.
   136 export HISTCONTROL=ignoreboth
   137 export EDITOR=emacsclient
   138 
   139 # check the window size after each command and, if necessary,
   140 # update the values of LINES and COLUMNS.
   141 shopt -s checkwinsize
   142 shopt -s histappend
   143 
   144 # enable color support of ls and also add handy aliases
   145 if [ "$TERM" != "dumb" ]; then
   146     eval "`dircolors -b`"
   147     alias ls='ls --color=auto'
   148     #alias dir='ls --color=auto --format=vertical'
   149     #alias vdir='ls --color=auto --format=long'
   150 fi
   151 
   152 
   153 _prompt_pwd()
   154 {
   155     case $PWD in
   156         $HOME)
   157             echo -n '~'
   158             ;;
   159         *)
   160             local last=${PWD/#*\//}
   161             echo -n $PWD | sed -e "s|^$HOME|~|" \
   162                                -e 's-/\([^/]\{2\}\)\([^/]*\)-/\1-g' \
   163                                -e "s|\$|${last:2}|"
   164             ;;
   165     esac
   166 }
   167 
   168 function cd_and_ls {
   169     cd $1 && ls
   170 }
   171 function cd_and_ll {
   172     cd $1 && ll
   173 }
   174 alias c=cd_and_ls
   175 alias cl=cd_and_ll
   176 
   177 reload()
   178 {
   179     source ~/.bashrc
   180 }
   181 
   182 GRAY=`tput setaf 0`
   183 RED=`tput setaf 1`
   184 GREEN=`tput setaf 2`
   185 YELLOW=`tput setaf 3`
   186 BLUE=`tput setaf 4`
   187 MAGENTA=`tput setaf 5`
   188 CYAN=`tput setaf 6`
   189 WHITE=`tput setaf 7`
   190 BOLD=`tput bold`
   191 RESET=`tput sgr0`
   192 GREEN_PS1='\[$GREEN\]\[$BOLD\]$(_ident)\[$RESET\]\[$MAGENTA\]$(_prompt_pwd)/\[$GREEN\]\$\[$RESET\] '
   193 YELLOW_PS1='\[$GREEN\]\[$BOLD\]$(_ident)\[$RESET\]\[$MAGENTA\]$(_prompt_pwd)/\[$YELLOW\]\$\[$RESET\] '
   194 PS1=GREEN_PS1
   195 
   196 _inside_screen()
   197 {
   198     # I hate bash.
   199     if [ "$STY" = "" ]; then
   200         echo "false"
   201     else
   202         echo "true"
   203     fi
   204 }
   205 
   206 if [ `_inside_screen` = "true" ]; then
   207     PS1=$YELLOW_PS1
   208 else
   209     PS1=$GREEN_PS1
   210 fi
   211 
   212 _ident()
   213 {
   214     if [ `_inside_screen` = "true" ]; then
   215         echo "$(hostname)($STY)"
   216     else
   217         echo $(hostname)
   218     fi
   219 }
   220 
   221 _screen_name()
   222 {
   223     expr "$STY" : '[0-9]*\.\([a-z\.]*\)'
   224 }
   225 mkdir -p ~/.bash_history.d
   226 
   227 if [ `_inside_screen` = "true" ]; then
   228     # If I'm inside screen, set the caption to show STY so I know
   229     # which screen.
   230     screen -X caption always  "$STY %= %-w%L>%{= BW}%n*%t%{-}%52<%+w %L="
   231     export HISTFILE=~/.bash_history.d/`_screen_name`.$WINDOW
   232 fi
   233 
   234 [[ -n "$(command -v stty)" ]] && stty -ixoff -ixon