有没有办法在 windows (cmd.exe) 下为 Ant 提供正确的选项卡完成?
我可以编写默认目标以列出所有其他目标,但这与您在 linux 上获得的正确选项卡完成不同。
有没有办法在 windows (cmd.exe) 下为 Ant 提供正确的选项卡完成?
我可以编写默认目标以列出所有其他目标,但这与您在 linux 上获得的正确选项卡完成不同。
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.
BASH 在内置complete
命令中有一个可定制的完成机制。通过编写完整命令的脚本,您可以对几乎任何您能想到的东西进行命令行补全。ant 目标的完成是通过一个名为 Perl shell 脚本完成的,该脚本complete-ant-cmd.pl
位于 Cygwin 的系统范围的 bashrc 文件中。
CMD.exe 没有这种机制,并且它不能扩展到已经内置的内容之外。
正如其他人所提到的,您可以尝试将列出所有目标及其描述的ant -p
or命令。ant --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
$
此功能适用于Windows 上的 Cygwin bash 环境。
我一直在使用 Cygwin。不知道也没有启用此功能。但是我在更新我的个人资料后刚刚尝试过,如该链接中所述:
$ ant t<TAB>est<TAB>
test test_1 test_2 test_3
$ ant test
我不认为 cmd.exe 支持这种可自定义的命令完成。
你是否可以用 PowerShell 做类似的事情是我无法回答的问题。
顺便说一句,“ant -p[rojecthelp]”是在构建文件中打印目标(具有描述属性集)的典型方式。而不是编写默认目标来执行此操作。