Advertisement
Guest User

OsoGato

a guest
Sep 4th, 2009
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.66 KB | None | 0 0
  1. [ -z "$PS1" ] && return
  2.  
  3. umask 0022
  4.  
  5. # completion
  6. if [ -f "$HOME/.bash_completion" -a ! "${BASH_COMPLETION+set}" ]; then
  7.     . "$HOME/.bash_completion"
  8. fi
  9.  
  10. # remap console keys
  11. if [ -z "$DISPLAY" -a -f "$HOME/.loadkeys" ]; then
  12.     loadkeys "$HOME/.loadkeys" >/dev/null
  13. fi
  14.  
  15. ## prompt {{{
  16. if [ "$TERM" = "linux" ]
  17. then
  18.     # (system console) long prompt
  19.     PS1="\u@\h[\#]\W\$ "
  20. else
  21.     # (xterm etc.) short, color prompt if possible
  22.     if [ -x /bin/tput -o -x /usr/bin/tput ] && tput setaf 1 &>/dev/null; then
  23.         if type __git_ps1 &>/dev/null; then
  24.             GIT_PS1='\[\e['30';1m\]$(__git_ps1 "·%s")\[\e[0m\]'
  25.         else
  26.             GIT_PS1=
  27.         fi
  28.     PS1='$(if [ $? -eq 0 ]
  29.            then echo "\[\e['30';1m\]·\[\e[0m\]"
  30.            else echo "\[\e['31';1m\]·\[\e[0m\]"
  31.        fi)\[\e['33';1m\]$(promptwd "\w")\[\e[0m\]'"$GIT_PS1"'\$ '
  32.         unset GIT_PS1
  33.     else
  34.     PS1='[\#]\W\$ '
  35.     fi
  36.     # disable XON/XOFF
  37.     stty -ixon
  38. fi
  39. # set variable identifying the chroot you work in
  40. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  41.     debian_chroot=$(cat /etc/debian_chroot)
  42. fi
  43. PS1="${debian_chroot:+($debian_chroot)}$PS1"
  44.  
  45. PS1 ()
  46. {
  47.     if [[ "$PS1" =~ promptwd ]]; then
  48.         PS1=$(echo "$PS1" | awk '{ sub(/\$\(promptwd "\\w"\)/, "\\W"); print }')
  49.     else
  50.         PS1=$(echo "$PS1" | awk '{ sub(/\\W/, "$(promptwd \"\\w\")"); print }')
  51.     fi
  52. }
  53. #promptwd ()
  54. #{
  55. #   local top=$(echo "$1" | sed "s#\([^/]*/\)\(.*\)\(/[^/]\+/[^/]\+\)#\2#")
  56. #   if [ "$top" = "$1" ]; then
  57. #       echo "$1"
  58. #   elif [ ${#top} -gt 5 ]; then
  59. #       top="${top:0:3}"
  60. #       top="${top%%/*}.."
  61. #       echo "$1" | sed "s#\([^/]*/\)\(.*\)\(/[^/]\+/[^/]\+\)#\1$top\3#"
  62. #   else
  63. #       echo "$1"
  64. #   fi
  65. #}
  66.  
  67. # title bar
  68. case "$TERM" in
  69. xterm*|*rxvt*)
  70.     PROMPT_COMMAND='history -a; echo -ne "\033]0;$USER@$HOSTNAME:${PWD/$HOME/~}\007"'
  71.     ;;
  72. esac
  73. ## }}}
  74.  
  75. ## options and variables {{{
  76. shopt -s no_empty_cmd_completion
  77. shopt -s checkwinsize   # if necessary, update LINES/COLUMNS after each command
  78. shopt -s cmdhist        # multi-line histories
  79. shopt -s dotglob        # include hidden files in pathname expansions
  80. shopt -s extglob        # extended pattern matching
  81. shopt -s histappend     # append to history file rather than overwrite
  82. shopt -s nocaseglob     # case-insensitive matching
  83. # use embedded newlines instead of ; for multi-line commands
  84. # shopt -s lithist
  85.  
  86. # avoid cluttering bash dotfiles
  87. HISTFILE=$HOME/.commandline_history
  88. # max number of lines in history file
  89. HISTFILESIZE=10000
  90. # max number of commands
  91. HISTSIZE=10000
  92.  
  93. # commands to exclude from history
  94. HISTIGNORE="l[saltScoh]:cls:c[dl]:mcl *:j:bd:..*(.):popd:pp:dirs:[bf]g:pwd:?:hist?(op):clear:reset:exit"
  95.  
  96. # exclude duplicate commands and command lines starting with space
  97. HISTCONTROL=ignoreboth
  98.  
  99. # time builtin format
  100. TIMEFORMAT=$'\n%2lR\t%P%%'
  101.  
  102. # allow scripts access to window dimensions
  103. export LINES
  104. export COLUMNS
  105.  
  106. # pager
  107. export PAGER=less
  108. export LESS=-Mi
  109. export LESS_TERMCAP_mb=$'\e[01;31m'     # blinking
  110. export LESS_TERMCAP_md=$'\e[01;94m'     # begin bold
  111. export LESS_TERMCAP_so=$'\e[01;90;103m' # begin stand-out mode (search highlighting)
  112. export LESS_TERMCAP_us=$'\e[01;36m'     # begin underline
  113. export LESS_TERMCAP_me=$'\e[0m'         # end mode
  114. export LESS_TERMCAP_se=$'\e[0m'         # end stand-out mode
  115. export LESS_TERMCAP_ue=$'\e[0m'         # end underline
  116.  
  117. # text editors
  118. export EDITOR='vim'
  119. export VISUAL='scim-run gvim'
  120. export GIT_EDITOR='vim'
  121.  
  122. # python
  123. export PYTHONPATH="$HOME/code/py/modules"
  124. if [ -f "$HOME/.pythonrc" ]; then
  125.     export PYTHONSTARTUP="$HOME/.pythonrc"
  126. fi
  127. ## }}}
  128.  
  129. ## user bin directory {{{
  130. BIN="$HOME/bin"
  131.  
  132. lnbin ()
  133. {
  134.     if [ ! -d "$BIN" ] || ! type abspath &>/dev/null; then
  135.         return 1
  136.     fi
  137.     local IFS=$'\n'
  138.     local code=1 arg file
  139.     for arg in "$@"; do
  140.         for file in $(find "$arg" -maxdepth 1)
  141.         do
  142.             if [ -f "$file" -a -x "$file" ]; then
  143.                 ln -fs "$(abspath "$file")" "$BIN"
  144.                 code=0
  145.             fi
  146.         done
  147.     done
  148.     return $code
  149. }
  150. ## }}}
  151.  
  152. # PATH
  153. addpath ()
  154. {
  155.     [ $# -ne 1 ] && return 2
  156.     if ! echo "$PATH" | grep '\(:\|^\)'"$1"'\(:\|$\)' >/dev/null
  157.     then PATH="$PATH:$1"
  158.     else return 1
  159.     fi
  160. }
  161.  
  162. # bootstrap other scripts
  163. addsource ()
  164. {
  165.     [ $# -eq 0 ] && return 2
  166.     local -i code=0
  167.     local arg
  168.     for arg in "$@"; do
  169.         if [ -f "$arg" ]
  170.         then . "$arg"
  171.         else false
  172.         fi
  173.         code+=$?
  174.     done
  175.     return $code
  176. }
  177. addsource "$HOME/.bash_aliases"
  178. addsource "$HOME/.bash_hacks"
  179. addpath "."
  180.  
  181. # done
  182. true
  183.  
  184. # vim:set ts=4 sw=4 noet fdm=marker:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement