Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 99879 invoked from network); 9 Nov 2001 01:46:28 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 9 Nov 2001 01:46:28 -0000 Received: (qmail 23970 invoked by uid 97); 9 Nov 2001 01:36:48 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 23949 invoked by uid 97); 9 Nov 2001 01:36:47 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 23930 invoked from network); 9 Nov 2001 01:36:47 -0000 To: ant-dev@jakarta.apache.org Subject: [CONTRIB] Antifying bash? and now Z-Shell too! References: <200110200802.f9K82VWt020279@sm14.texas.rr.com> <20011022104136.A6270@collab.net> <3BDB1D56.693DDFF5@progress.com> <3BE49D4C.D2291469@progress.com> From: Mike Williams Date: 09 Nov 2001 12:36:31 +1100 In-Reply-To: <3BE49D4C.D2291469@progress.com> Message-ID: Lines: 22 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N >>> On Sat, 03 Nov 2001 20:43:40 -0500, >>> "Bill" == "Bill Burton" wrote: Bill> Thanks for posting this program. I was able to figure out how to Bill> configure Z-Shell to use it. Great! I'm happy that it works for both bash and zsh. Bill> Other than updating the comments at the top, only one line of code Bill> was added to strip CR's after each target so it would work with zsh Bill> on Cygwin. Thanks Bill. I've tidied up the comments a bit more, and fixed a bug that caused some targets to be missed. See attached. -- cheers, Mike "You live and learn. At any rate, you live." -- Douglas Adams --=-=-= Content-Type: application/x-perl Content-Disposition: attachment; filename=complete-ant-cmd.pl #!/usr/bin/perl # # A script to allow Bash or Z-Shell to complete an Ant command-line. # # To install for Bash 2.0 or better, add the following to ~/.bashrc: # # $ complete -C complete-ant-cmd ant build.sh # # To install for Z-Shell 2.5 or better, add the following to ~/.zshrc: # # function ant_complete () { # local args_line args # read -l args_line # set -A args $args_line # set -A reply $(COMP_LINE=$args_line complete-ant-cmd ${args[1]} $1) # } # compctl -K ant_complete ant build.sh # # @author Mike Williams my $cmdLine = $ENV{'COMP_LINE'}; my $antCmd = $ARGV[0]; my $word = $ARGV[1]; my @completions; if ($word =~ /^-/) { list( restrict( $word, getArguments() )); } elsif ($cmdLine =~ /-(f|buildfile)\s+\S*$/) { list( getBuildFiles($word) ); } else { list( restrict( $word, getTargets() )); } exit(0); sub list { for (@_) { print "$_\n"; } } sub restrict { my ($word, @completions) = @_; grep( /^\Q$word\E/, @completions ); } sub getArguments { qw(-buildfile -debug -emacs -f -find -help -listener -logfile -logger -projecthelp -quiet -verbose -version); } sub getBuildFiles { my ($word) = @_; grep( /\.xml$/, glob( "$word*" )); } sub getTargets { # Look for build-file my $buildFile = 'build.xml'; if ($cmdLine =~ /-(f|buildfile)\s+(\S+)/) { $buildFile = $2; } return () unless (-f $buildFile); # Run "ant -projecthelp" to list targets. Keep a cache of results in a # cache-file. my $cacheFile = $buildFile; $cacheFile =~ s|(.*/)?(.*)|${1}.ant-targets-${2}|; if ((!-e $cacheFile) || (-M $buildFile) < (-M $cacheFile)) { open( CACHE, '>'.$cacheFile ) || die "can\'t write $cacheFile: $!\n"; open( HELP, "$antCmd -projecthelp -f '$buildFile'|" ) || return(); my %targets; while( ) { if (/^\s+(\S+)/) { $targets{$1}++; } } my @targets = sort keys %targets; for (@targets) { print CACHE "$_\n"; } return @targets; } # Read the target-cache open( CACHE, $cacheFile ) || die "can\'t read $cacheFile: $!\n"; my @targets; while () { chop; s/\r$//; # for Cygwin push( @targets, $_ ); } close( CACHE ); @targets; } --=-=-= Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: --=-=-=--