Mac 終端命令列顏色高亮顯示

2020-09-25 11:00:33

一、顏色高亮顯示

針對terminal採用bash模式:

  1. 編輯 ~/.bash_profile, 加入以下程式碼:
    export CLICOLOR=1
    export LSCOLORS=gxfxaxdxcxegedabagacad
  2. 儲存,然後重新啟動terminal,搞定,恢復正常了.

 

詳細講解程式碼中的涵義:

  1. CLICOLOR: 前景色和背景色的字串合併值
  2. LSCOLORS: 對於不同變數所採用的顏色方案,具體看如下表格:
    a       black
    b       red
    c       green
    d       brown
    e       blue
    f        magenta
    g      cyan
    h       light grey
    A      bold black, usually shows up as dark grey
    B       bold red
    C      bold green
    D      bold brown, usually shows up as yellow
    E       bold blue
    F       bold magenta
    G     bold cyan
    H      bold light grey; looks like bright white
    x       default foreground or background
    而檔案型別列表如下:
    1. directory
    2. symbolic link
    3. socket
    4. pipe
    5. executable
    6. block special
    7. character special
    8. executable with setuid bit set
    9. executable with setgid bit set
    10. directory writable to others, with sticky bit
    11. directory writable to others, without sticky

所以對照這張表就可以得知:

gxfxaxdxcxegedabagacad

就是對於directory而言,它的前景色就是: g(cyan),而背景色就是:x(預設的背景色).