是否可以为我的linux功能复制命令的制表符完成

是否可以为我的linux功能复制命令的制表符完成

本文介绍了是否可以为我的linux功能复制命令的制表符完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 magic 的bash shell函数.我想定义一个制表符完成功能 _magic ,该功能将允许 magic 搭载任何给定命令的制表符完成功能(如果可用).换句话说,我希望魔术能够执行以下操作:

Let's say I have a bash shell function named magic. I want to define a tab completion function _magic which would allow magic to piggyback on the tab completion functions of any given command (if available). In other words, I want magic to be able to do something like this:

~ $ magic git ... <search for _git and use it if found>
~ $ magic cd ... <search for _cd and use it if found>
~ $ magic some-cmd ... <search for _some-cmd and use it if found>

我似乎无法在网上找到任何可以帮助我使用compgen,complete等实现此目标的东西.这是否有可能?提前致谢.

I can't seem to find anything online that would help me achieve this using compgen, complete etc. Is this even possible? Thanks in advance.

推荐答案

有许多这样的(伪?)命令都需要这样做.例如timenicestrace等.
它们都使用相同的命令完成:_command.因此,不要重新发明轮子. :)

There are many such (pseudo?) commands, that need this. e.g. time, nice, strace etc.
They all use the same command completion: _command. So, don't re-invent the wheel. :)

如果可以,请尝试在您的bash终端中运行它:

Try running this in your bash terminal, if this work:

complete -F _command magic

这篇关于是否可以为我的linux功能复制命令的制表符完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:17