【问题标题】:how to add non-latin gnu/make targets to completion list?如何将非拉丁 gnu/make 目标添加到完成列表?
【发布时间】:2015-07-26 10:44:46
【问题描述】:

gnu/make 在 makefile 中支持非拉丁标识符(例如,目标)。

示例:

$ cat GNUmakefile
test:
  @echo test
тест:
  @echo test in russian

$ make test тест
test
test in russian

但是这个例子的 bash-completion 只完成了一个目标——test:

"make" + tab → "make test"。

如何将非拉丁目标添加到完成列表中?


使用不同版本的bash-completion在各种发行版列表(debian 5-8、ubuntu 12-15、centos 5-6、mandriva 2008)上进行了测试。

我至少需要最新版本的 bash-completion 支持此功能。

【问题讨论】:

  • 请在您的问题中添加操作系统/发行版和版本。
  • @Cyrus,我已经更新了问题。

标签: bash gnu-make bash-completion


【解决方案1】:

我找到了解决办法。

来自文件/usr/share/bash-completion/completions/make 的函数_make_target_extract_script 中的错误,它返回sed-脚本,其中包含以下行:

/^[^a-zA-Z0-9]/             d             # convention for hidden tgt

删除以非拉丁字符开头(特别是)的目标。

在我看来,这样的正则表达式会更合适(参见this):

/^[^[[:alnum:]]]/             d             # convention for hidden tgt

如果你不能编辑/usr/share/bash-completion/completions/make,你可以添加到~/.bashrc这样的行(基于this answer):

_completion_loader make
eval "$(type _make_target_extract_script | sed '1d;s/a-zA-Z0-9/[[:alnum:]]/')"

更新

我提交了bug report(很遗憾,需要注册)。

【讨论】:

  • 在常规 Debian BTS 中提交错误可能比 Alioth 错误更可取。
【解决方案2】:

如果你想看到这个工作,直接的解决方案是用oh-my-zsh 切换到zsh

Bash 以各种错误和不受支持的功能而闻名。 zsh 的运行速度提高了 2 倍,并且与 bash POSIX shell 几乎完全兼容,因此您的大部分 bashrcshell 脚本将与 bashzsh 以相同的方式运行。

【讨论】:

  • 感谢您的回答,但 zsh 不适合我,例如,因为安全漏洞:default 能够为 @ 创建别名987654332@ 和 /path/to/command.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多