文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>改变我的BASH显示(prompt)

改变我的BASH显示(prompt)

时间:2009-07-21  来源:zeuls

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\] '
 
 

 

相关阅读 更多 +
排行榜 更多 +
浴血混战官方下载

浴血混战官方下载

飞行射击 下载
检票员模拟器免广告下载

检票员模拟器免广告下载

模拟经营 下载
最终前哨最终版手机版下载

最终前哨最终版手机版下载

休闲益智 下载