home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / redakcyjne / openSuSE / openSUSE-11.2-KDE4-LiveCD-i686.iso / boot / i386 / loader / initrd / initrd~ / etc / bash.bashrc next >
Text File  |  2009-11-02  |  9KB  |  365 lines

  1. # /etc/bash.bashrc for SuSE Linux
  2. #
  3. # PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes
  4. # will be lost during system upgrades.  Instead use /etc/bash.bashrc.local
  5. # for your local settings, favourite global aliases, VISUAL and EDITOR
  6. # variables, etc ...
  7.  
  8. #
  9. # Check which shell is reading this file
  10. #
  11. if test -z "$is" ; then
  12.  if test -f /proc/mounts ; then
  13.   case "`/bin/ls --color=never -l /proc/$$/exe`" in
  14.     */bash)    is=bash
  15.     read -t 1 a r </proc/$$/cmdline
  16.     case "$a" in
  17.     sh|-sh|*/sh)
  18.         is=sh    ;;
  19.     esac            ;;
  20.     */ash)    is=ash  ;;
  21.     */ksh)    is=ksh  ;;
  22.     */pdksh)    is=ksh  ;;
  23.     */zsh)    is=zsh  ;;
  24.     */*)    is=sh   ;;
  25.   esac
  26.   #
  27.   # `r' in $- occurs *after* system files are parsed
  28.   #
  29.   for a in $SHELL ; do
  30.     case "$a" in
  31.       */r*sh)
  32.         readonly restricted=true ;;
  33.       -r*|-[!-]r*|-[!-][!-]r*)
  34.         readonly restricted=true ;;
  35.       --restricted)
  36.         readonly restricted=true ;;
  37.     esac
  38.   done
  39.   unset a r
  40.  else
  41.   is=sh
  42.  fi
  43. fi
  44.  
  45. #
  46. # Call common progams from /bin or /usr/bin only
  47. #
  48. path ()
  49. {
  50.     if test -x /usr/bin/$1 ; then
  51.     ${1+"/usr/bin/$@"}
  52.     elif test -x   /bin/$1 ; then
  53.     ${1+"/bin/$@"}
  54.     fi
  55. }
  56.  
  57.  
  58. #
  59. # ksh/ash sometimes do not know
  60. #
  61. test -z "$UID"  && readonly  UID=`path id -ur 2> /dev/null`
  62. test -z "$EUID" && readonly EUID=`path id -u  2> /dev/null`
  63.  
  64. #
  65. # Colored file listings
  66. #
  67. if test -x /usr/bin/dircolors ; then
  68.     #
  69.     # set up the color-ls environment variables:
  70.     #
  71.     if test -f $HOME/.dir_colors ; then
  72.     eval "`/usr/bin/dircolors -b $HOME/.dir_colors`"
  73.     elif test -f /etc/DIR_COLORS ; then
  74.     eval "`/usr/bin/dircolors -b /etc/DIR_COLORS`"
  75.     fi
  76. fi
  77.  
  78. #
  79. # ls color option depends on the terminal
  80. # If LS_COLORS is set but empty, the terminal has no colors.
  81. #
  82. if test "${LS_COLORS+empty}" = "${LS_COLORS:+empty}" ; then
  83.     LS_OPTIONS=--color=tty
  84. else
  85.     LS_OPTIONS=--color=none
  86. fi
  87. if test "$UID" = 0 ; then
  88.     LS_OPTIONS="-A -N $LS_OPTIONS -T 0"
  89. else
  90.     LS_OPTIONS="-N $LS_OPTIONS -T 0"
  91. fi
  92.  
  93. #
  94. # Avoid trouble with Emacs shell mode
  95. #
  96. if test "$EMACS" = "t" ; then
  97.     LS_OPTIONS='-N --color=none -T 0';
  98.     path tset -I -Q
  99.     path stty cooked pass8 dec nl -echo
  100. fi
  101. export LS_OPTIONS
  102.  
  103. #
  104. # Set prompt and aliases to something useful for an interactive shell
  105. #
  106. case "$-" in
  107. *i*)
  108.     #
  109.     # Some useful functions
  110.     #
  111.     if test -z "$restricted" ; then
  112.     startx  () {
  113.         test -x /usr/bin/startx || {
  114.         echo "No startx installed" 1>&2
  115.         return 1;
  116.         }
  117.         /usr/bin/startx ${1+"$@"} 2>&1 | tee $HOME/.xsession-errors
  118.     }
  119.     remount () { /bin/mount -o remount,${1+"$@"} ; }
  120.     fi
  121.  
  122.     #
  123.     # Set prompt to something useful
  124.     #
  125.     case "$is" in
  126.     bash)
  127.     # Append history list instead of override
  128.     shopt -s histappend
  129.     # Force a reset of the readline library
  130.     unset TERMCAP
  131.     # Returns short path (last two directories)
  132.     spwd () {
  133.       ( IFS=/
  134.         set $PWD
  135.         if test $# -le 3 ; then
  136.         echo "$PWD"
  137.         else
  138.         eval echo \"..\${$(($#-1))}/\${$#}\"
  139.         fi ) ; }
  140.     # Set xterm prompt with short path (last 18 characters)
  141.     ppwd () {
  142.         local _t="$1" _w _x _u="$USER" _h="$HOST"
  143.         test -n "$_t"    || return
  144.         test "${_t#tty}" = $_t && _t=pts/$_t
  145.         test -O /dev/$_t || return
  146.         _w="$(dirs +0)"
  147.         _x=$((${#_w}-18))
  148.         test ${#_w} -le 18 || _w="...${_w#$(printf "%.*s" $_x "$_w")}"
  149.         printf "\e]2;%s@%s:%s\007\e]1;%s\007" "$_u" "$_h" "$_w" "$_h" > /dev/$_t
  150.         }
  151.     # If set: do not follow sym links
  152.     # set -P
  153.     #
  154.     # Other prompting for root
  155.     _t=""
  156.     if test "$UID" -eq 0  ; then
  157.         _u="\h"
  158.         _p=" #"
  159.     else
  160.         _u="\u@\h"
  161.         _p=">"
  162.         if test \( "$TERM" = "xterm" -o "${TERM#screen}" != "$TERM" \) \
  163.             -a -z "$EMACS" -a -z "$MC_SID" -a -n "$DISPLAY"
  164.         then
  165.         _t="\$(ppwd \l)"
  166.         fi
  167.         if test -n "$restricted" ; then
  168.         _t=""
  169.         fi
  170.     fi
  171.     case "$(declare -p PS1 2> /dev/null)" in
  172.     *-x*PS1=*)
  173.         ;;
  174.     *)
  175.         # With full path on prompt
  176.         PS1="${_t}${_u}:\w${_p} "
  177. #        # With short path on prompt
  178. #        PS1="${_t}${_u}:\$(spwd)${_p} "
  179. #        # With physical path even if reached over sym link
  180. #        PS1="${_t}${_u}:\$(pwd -P)${_p} "
  181.         ;;
  182.     esac
  183.     # Colored root prompt (see bugzilla #144620)
  184.     if test "$UID" -eq 0 -a -t ; then
  185.         _bred="$(path tput bold 2> /dev/null; path tput setaf 1 2> /dev/null)"
  186.         _sgr0="$(path tput sgr0 2> /dev/null)"
  187.         PS1="\[$_bred\]$PS1\[$_sgr0\]"
  188.         unset _bred _sgr0
  189.     fi
  190.     unset _u _p _t
  191.     ;;
  192.     ash)
  193.     cd () {
  194.         local ret
  195.         command cd "$@"
  196.         ret=$?
  197.         PWD=$(pwd)
  198.         if test "$UID" = 0 ; then
  199.         PS1="${HOST}:${PWD} # "
  200.         else
  201.         PS1="${USER}@${HOST}:${PWD}> "
  202.         fi
  203.         return $ret
  204.     }
  205.     cd .
  206.     ;;
  207.     ksh)
  208.     # Some users of the ksh are not common with the usage of PS1.
  209.     # This variable should not be exported, because normally only
  210.     # interactive shells set this variable by default to ``$ ''.
  211.     if test "${PS1-\$ }" = '$ ' ; then
  212.         if test "$UID" = 0 ; then
  213.         PS1="${HOST}:"'${PWD}'" # "
  214.         else
  215.         PS1="${USER}@${HOST}:"'${PWD}'"> "
  216.         fi
  217.     fi
  218.     ;;
  219.     zsh)
  220. #    setopt chaselinks
  221.     if test "$UID" = 0; then
  222.         PS1='%n@%m:%~ # '
  223.     else
  224.         PS1='%n@%m:%~> '
  225.     fi
  226.     ;;
  227.     *)
  228. #    PS1='\u:\w> '
  229.     PS1='\h:\w> '
  230.     ;;
  231.     esac
  232.     PS2='> '
  233.  
  234.     if test "$is" = "ash" ; then
  235.     # The ash shell does not have an alias builtin in
  236.     # therefore we use functions here. This is a seperate
  237.     # file because other shells may run into trouble
  238.     # if they parse this even if they do not expand.
  239.     test -s /etc/profile.d/alias.ash && . /etc/profile.d/alias.ash
  240.     else
  241.     unalias ls 2>/dev/null
  242.         case "$is" in
  243.     bash) alias ls='ls $LS_OPTIONS'        ;;
  244.     zsh)  alias ls='\ls $=LS_OPTIONS'    ;;
  245.     *)    alias ls='/bin/ls $LS_OPTIONS'    ;;
  246.     esac
  247.     alias dir='ls -l'
  248.     alias ll='ls -l'
  249.     alias la='ls -la'
  250.     alias l='ls -alF'
  251.     alias ls-l='ls -l'
  252.  
  253.     #
  254.     # Set some generic aliases
  255.     #
  256.     alias o='less'
  257.     alias ..='cd ..'
  258.     alias ...='cd ../..'
  259.     alias cd..='cd ..'
  260.     if test "$is" != "ksh" ; then
  261.         alias -- +='pushd .'
  262.         alias -- -='popd'
  263.     fi
  264.     alias rd=rmdir
  265.     alias md='mkdir -p'
  266.     if test "$is" = "bash" -a ! -x /bin/which -a ! -x /usr/bin/which ; then
  267.         #
  268.         # Other shells use the which command in path (e.g. ash) or
  269.         # their own builtin for the which command (e.g. ksh and zsh).
  270.         #
  271.         _which () {
  272.         local file=$(type -p ${1+"$@"} 2>/dev/null)
  273.         if test -n "$file" -a -x "$file"; then
  274.             echo "$file"
  275.             return 0
  276.         fi
  277.         hash -r
  278.         type -P ${1+"$@"}
  279.         }
  280.         alias which=_which
  281.     fi
  282.     alias rehash='hash -r'
  283.     alias you='if test "$EUID" = 0 ; then /sbin/yast2 online_update ; else su - -c "/sbin/yast2 online_update" ; fi'
  284.     if test "$is" != "ksh" ; then
  285.         alias beep='echo -en "\007"' 
  286.     else
  287.         alias beep='echo -en "\x07"'
  288.     fi
  289.     alias unmount='echo "Error: Try the command: umount" 1>&2; false'
  290.     test -s $HOME/.alias && . $HOME/.alias
  291.     fi
  292.  
  293.     #
  294.     # Expert mode: if we find $HOME/.bash.expert we skip our settings
  295.     # used for interactive completion and read in the expert file.
  296.     #
  297.     if test "$is" = "bash" -a -r $HOME/.bash.expert ; then
  298.     . $HOME/.bash.expert
  299.     elif test "$is" = "bash" ; then
  300.     # Complete builtin of the bash 2.0 and higher
  301.     case "$BASH_VERSION" in
  302.     [2-9].*)
  303.         if test -e $HOME/.bash_completion ; then
  304.         . $HOME/.bash_completion
  305.         elif test -e /etc/bash_completion ; then
  306.         . /etc/bash_completion
  307.         elif test -s /etc/profile.d/complete.bash ; then
  308.         . /etc/profile.d/complete.bash
  309.         fi
  310.         for s in /etc/bash_completion.d/*.sh ; do
  311.         test -r $s && . $s
  312.         done
  313.         if test -f /etc/bash_command_not_found ; then
  314.         . /etc/bash_command_not_found
  315.         fi
  316.         ;;
  317.     *)  ;;
  318.     esac
  319.     fi
  320.  
  321.     # Do not save dupes and lines starting by space in the bash history file
  322.     HISTCONTROL=ignoreboth
  323.     if test "$is" = "ksh" ; then
  324.     # Use a ksh specific history file and enable
  325.         # emacs line editor
  326.         : ${HISTFILE=$HOME/.kshrc_history}
  327.         : ${VISUAL=emacs}
  328.     case $(set -o) in
  329.     *multiline*) set -o multiline
  330.     esac
  331.     fi
  332.     # command not found handler in zsh version
  333.     if test "$is" = "zsh" ; then
  334.     if test -f /etc/zsh_command_not_found ; then
  335.         . /etc/zsh_command_not_found
  336.     fi
  337.     fi
  338.     ;;
  339. esac
  340.  
  341. #
  342. # Just in case the user excutes a command with ssh
  343. #
  344. if test -n "$SSH_CONNECTION" -a -z "$PROFILEREAD" ; then
  345.     _SOURCED_FOR_SSH=true
  346.     . /etc/profile > /dev/null 2>&1
  347.     unset _SOURCED_FOR_SSH
  348. fi
  349.  
  350. if test "$is" != "ash" ; then
  351.     #
  352.     # And now let's see if there is a local bash.bashrc
  353.     # (for options defined by your sysadmin, not SuSE Linux)
  354.     #
  355.     test -s /etc/bash.bashrc.local && . /etc/bash.bashrc.local
  356. fi
  357.  
  358. if test -n "$restricted" -a -z "$PROFILEREAD" ; then
  359.     PATH=/usr/lib/restricted/bin
  360.     export PATH
  361. fi
  362. #
  363. # End of /etc/bash.bashrc
  364. #
  365.