ubuntu20.04LTS终端没有颜色——给黑底白字的终端染色

相关的几个文件,或许更多

vim /etc/bash.bashrc
vim /etc/profile
vim ~/.bashrc
vim ~/.bash_profile

终端颜色由 PS1 变量进行定义,上面这些文件中就有 PS1 变量。
1.去掉 ~/.bashrc 中的 force_color_prompt=yes 注释,保存后并 source ~/.bashrc 之后如果终端颜色已经上色,这就达到目的了。
2.终端执行 export TERM=xterm-256color 开启256真彩色试试结果,如果有效,把这行代码追加到 ~/.bashrc 或者 /etc/profile 文件的末行。
3.试试下面的命令,其实就是开启 force_color_prompt=yes

cp /etc/bash.bashrc /etc/bash.bashrc.bak
cat << EOF >> /etc/bash.bashrc
# 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
EOF
暂无评论

发送评论 编辑评论


				
上一篇
下一篇