让 OS X Terminal 里的 ls 也有颜色

2014 年 1 月 5 日
 Livid
在 .profile 里加入:

export CLICOLOR=1
export LSCOLORS=exfxcxdxbxexexabagacad
14022 次点击
所在节点    macOS
22 条回复
alexrezit
2014 年 1 月 5 日
$ alias l
alias l='ls -FG'
kqz901002
2014 年 1 月 5 日
bash的话
export CLICOLOR=1
export GREP_OPTIONS="--color=auto" 这样就可以

zsh得像楼主这样
Livid
2014 年 1 月 5 日
@kqz901002
@alexrezit

谢谢,这是我最喜欢 V2EX 的一点,我知道肯定会有人提出更好的做法。
Livid
2014 年 1 月 5 日
@kqz901002 我发现如果不加入最后一行,颜色的配置方式貌似和 Ubuntu 上显示的不一样。
kqz901002
2014 年 1 月 5 日
@Livid 这样啊,可能跟colorscheme有关系, http://equation85.github.io/blog/customize-terminal-on-mac/
kqz901002
2014 年 1 月 5 日
@Livid
@alexrezit
感觉oh-my-zsh默认的就已经很舒服了
https://github.com/robbyrussell/oh-my-zsh
jasontse
2014 年 1 月 5 日
Linux bash 我是这么做的
export LS_OPTIONS='--color=auto'
alias ls='ls $LS_OPTIONS'

tree 也会有高亮
bigclean
2014 年 1 月 5 日
可以使用 gnu coreuils 中的 ls 替代 bsd ls,其支持 dircolors,搭配 solarized 主题(https://github.com/seebi/dircolors-solarized/)使用非常方便。
duoxing
2014 年 1 月 5 日
添加了之后,ls确实有颜色了,但是对目录的颜色不是很满意,在什么地方可以改呢?
duoxing
2014 年 1 月 5 日
好了,知道在什么地方改了,改好了,谢谢,请忽略上面那条
run2
2014 年 1 月 5 日
@duoxing 估计只有直接改配色方案了,github里很多 terminal color scheme
Owenjia
2014 年 1 月 5 日
https://github.com/seebi/dircolors-solarized
ls的话,我用的这个~~
leebo
2014 年 1 月 5 日
oh my zsh 哈哈 肯定有人会说这个吧
hackevin
2014 年 1 月 5 日
drwxr-xr-x+ 5 hackevin staff 170 [2013-12-21 22:15] Public/
drwx------+ 3 hackevin staff 102 [2013-12-21 22:15] Movies/

-----------------------------------------------------------------

[hackevin.iNULLMBA] $ bash --version
GNU bash, version 4.3.0(1)-rc1 (x86_64-apple-darwin13.0.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[hackevin.iNULLMBA] $ brew install coreutils

[hackevin.iNULLMBA] $ cat .profile
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
alias ls='ls -F -rt --color=auto --time-style=+"[%Y-%m-%d %H:%M]"'
kqz901002
2014 年 1 月 5 日
@hackevin
➜ ~ bash --version
GNU bash, 版本 4.2.45(2)-release (i386-apple-darwin13.0.2)
Copyright (C) 2011 Free Software Foundation, Inc.
许可证 GPLv3+: GNU GPL 许可证版本3或者更高 <http://gnu.org/licenses/gpl.html>

这是自由软件,您可以自由地更改和重新发布。
在法律允许的范围内没有担保.

竟然是中文的 吓尿我了
sinxccc
2014 年 1 月 5 日
@kqz901002 locale
kevinroot
2014 年 1 月 5 日
用的zsh自带的主题:robbyrussell.zsh-theme看着挺舒服的的
dorentus
2014 年 1 月 5 日
> export CLICOLOR=1
之后就有颜色了吧,LSCOLORS 似乎是用来设置颜色的?


@hackevin 你的 bash 是自己装的?怎么版本这么高……
我的 OS X 10.9.1 (13B42) 自带的 /bin/bash 才是 3.2.51:

> GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
> Copyright (C) 2007 Free Software Foundation, Inc.

homebrew 带的 bash stable 也只是 4.2.45 而已啊……
jokefun
2014 年 1 月 6 日
hackevin
2014 年 1 月 6 日
@dorentus 自己编译的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/95737

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX