macbook中使用彩色的ls

一、首先,macbook中原裝的ls和gnu的ls是不相同的,因此,要下載安裝正牌lsgit

brew install coreutils    //gnu ls 在裏面

二、由於和mac的ls有衝突,因此,coreutils的命令都加了‘g',例如ls變成gls,爲了取消這個限制,能夠把gnu命令的執行文件夾放到path的最前面,這樣就會最早執行gnu的命令,而不是mac的了。github

在/etc/profile文件中添加:shell

#add gnu coreutils in your /etc/profile
PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

三、解決顏色的問題,先說說原理:ls  --color=auto會根據設置的顏色文件對不一樣類型的文件或文件夾顯示不一樣的文件,coreutils中還有一個專門的命令用於調試顏色的dircolors。它的用法:dircolors會生成一個文件用於設置變量LS_COLORS,而後把這個生成的文件用eval執行一下,ls就會按着文件顯示顏色嘍。dircolors -p還會顯示一個默認的顏色配置方案。vim

四、看看下面gnu的說明:bash

10.4 ‘dircolors’: Color setup for ‘ls’
======================================

‘dircolors’ outputs a sequence of shell commands to set up the terminal
for color output from ‘ls’ (and ‘dir’, etc.).  Typical usage:

     eval "$(dircolors [OPTION]... [FILE])"

   If FILE is specified, ‘dircolors’ reads it to determine which colors
to use for which file types and extensions.  Otherwise, a precompiled
database is used.  For details on the format of these files, run
‘dircolors --print-database’.

   To make ‘dircolors read a ‘~/.dircolors’ file if it exists, you can
put the following lines in your ‘~/.bashrc’ (or adapt them to your
favorite shell):

     d=.dircolors
     test -r $d && eval "$(dircolors $d)"

   The output is a shell command to set the ‘LS_COLORS’ environment
variable.  You can specify the shell syntax to use on the command line,
or ‘dircolors’ will guess it from the value of the ‘SHELL’ environment,
variable.

   The program accepts the following options.  Also see *note Common
options::.
‘--sb’
‘--bosh’
‘--bourne-shell’
     Output Bourne shell commands.  This is the default if the ‘SHELL’
     environment variable is set and does not end with ‘csh’ or ‘tcsh’.

‘-c’
‘--csh’
‘--c-shell’
     Output C shell commands.  This is the default if ‘SHELL’ ends with
     ‘csh’ or ‘tcsh’.‘--pp’
‘--print-database’
     Print the (compiled-in) default color configuration database.  This
     output is itself a valid configuration file, and is fairly
     descriptive of the possibilities.

   An exit status of zero indicates success, and a nonzero value
indicates failure.

五、我用的是和vim的主題一直的molocai。spa

https://github.com/seebi/dircolors-solarized調試

六、下載後,將裏面的dircolors.256dark複製爲用戶目錄的.dircolors。code

七、編輯.bash_profile文件,添加:orm

eval `discolors ~/.dircolors`
alias ls="ls --color=auto"

八、重載配置文件。blog

source .bash_profile

相關文章
相關標籤/搜索