0
点赞
收藏
分享

微信扫一扫

Xshell中主机名和用户名的颜色的设置

肉肉七七 2022-03-30 阅读 72
大数据

原文地址https://www.dyxmq.cn/linux/xshell-color-prompt.html
设置前显示如下
在这里插入图片描述
设置后显示
在这里插入图片描述

修改用户目录下的.bashrc文件,每个用户家目录下的对应文件都需要修改(修改一个只对应一个用户的,其他用户的不会变),vi .bashrc然后做如下修改

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
#上面是centos中原来的内容,下面是新加的(Ubuntu中有下面的内容,去掉一行注释就行,具体我也不知道啥道理,只是试了可以用)


# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) 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   #Ubuntu中只需要将这行的注释去掉就行
 
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

修改完之后,颜色就会改变啦!

举报

相关推荐

0 条评论