一、首先,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