缩短终端前面的“$”提示符

由于变量PS1控制着提示符,所以我们将对其进行修改。

改动之前

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
Username@PCname:~/Documents/dir1/dir2$ 

不显示用户名。

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}@\h:\w\$ '
fi

编辑后, 在终端中输入 source ~/.bashrc 或重新启动终端。

@PCname:~/Documents/dir1/dir2$ 

不要显示电脑名称。

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@:\w\$ '
fi

在编辑后,请执行 “source ~/.bashrc” 或重新启动终端。

Username@:~/Documents/dir1/dir2$ 

不显示当前目录

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\$ '
fi

编辑后,输入 source ~/.bashrc 或者重启终端。

Username@PCname:$ 

不显示全部

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\$ '
fi

在编辑后,执行 source ~/.bashrc 或重新启动终端。

$ 

请参考

    • https://qiita.com/fugee/items/8ccd0439cf197cfce0aa

 

    https://qiita.com/watertight/items/84568d0b6ef77e00dac0