zoukankan      html  css  js  c++  java
  • terminal bash 颜色的详细解释

    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:term_colors 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:term_before Here’s what I wound up with after some minor tweaking:term_afterFor 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:putty_before 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:putty_afterYou 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…

  • 相关阅读:
    HDU 1874 畅通project续 最短路径入门(dijkstra)
    怎样推断 ios设备的类型(iphone,ipod,ipad)
    双向数据绑定---AngularJS的基本原理学习
    常见的CPU訪问引起的内存保护问题为什么仅仅用event_122上报
    最简单的基于FFmpeg的视频编码器-更新版(YUV编码为HEVC(H.265))
    【Java项目实战】——DRP之HTML总结
    myql5.7.7优化配置參数
    2014年七月最佳jQuery插件荟萃
    敏捷DoD完毕定义的多种形态
    c#网络通信框架networkcomms内核解析之三 消息同步调用
  • 原文地址:https://www.cnblogs.com/welhzh/p/4283787.html
Copyright © 2011-2022 走看看