自定义壳标签完成 [英] Customize tab completion in shell

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

问题描述

这可能会比自定义选项卡完成更好的名字,但这里的情况:

This may be have a better name than "custom tab completion", but here's the scenario:

通常情况下,当我在命令行中,我输入一个命令,然后用{TAB}两次,我得到在当前目录下的所有文件和子目录的列表。例如:

Typically when I'm at the command line and I enter a command, followed with {TAB} twice, I get a list of all files and subdirectories in the current directory. For example:

[user@host tmp]$ cat <TAB><TAB>
chromatron2.exe                  Fedora-16-i686-Live-Desktop.iso  isolate.py
favicon.ico                      foo.exe                          James_Gosling_Interview.mp3

不过,我注意到至少一个程序以某种方式过滤该列表:葡萄酒。试想一下:

[user@host tmp]$ wine <TAB><TAB>
chromatron2.exe  foo.exe

它有效地过滤结果 *。exe文件

想这可能是某种形式的包装脚本负责过滤,一个做了文件的事实证明葡萄酒不是一个脚本,但一个可执行文件。

Thinking it might be some sort of wrapper script responsible for the filtering, a did a which and file an it turns out wine is not a script but an executable.

现在,我不知道这个过滤器是否以某种方式连接的程序本身,或在默认安装葡萄酒另有规定$ C $的CD,所以我不知道这个问题是否更适合于计算器或超级用户,所以我穿越我的手指在这里把它扔。我道歉,如果我猜错了。 (另外,我查了一些类似的问题,但大多数是不相关或参与编辑的外壳配置。)

Now, I don't know whether this "filter" is somehow encoded in the program itself, or otherwise specified during the default wine install, so I'm not sure whether this question is more appropriate for stackoverflow or superuser, so I'm crossing my fingers and throwing it here. I apologize if I guessed wrong. (Also, I checked a few similar questions, but most were irrelevant or involved editing the shell configuration.)

我的问题是,这是怎么过滤实现的呢?先谢谢了。

So my question is, how is this "filtering" accomplished? Thanks in advance.

推荐答案

您可能会发现所谓的系统上的文件的/ etc / bash_completion 这是充满了功能和的设置此行为完全命令。该文件将被你的shell启动文件中的一个来源,如〜/ .bashrc中

You will likely find a file on your system called /etc/bash_completion which is full of functions and complete commands that set up this behavior. The file will be sourced by one of your shell startup files such as ~/.bashrc.

有也可以是称为 /etc/bash_completion.d 目录,其中包含与多个完成的功能的各个文件。这些文件由的/ etc / bash_completion

There may also be a directory called /etc/bash_completion.d which contains individual files with more completion functions. These files are sourced by /etc/bash_completion.

这是葡萄酒完成命令的样子从的/ etc / bash_completion 我的系统上:

This is what the wine completion command looks like from the /etc/bash_completion on my system:

complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine

这组文件是由猛砸完成项目。

这篇关于自定义壳标签完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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