gpt4 book ai didi

linux - 如何更改 Ubuntu 提示符

转载 作者:太空宇宙 更新时间:2023-11-04 05:47:31 26 4
gpt4 key购买 nike

您好,我正在使用 Xubuntu,我想更改提示符。

如果我处于类似这样的长路径中,我的实际提示会很长:

文档/SubFolder_1/SubFolder_2/SubFolder_x/

它看起来像

my_name@CMGBiotools-VirtualBox :~ Document/SubFolder_1/subFolder_2/SubFolder_x/$

所以我只想要 my_name 和最后一个文件夹,例如:

my_name: SubFolder_x$

如果我在终端中输入 echo $PS1,则会出现以下内容:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

.bashrc 看起来像:

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

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 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

我必须修改哪一行??

非常感谢!!!

最佳答案

将其放入您的.bashrc

PS1="[\u: \W]\$ "
export PS1

有一大堆内容可供阅读Prompt Statement variables

关于linux - 如何更改 Ubuntu 提示符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52867343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com