如何bash的标签完成工作? [英] How does bash tab completion work?

查看:150
本文介绍了如何bash的标签完成工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了很多时间在最近的外壳和我不知道如何的标签自动完成的作品。什么是其背后的机制?如何在bash知道每个目录的内容?

I've been spending alot of time in the shell lately and I'm wondering how the tab autocomplete works. What's the mechanism behind it? How does the bash know the contents of every directory?

推荐答案

有两个部分自动完成:


  • readline库,如已经提到fixje,管理命令行编辑,并要求回时,标签是pressed庆典,使完成。巴什然后给出(见下点)尽可能完整的列表,并通过在已键入的字符明确标识的readline插入尽可能多的字符。(您可以配置readline库颇多,请参见<一个href=\"http://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?%28bash.info.gz%29Command%2520Line%2520Editing\">Command有关详细信息,猛砸手册的在线编辑。)

猛砸本身所具有的buildin的完整来定义单个命令的完成机制。如果当前命令没有被定义,它(使用执行opendir / readdir的,因为伊格纳西奥说的)用来完成按文件名。

Bash itself has the buildin complete to define a completion mechanism for individual commands. If for the current command nothing is defined, it used completion by file name (using opendir/readdir, as Ignacio said).

要定义自己补全部分章节描述<一个href=\"http://info2html.sourceforge.net/cgi-bin/info2html-demo/info2html?%28bash.info.gz%29Programmable%2520Completion\">Programmable完成。总之,随着
完成«选项»«命令»定义完成一些命令。例如完整-u苏说:
完成对命令的参数时,搜索当前系统的用户

The part to define your own completions is described in the section Programmable Completion. In short, with complete «options» «command» you define the completion for some command. For example complete -u su says when completing an argument for the su command, search for users of the current system.

如果这是比更复杂
正常的选项可以覆盖(取决于参数指标如不同的完成,或者根据previous参数),
您可以使用 -F功能,然后将调用一个shell函数产生可能的补全列表。
(这是用于例如用于GIT中完成,这是非常复杂的,这取决于子和有时
给定,以及使用有时分支的名称(这是什么庆典知道)选项。

If this is more complicated than the normal options can cover (e.g. different completions depending on argument index, or depending on previous arguments), you can use -F function, which will then invoke a shell function to generate the list of possible completions. (This is used for example for the git completion, which is very complicated, depending on subcommand and sometimes on options given, and using sometimes names of branches (which are nothing bash knows about).

您可以列出使用简单的完整,有什么是可能的IM pression在当前的bash环境中定义的现有完井。如果你安装了bash-completion软件包(或者不管它被命名为您的系统上),落成了很多命令安装,并作为Wrikken说,在/ etc / bash_completion包含,然后经常在shell启动执行的bash脚本配置此。其他自定义脚本完成可放在/etc/bash_completion.d;这些都从/ etc / bash_completion采购。

You can list the existing completions defined in your current bash environment using simply complete, to have an impression on what is possible. If you have the bash-completion package installed (or however it is named on your system), completions for a lot of commands are installed, and as Wrikken said, /etc/bash_completion contains a bash script which is then often executed at shell startup to configure this. Additional custom completion scripts may be placed in /etc/bash_completion.d; those are all sourced from /etc/bash_completion.

这篇关于如何bash的标签完成工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