【问题】
Ubuntu下,默认情况下,对于终端,是显示出绝对的路径的,比如:
现在想要让其只显示相对路径。
【解决过程】
1.参考:
去将.bashrc中的,有关PS1的部分,从:
| if [ “$color_prompt” = yes ]; then # If this is an xterm set the title to user@host:dir | 
改为:
| if [ “$color_prompt” = yes ]; then # If this is an xterm set the title to user@host:dir | 
2.保存修改,退出gedit。然后再source一下,发现终端的标题变成当前路径了:
3.再重启终端,看看是否生效,结果还是不行。
4.再去把上面那个PS1中的值,变成:
| if [ “$color_prompt” = yes ]; then # If this is an xterm set the title to user@host:dir | 
然后保存退出gedit,再source一下,结果就可以了:
crifan@ubuntu:~/develop/crosstool-ng/crosstool-ng-1.18.0_build$ gedit ~/.bashrc crifan@ubuntu:~/develop/crosstool-ng/crosstool-ng-1.18.0_build$ source ~/.bashrccrifan@ubuntu:crosstool-ng-1.18.0_build$
效果如下:
【总结】
想要将Ubuntu的终端,中的绝对路径的显示,变成当前路径(文件夹)的话,则需要去修改自己的.bashrc,将其中的小写的w,改为大写的W即可:
(1)针对终端的标题title
从:
# 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"
    ;;
*)
    ;;
esac改为:
# 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"
    ;;
*)
    ;;
esac
(2)针对终端的当前显示prompt
从:
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt改为:
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
fi
unset color_prompt force_color_prompt转载请注明:在路上 » 【已解决】Ubuntu中让终端只显示当前路径,而不显示绝对路径



