Mac终端terminal颜色实在太单调了,安装Linux使用的GNU Coreutils替换Mac的ls命令:

Mac终端terminal颜色实在太单调了,安装Linux使用的GNU Coreutils替换Mac的ls命令:

1、使用 Homebrew 工具安装Coreutils。
Homebrew类似于Centos下的Yum工具,安装软件自动解决依赖关系,非常不错。Homebrew工具的安装见Homebrew官方首页安装说明。
由于Coreutils安装包是xz压缩格式,因此需要同时安装xz工具:
brew install xz coreutils
 
2、生成颜色配置文件:
gdircolors --print-database > ~/.dir_colors
3、在~/.bash_profile配置文件中加入以下代码:
if brew list | grep coreutils > /dev/null ; then
  PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
  alias ls='ls --show-control-chars --color=auto'
  eval `gdircolors -b $HOME/.dir_colors`
fi
gdircolor的作用就是设置ls命令使用的环境变量LS_COLORS(BSD是LSCOLORS),我们可以修改~/.dir_colors自定义文件的颜色,此文件中的注释已经包含各种颜色取值的说明。
 
 

Mac到手有一段时间了,看着那默认的单调的Terminal,实在是很难看,便着手美化了一下终端的配色方案,主要分为两步:

一是在终端的设置偏好里设置,可以设置字体的大小,颜色,背景颜色,透明度等等,一般基本的美化操作在这里都可以设置。但是不能设置ls命令针对不同文件显示不同的颜色。

二是调整ls命令显示的文件类型颜色。这步也是最复杂的,主要原理是用dircolors命令读取 .dir_color文件中的配色方案,设置LS_COLORS变量,让ls针对不同文件显示不同的颜色。主要分为以下三步骤(参考TroyCheng同学方法):

主要分以下三步:

  1. 手动下载并编译安装coreutils,可以在这里下载:下载地址。下载完毕之后解压并且安装(安装需要使用gcc,make等命令,可以通过安装Xcode获得):
    tar xzvf coreutils-8.9.tar.gz;
    cd coreuiils-8.9;
    ./configure --prefix=/usr;
    sudo make;
    sudo make install
  2. 安装完毕之后需要配置终端的profile:
    export PS1="\[\e[0;32m\][\e[0;32m\]\u@\e[0;31m\]\h \[\e[0;34m\]\w\e[0;32m\]] $ \[\e[0m\]"
    test -r /sw/bin/init.sh && . /sw/bin/init.sh
    if [ "$TERM" != "dumb" ]; then
    export LS_OPTIONS='--color=auto'
    test -r ~/.dir_color && eval "$(dircolors -b ~/.dir_color)" || eval "$(dircolors -b)"
    eval `dircolors ~/.dir_color`
    fi
    # Useful aliases
    alias ls='ls $LS_OPTIONS'
    alias ll='ls -al'
    alias grep='grep $LS_OPTIONS'
    alias fgrep='fgrep $LS_OPTIONS'
    alias egrep='egrep $LS_OPTIONS'
  3. 如果需要自己设置颜色文件,那么可以编辑如下文件:
    vim ~/.dir_color;
    添加如下的内容即可:
    # Configuration file for dircolors, a utility to help you set the
    # LS_COLORS environment variable used by GNU ls with the --color option.
     
    # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
    # slackware version of dircolors) are recognized but ignored.
     
    # Below, there should be one TERM entry for each termtype that is colorizable
    TERM linux
    TERM linux-c
    TERM mach-color
    TERM console
    TERM con132x25
    TERM con132x30
    TERM con132x43
    TERM con132x60
    TERM con80x25
    TERM con80x28
    TERM con80x30
    TERM con80x43
    TERM con80x50
    TERM con80x60
    TERM xterm
    TERM xterm-color
    TERM xterm-debian
    TERM rxvt
    TERM screen
    TERM screen-w
    TERM vt100
     
    # Below are the color init strings for the basic file types. A color init
    # string consists of one or more of the following numeric codes:
    # Attribute codes:
    # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
    # Text color codes:
    # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
    # Background color codes:
    # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
    NORMAL 00   # global default, although everything should be something.
    FILE 00     # normal file
    DIR 01;36   # directory
    LINK 01;37  # symbolic link.  (If you set this to 'target' instead of a
    # numerical value, the color is as for the file pointed to.)
    FIFO 40;33  # pipe
    SOCK 01;35  # socket
    DOOR 01;35  # door
    BLK 40;33;01    # block device driver
    CHR 40;33;01    # character device driver
    ORPHAN 40;31;01 # symlink to nonexistent file
     
    # This is for files with execute permission:
    EXEC 00;35
     
    # List any file extensions like '.gz' or '.tar' that you would like ls
    # to colorize below. Put the extension, a space, and the color init string.
    # (and any comments you want to add after a '#')
     
    # If you use DOS-style suffixes, you may want to uncomment the following:
    #.cmd 01;32 # executables (bright green)
    #.exe 01;32
    #.com 01;32
    #.btm 01;32
    #.bat 01;32
     
    .tar 01;31 # archives or compressed (bright red)
    .tgz 01;31
    .arj 01;31
    .taz 01;31
    .lzh 01;31
    .zip 01;31
    .z   01;31
    .Z   01;31
    .gz  01;31
    .bz2 01;31
    .deb 01;31
    .rpm 01;31
    .jar 01;31
    .dmg 01;31
     
    # image formats
    .jpg 01;35
    .png 01;35
    .gif 01;35
    .bmp 01;35
    .ppm 01;35
    .tga 01;35
    .xbm 01;35
    .xpm 01;35
    .tif 01;35
    .png 01;35
    .mpg 01;35
    .avi 01;35
    .fli 01;35
    .gl 01;35
    .dl 01;35
     
    # source code files
    .pl 00;33
    .PL 00;33
    .pm 00;33
    .tt 00;33
    .yml 00;33
    .sql 00;33
    .html 00;33
    .css 00;33
    .js 00;33

