http://evadeflow.com/2010/06/sane-terminal-colors/

Sane Terminal Colors

June 26, 2010

I recently created a new Ubuntu VM and once again found myself not liking the default terminal colors when I aliased ‘ls’ to ‘ls –color=auto’. I must’ve looked up how to customize this a dozen times, and done it slightly differently each time.  Here, for reference, is what I did this time.

  1. Add these lines to my .zshrc:

    eval $(dircolors -b ~/.dircolors)
    alias ls='ls -hF --color=auto'
  2. Run this command:  dircolors -p  > ~/.dircolors
  3. Modify ~/.dircolors to emit the colors I want it to
  4. Modify the gnome-terminal profile colors so they don’t look so garish

The trick is understanding that these colors (from ~/.dircolors):

# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white

and their bold variants map directly to the colors shown in gnome-terminal’s Colors dialog: So, if the thing called out as ‘green’ in your dircolors config is too DayGlo for you, just use the above dialog to select a darker color for the GREEN ‘slot’.  Or even a completely different color. (The color doesn’t have to match the name; you could modify the MAGENTA slot to be dark blue, for example.)

The colors in the bottom row of the palette represent the colors you’ll see when the bold attribute is enabled. By using these eight base colors, plus their bold variants, you can have up to sixteen custom colors in your scheme. (Again, the bold variants don’t have to match the base color, i.e., BOLD + RED could actually be bright orange if you want.)

Before tweaking dircolors, when I set my terminal background to a beige-ish color, ‘ls --color=auto’ produced this awful mess: Here’s what I wound up with after some minor tweaking:For my money, this is a lot subtler and easier on the eyes. And it’s readable, which seems like a good minimum standard. :-}

The only thing you have to look out for with this setup is that logging in remotely via ssh may cause you to see some funky colors, depending on the type of your remote terminal.  You can mitigate this by tweaking your dircolors config so it looks reasonable when logged in remotely, then re-jiggering your gnome-terminal colors to taste. This is where having the ability to use completely different colors in gnome-terminal can help: use something that’s at least legible in a standard xterm, and then map those settings—whatever they are—so they look good in gnome-terminal.

Another option is to make the display of colors conditional on whether SSH_CLIENT is defined:

  if [ -z $SSH_CLIENT ]; then
alias ls='ls -hF --color=auto'
else
alias ls='ls -hF'
fi

This is often the sanest choice. Alternatively, you can conditionally source a different dircolors config:

  if [ –z $SSH_CLIENT ]; then
# Local login: use default settings
eval $(dircolors -b ~/.dircolors)
else
# Remote login: use alternate color scheme
eval $(dircolors -b ~/.dircolors_remote)
fi

But this starts getting into the realm of diminishing returns, IMO. I usually find it easier to create a profile with a custom color-mapping on the SSH client.  If it’s a Windows machine, PuTTY can be used for this; if it’s another Linux box, then gnome-terminal (or konsole/whatever)  can be used in the same way described above.

As an example, here’s how my current color scheme looks using a default PuTTY session: This looks okay-ish, but if I were going to be logging in remotely a lot, I might create a custom config in PuTTY whose colors exactly match the gnome-terminal settings on the host.  Here’s what I get when I do that:You can see that these muted colors more-or-less match those of the gnome-terminal screenshot above. (It looks a little different because there’s no transparency, but it’s close.)

Having different color schemes for different hosts (or different types of hosts) can really help you stay oriented when working with multiple machines. You can know immediately, for example, that any terminal with a green background is connected to the Sound Server, and any terminal with a beige background is connected to the Simulation Host and any terminal with a black background is connected to an Image Generator. (Or whatever server types are appropriate for the app sphere you work in.)

Once you’ve worked with a color scheme like this for awhile, you find it hard to go back to an undifferentiated mess of bland terminals, which is why I find myself doing a lot of color-wrangling when setting up a new system.  Hopefully this Note To Self will make that process a bit easier…

