自动完成命令行参数 [英] Auto-complete command line arguments

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

问题描述

在bash中,可执行文件(如mplayer和imagemagick的convert)在命令行参数上有一个很酷的自动完成功能。例如,如果我键入

In bash, executables such as mplayer and imagemagick's "convert" have a cool auto-complete functionality on their command line arguments. For instance, if I type

mplayer <tab><tab>

,然后mplayer将列出位于该文件夹中的所有媒体文件,媒体文件。

in one of my folder, then mplayer will list all media files located in that folder, and only the media files.

同样,如果我键入

convert -<tab><tab>

然后我会看到convert脚本的所有可能的选项,这是伟大的。

then I will see all the possible options of the convert script, which is great.

我的问题是如何使用bash,ruby或python脚本实现类似的功能?

My question is how to achieve a similar functionality, using bash, ruby or python scripts?

推荐答案

这是BASH智能完成的一个例子。基本说明是此处,指南要编写自己的扩展程序是这里和另一个(Debian的指南是此处。以下是更全面的功能介绍 complete 命令(有助于此行为的命令)。

This is an example of BASH's smart completion. A basic description is here, a guide to writing your own extensions is here and another (Debian-based) guide is here. And here's a fuller featured introduction to the complete command (the command that facilitates this behaviour).

这篇关于自动完成命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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