Chinaunix首页 | 论坛 | 博客
  • 博客访问: 566366
  • 博文数量: 89
  • 博客积分: 2383
  • 博客等级: 大尉
  • 技术积分: 970
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 23:02
个人简介

Scientific Linux是重新编译的Red Hat Enterprise Linux,由费米国家加速器实验室、欧洲核研究组织以及世界各地的大学和实验室共同开发。它旨在与Red Hat Enterprise Linux完全兼容,也强调自主方便的定制,用户可以根据自己的需求做相应修改,可以使用脚本或者Anaconda给自己定制最小化的安装模式。

文章分类

全部博文(89)

文章存档

2017年(1)

2016年(2)

2013年(2)

2012年(2)

2011年(16)

2010年(13)

2009年(46)

2008年(7)

我的朋友

分类: LINUX

2009-07-21 10:03:53

Changing your own bash shell prompt

(用不同的颜色显示不同的用户,我喜欢超级用户是红色的,并且将当前路径全部显示。)

To change the colour of the BASH shell prompt for yourself only, you can edit your ~/.bashrc file by adding the following to the end:

if [ $TERM = 'xterm' ]
then
        PS1='\[\033[02;32m\]\u@\h\[\033[02;34m\] \w \$\[\033[00m\] '
else
        PS1='\u@\h \w \$ '
fi

Changing the root bash shell prompt

This is the same principle as the above, but log in as root first and add the following to the end of root's ~/.bashrc:

if [ $TERM = 'xterm' ]
then
        PS1='\[\033[01;31m\]\u@\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
        PS1='\u@\h \w \$ '
fi

Changing the default setting for new users

If you want to make this change apply to all existing users (unless otherwise overridden by their local ~/.bashrc file) you need to edit the /etc/bashrc file. The particular section you need to edit looks like this:

if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

After some playing around with it, I couldn't work out how to modify the PROMPT_COMMAND value correctly, but adding in the PS1 setting directly underneath it did the trick:

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
PS1='\[\033[02;32m\]\u@\h\[\033[02;34m\] \w \$\[\033[00m\] '
 
 

 

阅读(2059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~