海运的博客

Linux SSH终端terminal配色更改为256色

发布时间:December 15, 2012 // 分类:Xshell // No Comments

一般使用Xshell通过SSH连接管理Centos/Debina服务器终端为8色,通过设置终端类型可开启256色彩以显示更加鲜艳的色彩。
查看当前终端类型:

echo $TERM 
xterm-color

查看当前服务器终端色彩:

tput colors
8

或使用以下脚本检测并以色彩方式:

#!/usr/bin/env python
#检测当前终端支持色彩
import sys
import os

def echo(msg):
    os.system('echo -n "' + str(msg) + '"')

def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")

# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)

echo("\n")
echo("\n")

y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1

    echo("\n")

echo("\n")

for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")

echo("\n")

配置Linux终端如果支持就调整为256色终端,添加到.bashrc文件内。

if [ -e /usr/share/terminfo/x/xterm-256color ]; then
#debian在/lib/terminfo/x/xterm-256color
        export TERM='xterm-256color'
else
        export TERM='xterm-color'
fi

如不支持xterm-256color安装:

apt-get install ncurses-base
yum install ncurses

扩展阅读:
Colour colour everywhere! 256 colour-mode for Linux consoles:http://www.robmeerman.co.uk/unix/256colours
256 colors in vim:http://vim.wikia.com/wiki/256_colors_in_vim

标签:shell, bash, linux服务器终端开启256色, linux检查终端配色, terminal

评论已关闭

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...