문제

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.

도움이 되었습니까?

해결책

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 &quot;ant -p&quot; command and show all described
         targets. The "&quot;" 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
$

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top