macbook中使用彩色的ls

1、首先,macbook中原装的ls和gnu的ls是不相同的,所以,要下载安装正牌ls

brew install coreutils    //gnu ls 在里面

2、因为和mac的ls有冲突,所以,coreutils的命令都加了‘g',例如ls变成gls,为了取消这个限制,可以把gnu命令的执行文件夹放到path的最前面,这样就会最先执行gnu的命令,而不是mac的了。

在/etc/profile文件中添加:

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

3、解决颜色的问题,先说说原理:ls  --color=auto会根据设置的颜色文件对不同类型的文件或文件夹显示不同的文件,coreutils中还有一个专门的命令用于调试颜色的dircolors。它的用法:dircolors会生成一个文件用于设置变量LS_COLORS,然后把这个生成的文件用eval执行一下,ls就会按着文件显示颜色喽。dircolors -p还会显示一个默认的颜色配置方案。

4、看看下面gnu的说明:

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.

5、我用的是和vim的主题一直的molocai。

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

6、下载后,将里面的dircolors.256dark复制为用户目录的.dircolors。

7、编辑.bash_profile文件,添加:

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

8、重载配置文件。

source .bash_profile

 

posted @ 2018-02-11 16:34  立体风  阅读(2122)  评论(0编辑  收藏  举报