Ubuntu设置PS1属性达到SHELL提示符…

来源:互联网 发布:微信数据移动到sd卡 编辑:程序博客网 时间:2024/06/03 16:38

默认情况下,Ubuntu终端会输出完整路径,在路径名很长的时候,提示方式很不友好,通过以下步骤修改PS1变量的设置,可以让终端输出短路径。

修改用户目录下的.bashrc文件

2011年 04月 06日 星期三 15:50:48 CST
kay@Vostro-PC:~$ vi .bashrc 

找到如下代码:

if [ "$color_prompt" = yes ]; then
   PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$' # Modify1 w->W
else
   PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$' #Modify2
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1" #Modify3
    ;;
*)
    ;;
esac

以上内容全部修改完成之后,执行:

source .bashrc

就能看到修改之后的效果了。
修改之前为
kay@Vostro-PC:/etc/vim$
修改之后为
kay@Vostro-PC:vim$
相对于直接使用export PS1=”"的方式,此种修改方法保留了终端标题栏显示完整路径的功能。

如果想要终端颜色丰富一些,我们可以开启~/.bashrc中的force_color_prompt=yes参数,这样终端会用颜色来区分各种不同的项目,提高可阅读性

 
原创粉丝点击