SHARE
TWEET

Zain

a guest Aug 16th, 2009 601 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #### PS1 customization ####
  3. NONE="\[\033[0m\]"    # unsets color to term fg color
  4.  
  5. # regular colors
  6. K="\[\033[0;30m\]"    # black
  7. R="\[\033[0;31m\]"    # red
  8. G="\[\033[0;32m\]"    # green
  9. Y="\[\033[0;33m\]"    # yellow
  10. B="\[\033[0;34m\]"    # blue
  11. M="\[\033[0;35m\]"    # magenta
  12. C="\[\033[0;36m\]"    # cyan
  13. W="\[\033[0;37m\]"    # white
  14.  
  15. # emphasized (bolded) colors
  16. EMK="\[\033[1;30m\]"
  17. EMR="\[\033[1;31m\]"
  18. EMG="\[\033[1;32m\]"
  19. EMY="\[\033[1;33m\]"
  20. EMB="\[\033[1;34m\]"
  21. EMM="\[\033[1;35m\]"
  22. EMC="\[\033[1;36m\]"
  23. EMW="\[\033[1;37m\]"
  24.  
  25. # background colors
  26. BGK="\[\033[40m\]"
  27. BGR="\[\033[41m\]"
  28. BGG="\[\033[42m\]"
  29. BGY="\[\033[43m\]"
  30. BGB="\[\033[44m\]"
  31. BGM="\[\033[45m\]"
  32. BGC="\[\033[46m\]"
  33. BGW="\[\033[47m\]"
  34.  
  35.  
  36. # displays only the last 25 characters of pwd
  37. set_new_pwd() {
  38.     # How many characters of the $PWD should be kept
  39.     local pwdmaxlen=25
  40.     # Indicate that there has been dir truncation
  41.     local trunc_symbol=".."
  42.     local dir=${PWD##*/}
  43.     pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
  44.     NEW_PWD=${PWD/#$HOME/\~}
  45.     local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
  46.     if [ ${pwdoffset} -gt "0" ]
  47.     then
  48.         NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
  49.         NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
  50.     fi
  51. }
  52.  
  53. # the name of the git branch in the current directory
  54. set_git_branch() {
  55.     unset GIT_BRANCH
  56.     local branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1 /'`;
  57.    
  58.     if test $branch
  59.         then
  60.             GIT_BRANCH="${EMG}git:${NONE}$branch"
  61.     fi
  62. }
  63.  
  64. # revision of the svn repo in the current directory
  65. set_svn_rev() {
  66.     unset SVN_REV
  67.     local rev=`svn info 2> /dev/null | grep "Revision" | sed 's/Revision: \(.*\)/r\1 /'`;
  68.    
  69.     if test $rev
  70.         then
  71.             SVN_REV="${EMG}svn:${NONE}$rev"
  72.     fi
  73. }
  74.  
  75. # the name of the activated virtual env
  76. set_virtual_env_base() {
  77.     unset VIRTUAL_ENV_BASE
  78.     local venv=`basename "$VIRTUAL_ENV"`
  79.    
  80.     if test $venv
  81.         then
  82.             VIRTUAL_ENV_BASE="${EMG}env:${NONE}$venv "
  83.     fi
  84. }
  85.  
  86. update_prompt() {
  87.     set_new_pwd
  88.     set_git_branch
  89.     set_svn_rev
  90.     set_virtual_env_base
  91.    
  92.     PS1="${EMB}[${NONE}${NEW_PWD}${EMB}] ${GIT_BRANCH}${SVN_REV}${VIRTUAL_ENV_BASE}${B}\$ ${NONE}"
  93. }
  94.  
  95. PROMPT_COMMAND=update_prompt
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top