我的个人博客:https://lixiaohui.live
问题:
使用Xshell终端远程云服务器,发现Xshell终端主机名和用户名不显示颜色,命令行数据一多就找不到终端主机名和用户名了,看起来很不方便,对眼睛不友好。
解决:
windows下解决
-
打开xshell当前会话属性或者默认会话属性(如下图)
-
修改外观中的突出显示,利用正则表达式选中username@hostname从而修改其颜色(见下方操作)。
- 正则表达式:由于
username@hostname
在[]
中,在我的电脑上是[hdp@hadoop-server mapreduce],所以直接使用了\[.*\]
的正则
linux下解决
- 修改用户目录下的
.bashrc
文件,每个用户家目录下的对应文件都需要修改(修改一个只对应一个用户的,其他用户的不会变),vim .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
2.执行source .bashrc
使修改生效