当键入“第一命令”时,Bash可编程完成。 [英] Bash programmable completion when typing "first command"

查看:88
本文介绍了当键入“第一命令”时,Bash可编程完成。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来控制在bash4命令提示符下键入的第一个命令的完成?

Is there a way how to control completion for first command being typed on bash4 command prompt?

我可以用complete -E来控制空行的完成,但是一旦键入某些字符,bash(或可能是readline)就会为我提供PATH中的所有文件名,内置命令(如果有,则是else ...)以及完成尝试(TAB)时的功能。

I can control completions for "empty line" with complete -E, but as soon as some characters are typed, bash (or possibly readline) gives me all filenames from PATH, builtin commands (if, then, else...) and functions on completion attempt (TAB).

我能够通过在PROMPT_COMMAND中取消设置PATH并通过绑定功能来捕获DEBUG来恢复PATH来避免PATH条目,但是由于摆脱了bash bultin命令的完成而没有运气。

I was able to avoid PATH entries by unsetting PATH in PROMPT_COMMAND and restoring it by binding function to trap DEBUG, but no luck with getting rid of bash bultin commands completions.

有什么想法吗?

推荐答案

这是bash可编程完成工具设计中的一个真正的弱点。即使默认命令完成 -D 仅对空白行中的命令也有效(前提是没有 complete -E 已指定)。缺少 complete -I (用于不完全键入的命令)之类的东西。

This is a veritable weak point in the design of bash's programmable completion facilities. Even the "default" command completion -D takes effect for commands on a blank line only (provided that no complete -E is specified). Something like complete -I (for incompletely typed-in commands) is missing.

这篇关于当键入“第一命令”时,Bash可编程完成。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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