为 macOS 终端添加颜色
后知后觉 暂无评论

Terminal 默认显示无颜色,为了方便区分不同的文件类型。

指导

macOS Mojave 终端默认使用 Bash (默认提示符 $ ) ,因此编辑其配置文件 ~/.bash_profile 添加如下两行。

export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad

若使用 Csh (默认提示符 % ),需要修改 ~/.cshrc

从 macOS Catalina 开始终端将默认使用 Zsh ,其配置文件为 ~/.zshrc

说明

LSCOLORS 的含义:

    LSCOLORS The value of this variable describes what color to use
    for which attribute when colors are enabled with
    CLICOLOR. This string is a concatenation of pairs of the
    format fb, where f is the foreground color and b is the
    background color.

    The color designators are as follows:

    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

    Note that the above are standard ANSI colors. The actual
    display may differ depending on the color capabilities of
    the terminal in use.

    The order of the attributes are as follows:

    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
    bit

    The default is “exfxcxdxbxegedabagacad”, i.e. blue fore-
    ground and default background for regular directories,
    black foreground and red background for setuid executa-
    bles, etc.

附录

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。