MAC 终端terminal颜色的更多相关文章

  1. mac终端terminal快捷键:

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Hannotate SC" } span.s1 { } p.p1 { m ...

  2. mac终端terminal快捷键

    mac终端terminal快捷键: Command + K 清屏 Command + T 新建标签 Command +W  关闭当前标签页 Command + S  保存终端输出 Command + ...

  3. mac 终端(terminal) 启动tomcat

    mac 终端启动tomcat: 找到你的tomcat安装的根目录:找到bin目录,在终端 cd 到这个bin中,输入sudo ./startup.sh (然后终端会提示你输入本机密码如果是在需要权限的 ...

  4. Mac终端(Terminal)自定义颜色,字体,背景

    使用Mac作为开发机的时候,苹果终端自带的颜色黑白,字体又小,看起来确实不是很舒服.那推荐大家使用Solarized配色方案.Solarized 是目前最完整的 Terminal/Editor/IDE ...

  5. Mac终端ls颜色设置

    mac自带的终端是款非常好用的ssh工具,但ls命令下文件与文件夹都是单一的颜色,为了更好区分,作出修改. 终端默认背景颜色为白色,(终端->偏好设置->描述文本),可修改背景颜色与字体大 ...

  6. Mac 终端Terminal光标移动快捷键

    声明: 转载自: http://blog.csdn.net/lgm252008/article/details/8253519 在Mac系统中并没有Home.End等键,所以在使用时并不是特别的顺手, ...

  7. mac 终端添加颜色

    1.打开终端,然后找到终端偏好设置,选择自己喜欢的颜色 2.然后切换到当前用户的家目录: cd ~ 3.打开文件,开始编辑".bash_profile", 添加下面两句 expor ...

  8. Mac终端Terminal调用Sublime Text

    Sublime Text 本身提供了命令行工具, 只需要在 Terminal 中输入以下内容就行了 sudo ln -s /Applications/Sublime\ Text.app/Content ...

  9. mac终端(terminal)里的快捷键

    Command + K 清屏 Command + T 新建标签 Command +W 关闭当前标签页 Command + S 保存终端输出 Command + D 垂直分隔当前标签页 Command ...

随机推荐

  1. vSphereClient向ESXi主机分配许可证

    ESXi服务器需要使用VMwarevSphereClient进行管理(7.0+版本可以通过浏览器进行管理)在VMware vSphere client可以方便的创建.管理虚拟机,并分配相应的资源.要能 ...

  2. android打包library

    最近在做开发时,遇到一个需求,就是要自定义一个控件,最后需要将其打包成android library库,然后供以后其他需求使用,由于以前很少打包library,所以这次特地学了下怎么打包. 首先先随便 ...

  3. python read文件内容的iter方式

    遍历file的方式 iter(lambda: f.read(4096), "")等价与while True: data = f.read(4096) if not data: br ...

  4. [Idea Fragments]2013.08.08

    # 1 今晚看到好几篇文章把golang,Node.js还有Nginx-lua拿来说事,Node.js现在自然比较熟悉,golang则有过一些了解,而Nginx-lua则少有听到. 有好事者对Node ...

  5. sql server 订阅发布的配置

    网上sql server 的发布订阅功能的教程很多,但是很多东西写的不是很详细,常常给人误解,现在根据自己的情况从新整理一下: 1.服务器端  然后一路下一步, 2.订阅端(重点) 给服务器在本地取一 ...

  6. 完成blog后台一枚

    技术实现:纯jfinal+AmazeUI

  7. 基于Jquery的实现回车键Enter切换焦点

    系统默认情况下,使用Tab按键切换页面元素的焦点,有没有想过回车键Enter也可以实现这种功能,并且具有良好的用户体验. 接下来我们使用Jquery实现回车键Enter切换焦点,此代码在常用浏览器IE ...

  8. word中使用MathType能做什么

    在Office中写论文,特别是一些比较专业的论文需要用到各种公式的.会发现有很多地方Office自带的公式编辑器都无法完成,所以要用到MathType公式编辑器这个好用的工具了.MathType是一款 ...

  9. php 使用curl 进行简单模拟提交表单

    //初始化curl $ch = curl_init(); $url = 'xxx'; $option = [ CURLOPT_URL => $url, CURLOPT_HEADER => ...

  10. cocos2d安卓自动编译脚本去掉复制Resources资源和签名功能

    去掉这两个功能的原因: 1.因为有时候打包是分渠道的,不同的渠道资源也可能不一样,所以不能直接复制资源. 2.如果用cocostudio打release包,因为要输入签名地址,会导致在自动签名处停住不 ...