terminal bash 颜色的详细解释的更多相关文章

  1. tar命令的详细解释

    tar命令的详细解释 标签: linuxfileoutputbashinputshell 2010-05-04 12:11 235881人阅读 评论(12) 收藏 举报  分类: linux/unix ...

  2. 用python进行OpenCV实战之用OpenCV3实现图片载入、显示和储存(argparse详细解释)

    将下面文档存为load_display_save.py #-*- coding:utf-8 -*- ap = argparse.ArgumentParser() ap.add_argument(&qu ...

  3. Linux下函数调用堆栈帧的详细解释【转】

    转自:http://blog.chinaunix.net/uid-30339363-id-5116170.html 原文地址:Linux下函数调用堆栈帧的详细解释 作者:cssjtuer http:/ ...

  4. in文件注意事项及详细解释

    lammps做分子动力学模拟时,需要一个输入文件(input script),也就是in文件,以及关于体系的原子坐标之类的信息文件(data file)和势文件(potential file).lam ...

  5. 每天进步一点点------YUV格式详细解释

    YUV格式详细解释 YUV开放分类: 网络.计算机.手机.色彩学.影像学  概述  YUV(亦称YCrCb)是被欧洲电视系统所采用的一种颜色编码方法(属于PAL),是PAL和SECAM模拟彩色电视制式 ...

  6. in文件注意事项及详细解释(转载)

    转载自:https://www.cnblogs.com/sysu/p/10817315.html  和   https://www.cnblogs.com/panscience/p/4953940.h ...

  7. .htaccess语法之RewriteCond与RewriteRule指令格式详细解释

    htaccess语法之RewriteCond与RewriteRule指令格式详细解释 (2012-11-09 18:09:08) 转载▼ 标签:  htaccess it 分类: 网络 上文htacc ...

  8. cookie的详细解释

    突然看到网页上中英文切换的效果,不明白怎么弄得查了查 查到了cookie 并且附有详细解释 就copy留作 以后温习 http://blog.csdn.net/xidor/article/detail ...

  9. Linux学习笔记15——GDB 命令详细解释【转】

    GDB 命令详细解释 Linux中包含有一个很有用的调试工具--gdb(GNU Debuger),它可以用来调试C和C++程序,功能不亚于Windows下的许多图形界面的调试工具. 和所有常用的调试工 ...

随机推荐

  1. Convert.ToString和ToString的区别

    Convert.ToString能处理字符串为null的情况,不抛出异常. ToString方法不能处理字符串为null的情况,会抛出异常.如:“未将对象引用设置到对象的实例”.

  2. 在Eclipse中添加添加一些有助于开发的插件

    Eclipse不像MyEclipse那样高度的继承了很多插件,Eclipse需要使用什么插件可以自己进行添加,添加tomcatPlugin插件,成功之后你的Eclipse中就会多了几个图标. 参照文章 ...

  3. 《暗黑世界GM管理后台系统》部署+功能说明

    原地址:http://blog.csdn.net/uxqclm/article/details/11969761 欢迎来到9秒:www.9miao.com 暗黑三国管理后台说明文档 (一)功能描述该后 ...

  4. 年度十佳 DevOps 博客文章(后篇)

    如果说 15 年你还没有将 DevOps 真正应用起来,16 年再不实践也未免太落伍了.在上篇文章中我们了解到 15 年十佳 DevOps 博客文章的第 6-10 名,有没有哪一篇抓住了您的眼球,让您 ...

  5. ZOJ 2750 Idiomatic Phrases Game(Dijkstra)

    点我看题目 题意 : 给定一本字典,字典里有很多成语,要求从字典里的第一个成语开始,运用字典里的成语变到最后一个成语,变得过程就是成语接龙,后一个成语的第一个字必须有前一个成语的最后一个字相等,给定的 ...

  6. 物理地址为20位 如10000H 用段地址*16+偏移地址表示

    段地质在cpu中,为16位 段地质*16则变成物理首地址20位,这个物理首地址必定是16的倍数. 偏移地址16位, 则表明一个段的大小为64k. 同时也表明16位地址的寻址能力为64kb

  7. MemSQL Start[c]UP 2.0 - Round 2

    反正晚上睡不着,熬到1点开始做比赛,6个题目只做了2个题目,而且手速还比较慢,待提升空间还很大呢. A题:给定两个0,1串(len<=100000), 但是不是普通的二进制串,而是q进制串,q ...

  8. QT带OpenGL与不带的区别,QT5是一个伟大的框架,短时期内根本不会有替代者

    你好 , 我Qt的初学者 , 我在官网下载Qt时感觉很迷茫 , 不知道要下载哪个, 麻烦你写他们之间的不同点:Qt 5.2.0 for Windows 32-bit (MinGW 4.8, OpenG ...

  9. 手势识别官方教程(3)识别移动手势(识别速度用VelocityTracker)

    moving手势在onTouchEvent()或onTouch()中就可识别,编程时主要是识别积云的速度用VelocityTracker等, Tracking Movement This lesson ...

  10. WinForm实现简单的拖拽功能(C#)(2)

    首先创建一个winform应用程序,添加listbox1与listbox2,拖拽listbox1的项到listbox2上去. 具体代码如下 namespace OLE拖拽{ public partia ...