简体   繁体   English

bash“自动完成”(通过TAB TAB)条目可以着色/格式化吗?

[英]Can the bash "autocomplete" (via TAB TAB) entries be colored/formated?

Background:背景:

The "autocomplete" feature I am talking about is when you half-type a command or filename in bash, if you press TAB twice it will print out suggestions.我所说的“自动完成”功能是当你在 bash 中输入一半命令或文件名时,如果你按两次 TAB 它将打印出建议。

Question:题:

The entries output looks allot like the default ls behavior.条目输出看起来像默认的ls行为。

How could I override this to give it different colors or format (like ls )?我如何覆盖它以赋予它不同的颜色或格式(如ls )?

EDIT: Copy paste of Answer on UnixStackExchange - vote for it there!编辑:复制粘贴UnixStackExchange 上的答案- 在那里投票!

In bash 4.3 and later you can add在 bash 4.3 及更高版本中,您可以添加

set colored-stats on

to ~/.inputrc .~/.inputrc

See http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html :http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html

colored-stats

If set to ` on ', Readline displays possible completions using different colors to indicate their file type.如果设置为 ` on ',Readline 会使用不同的颜色显示可能的补全以指示其文件类型。 The color definitions are taken from the value of the LS_COLORS environment variable.颜色定义取自LS_COLORS环境变量的值。 The default is ` off '.默认值为“ off ”。

You can use http://geoff.greer.fm/lscolors/ to generate both LS_COLORS (which is used by GNU ls and colored-stats ) and LSCOLORS‏ (which is used by BSD ls ).可以使用http://geoff.greer.fm/lscolors/同时生成LS_COLORS (其用于通过GNU lscolored-stats )和LSCOLORS‏其由BSD使用ls )。

Append set colored-stats on to your input-rc file.set coloured-stats附加到您的 input-rc 文件中。

[[ -f $INPUTRC ]] && echo set colored-stats on >> $INPUTRC

Or if you have it in the default location:或者,如果您在默认位置拥有它:

echo set colored-stats on >> ~/.inputrc

Then restart bash.然后重新启动bash。

That's it.就是这样。

彩色完成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM