コマンドラインターミナルのANSIカラーを設定する方法

コマンドラインターミナルのANSIカラーを設定する方法

私は特に Mac OS X で bash を使用していますが、答えは Unix 全般になると思います。

すでに ANSI カラーを使用していますが、フォルダーや隠しファイルなどに別の色を再割り当てしたいと思います。

更新: 隠しファイルに特定の色を割り当てることはできず、また、スティッキー権限ビットの色がディレクトリよりも優先されるため、ディレクトリを常に同じ色にすることはできません (スクリーンショットではオリーブ グリーン)。

答え1

~/.profile を次のように変更します。すでにお持ちで使用しているものに応じて、これを ~/.bashrc または ~/.bash_profile に配置することもできます。注: これはデフォルトの色設定を示しています。赤いディレクトリを表示したい場合は、最初の e を B に変更します。

    LSCOLORS=exfxcxdxbxegedabagacad

    export LSCOLORS

    export CLICOLOR=1    

~/.profile を保存し、次の操作を実行します。

    . .profile

コマンドラインから。

以下は、ls マニュアル ページのさまざまな色設定と属性の順序です。

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 foreground and default background for regular directories, black foreground and red
                 background for setuid executables, etc.

答え2

dircolors(1) コマンドは、シェルの起動スクリプトで評価して環境変数 LS_COLORS を設定するコマンドを生成します。この環境変数は、/bin/ls に出力の色付け方法を指定します。詳細については、http://linux.die.net/man/5/dir_colors

関連情報