Windows 下 Ant 的 Tab 补全功能?

发布于 2024-10-03 18:43:18 字数 102 浏览 0 评论 0原文

有没有办法让 Ant 在 Windows 下(cmd.exe)有正确的制表符补全?

我可以编写默认目标来列出所有其他目标,但这与您在 Linux 上获得的正确制表符补全不同。

Is there any way to have a proper tab completion for Ant under windows (cmd.exe) ?

I could write up the default target to list all the other targets, but that's just no the same as a proper tab completion you get on linux for instance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

难如初 2024-10-10 18:43:18

您可以在 powershell.exe 中轻松集成 ant 的 tabcompletion,顺便说一下,它比普通的旧 cmd.exe 强大得多。

Powershell.exe 是 Windows 7/8 的一部分,但也可以在 XP 中作为单独的组件安装(可以从 Microsoft 网站下载)。

我使用了 https://github.com/peet/posh-ant 下提供的脚本。该脚本尚不完美,但已经完成了 95% 的工作。

You can integrate tabcompletion for ant quite easily in powershell.exe, which by the way is much more powerful than the plain old cmd.exe.

Powershell.exe is part of Windows 7/8 but also can be installed as separate component in XP (can be downloaded from the Microsoft website).

I used the script provided under https://github.com/peet/posh-ant. The script is not yet perfect, but does 95% of the job quite well.

倾其所爱 2024-10-10 18:43:18

BASH 在内置的 complete 命令中有一个可定制的完成机制。通过编写完整命令的脚本,您几乎可以对您能想到的任何内容进行命令行完成。 ant 目标补全是通过名为 complete-ant-cmd.pl 的 Perl shell 脚本完成的,该脚本位于 Cygwin 中的系统范围 bashrc 文件中。

CMD.exe 没有这种机制,并且无法扩展到超出其内置功能的范围。

正如其他人提到的,您可以尝试使用 ant -pant --projecthelp 命令来列出所有目标及其描述。尝试这个 build.xml 文件:

<project name="test" default="target2" basedir=".">
    <description>
         This is a test project. It is to demonstrate the use
         of the "ant -p" command and show all described
         targets. The """ probably won't work, but you can use
         regular quotes.
    </description>

    <target name="target1"
        description="This is the prime target, but not the default"/>

    <target name="target2"
        description="This is the default target but not because I said it here"/>

    <!-- Target "target3" won't display in "ant -p" because -->
    <!-- it has no description parameters. Life is tough.   -->

    <target name="target3"/>

    <target name="target4"
        description="This is target #4, but there's no target3"/>
 </project>

输出将是:

$ ant -p
Buildfile: /Users/david/build.xml

    This is a test project. It is to demonstrate the use
    of the "ant -p" command and show all described
    targets. The """ probably won't work, but you can use
    regular quotes.

Main targets:

    target1  This is the prime target, but not the default
    target2  This is the default target but not because I said it here
    target4  This is target #4, but there's no target3
Default target: target2
$

BASH has a customizable completion mechanism in the builtin complete command. By scripting the complete command, you could do command line completion on almost anything you can think of. The ant target completion is done via a Perl shell script called complete-ant-cmd.pl which is put in the system wide bashrc file in Cygwin.

CMD.exe does not have this mechanism and it cannot be expanded beyond what is already built into it.

As others have mentioned, you can try the ant -p or ant --projecthelp command that will list all targets and their description. Try this build.xml file:

<project name="test" default="target2" basedir=".">
    <description>
         This is a test project. It is to demonstrate the use
         of the "ant -p" command and show all described
         targets. The """ probably won't work, but you can use
         regular quotes.
    </description>

    <target name="target1"
        description="This is the prime target, but not the default"/>

    <target name="target2"
        description="This is the default target but not because I said it here"/>

    <!-- Target "target3" won't display in "ant -p" because -->
    <!-- it has no description parameters. Life is tough.   -->

    <target name="target3"/>

    <target name="target4"
        description="This is target #4, but there's no target3"/>
 </project>

The output will be:

$ ant -p
Buildfile: /Users/david/build.xml

    This is a test project. It is to demonstrate the use
    of the "ant -p" command and show all described
    targets. The """ probably won't work, but you can use
    regular quotes.

Main targets:

    target1  This is the prime target, but not the default
    target2  This is the default target but not because I said it here
    target4  This is target #4, but there's no target3
Default target: target2
$
别靠近我心 2024-10-10 18:43:18

此功能适用于 Windows 上的 Cygwin bash 环境

我一直使用 Cygwin。不知道也没有启用此功能。但我在按照该链接所述更新我的个人资料后刚刚尝试过:

$ ant t<TAB>est<TAB>
test    test_1  test_2  test_3
$ ant test

我不认为 cmd.exe 支持这种类型 可自定义的命令完成

我无法回答是否可以使用 PowerShell 做类似的事情。

顺便说一句,“ant -p[rojecthelp]”是在构建文件中打印目标(设置了描述属性)的典型方法。而不是编写默认目标来执行此操作。

This feature works in the Cygwin bash environment on Windows.

I use Cygwin all the time. Didn't know about and hadn't enabled this feature. But I tried it just now after updating my profile as described in that link:

$ ant t<TAB>est<TAB>
test    test_1  test_2  test_3
$ ant test

I don't think that cmd.exe supports this kind of customizable command completion.

Whether you could do something like it with PowerShell is a question I can't answer.

BTW, "ant -p[rojecthelp]" is the typical way to print the targets (which have description attribute set) in your build file. Rather than writing a default target to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文