Re: [問題] 目錄的顏色
心情好來給魚 :p
※ 引述《RiceSir.bbs@ptt.cc (Sir)》之銘言:
> 我按照上述方法安裝了 gnuls
> 然後修改 /etc/profile 跟 /etc/csh.cshrc 檔
> 現在變成 root 無法顯示目錄顏色但是 user 可以
> 難道這兩個不能一起修改嗎 ?
> Thanks.
先回答你的問題:~root/.cshrc 或是 ~root/.tcshrc 裡面有 alias ls,所以
被蓋掉了。
另外 FreeBSD 下不需要裝 gnuls,原因是 /bin/ls 與 tcsh 裡面的 ls-F 都
有支援色彩輸出:
* 在 man tcsh 裡面找 ls-F 的說明 (進入 more 以後按 /ls-F 搜尋),其中
這段告訴你 LS_COLORS 可以拿來顯示彩色:
The ls-F builtin can list files using different colors depend-
ing on the filetype or extension. See the color tcsh variable
and the LS_COLORS environment variable.
* 所以使用 tcsh 的人可以這樣設定:
alias ls "ls-F -FG"
* 如果你不是用 tcsh,那麼系統的 /bin/ls 也有支援,所以:
alias ls "/bin/ls -FG"
* 再來是色彩的設定,在 ls 的 manpage 裡面有寫,這是在 LSCOLORS 這個
環境變數裡面設定的,系統預設是 "exfxcxdxbxegedabagacad",通常我們
只會改 directory 的顏色,因為太暗了:
# in tcsh
set LSCOLORS="gxfxcxdxbxegedabagacad"
# in bash
export LSCOLORS="gxfxcxdxbxegedabagacad"
* 然後是其他便利性,眼尖的人應該會看到 CLICOLOR 與 CLICOLOR_FORCE 兩
個變數。
先是 CLICOLOR,這個變數與 ls 的時候加上 -G 是一樣的效果,在 ls.c
裡面是這樣寫的:
case 'G':
setenv("CLICOLOR", "", 1);
break;
:
:
/* Enabling of colours is conditional on the environment. */
if (getenv("CLICOLOR") &&
(isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
當輸出的 stdout 不是 tty 時,預設值會關閉色彩輸出,但這可以透過
CLICOLOR_FORCE 強制設定,於是下面兩種情況就有差別:
$ unset CLICOLOR_FORCE
$ ls -alG
與
$ unset CLICOLOR_FORCE
$ ls -alG | less -r
後者會看不到色彩。
* 另外就是 ls 色彩與 configure 的問題。
在 ls 強制輸出色彩的情況下 (即 set CLICOLOR_FORCE),configure 有可
能會失敗,這個問題只要先 unset CLICOLOR 以及 unset CLICOLOR_FORCE,
再跑一次 configure 就可以了。
--
Resistance is futile.
http://blog.gslin.org/ & <gslin@gslin.org>
--
※ Origin: 邪惡小鹿鹿 <Deer.twbbs.org> ◆ From: 140.113.22.90
討論串 (同標題文章)
FreeBSD 近期熱門文章
PTT數位生活區 即時熱門文章