xshell中修改主機名和用戶名顏色

我的個人博客:https://lixiaohui.live

問題:

使用Xshell終端遠(yuǎn)程云服務(wù)器,發(fā)現(xiàn)Xshell終端主機名和用戶名不顯示顏色,命令行數(shù)據(jù)一多就找不到終端主機名和用戶名了,看起來很不方便,對眼睛不友好。

解決:

windows下解決

  1. 打開xshell當(dāng)前會話屬性或者默認(rèn)會話屬性(如下圖)


  2. 修改外觀中的突出顯示,利用正則表達式選中username@hostname從而修改其顏色(見下方操作)。


  • 正則表達式:由于username@hostname[]中,在我的電腦上是[hdp@hadoop-server mapreduce],所以直接使用了\[.*\]的正則

linux下解決

  1. 修改用戶目錄下的.bashrc文件,每個用戶家目錄下的對應(yīng)文件都需要修改(修改一個只對應(yīng)一個用戶的,其他用戶的不會變),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中原來的內(nèi)容,下面是新加的(Ubuntu中有下面的內(nèi)容,去掉一行注釋就行,具體我也不知道啥道理,只是試了可以用)


# 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.執(zhí)行source .bashrc使修改生效

結(jié)果:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容