MAC 終端terminal顏色

Mac終端terminal顏色實在太單調了,安裝Linux使用的GNU Coreutils替換Mac的ls命令:css

Mac終端terminal顏色實在太單調了,安裝Linux使用的GNU Coreutils替換Mac的ls命令:

一、使用 Homebrew 工具安裝Coreutils。
Homebrew相似於Centos下的Yum工具,安裝軟件自動解決依賴關係,很是不錯。Homebrew工具的安裝見Homebrew官方首頁安裝說明。
因爲Coreutils安裝包是xz壓縮格式,所以須要同時安裝xz工具:
brew install xz coreutils
 
二、生成顏色配置文件:
gdircolors --print-database > ~/.dir_colors

三、在~/.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,實在是很難看,便着手美化了一下終端的配色方案,主要分爲兩步:html

一是在終端的設置偏好裏設置,能夠設置字體的大小,顏色,背景顏色,透明度等等,通常基本的美化操做在這裏均可以設置。可是不能設置ls命令針對不一樣文件顯示不一樣的顏色。linux

二是調整ls命令顯示的文件類型顏色。這步也是最複雜的,主要原理是用dircolors命令讀取 .dir_color文件中的配色方案,設置LS_COLORS變量,讓ls針對不一樣文件顯示不一樣的顏色。主要分爲如下三步驟(參考TroyCheng同窗方法):sql

主要分如下三步:vim

 

  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
相關文章
相關標籤/搜索