It ain't complete (only finds complete words, not a list of incomplete words), but I did test it a bit.

It autocompletes on qw(one two three four five six seven).

It's entirely perl. I tested it on Solaris, and although I didn't test it on windows, it should work (i re-used code that i had tested on windows).

[~] perl -e 'use GetWord;$a=Get_Word();print"$a\n";' Enter command > abc your command was abc [~] perl -e 'use GetWord;$a=Get_Word();print"$a\n";' Enter command > o<tab> ->auto generated->one [~] perl -e 'use GetWord;$a=Get_Word();print"$a\n";' Enter command > tw<tab> ->auto generated->two
This is GetWord code (partly taken from the Get_Password CPAN module, and partly from the camel book).

I'm going to use readmore tags, but i'm never sure if it works, so if they don't, i apologize in advance.

#/usr/bin/perl package GetWord; use Carp; our @ISA = qw(Exporter); our $VERSION = 1.001; my $get_rid_of_warning = $VERSION; our @EXPORT = qw( Get_Word ); sub Get_Word { my @valid_commands = qw(one two three four five six seven); my $flush = $|; $| = 1; # flush output to screen byte by byte my $pass = ""; my $bs = "\b"; print "Enter command > "; while (1) { my $ch = getone(); # Return character, end of getting word $ch =~ /[\r\n]/ && do { print "\n"; $| = $flush; # return to previous setting print "\nyour command was $pass\n"; return; }; # Backspace/delete key entered $ch =~ /[\b\x7F]/ && do { if ( length($pass) > 0 ) { chop $pass; print ("$bs"," ",$bs) x length($pass),$bs," ",$bs, "$p +ass"; } next; }; # tab key entered $ch =~ /[\t]/ && do { my $num = (my @res = grep {/^$pass/} @valid_commands); if ($num == 1) { print "<tab>\n"; print "->auto generated->$res[0]\n"; return; } next; }; # Warn for non-ascii characters if ( ord($ch) < 32 ) { print "\7"; next; } # Valid character enetered $pass .= $ch; print $ch; } } # ==================================================================== +======== # Terminal I/O program to get un-echoed unbuffered input # # Take from the Camel Book (3rd edition) # (Programming Perl, Larry Wall, O'Reilly), p.906 # ==================================================================== +======== BEGIN { use POSIX ":termios_h"; my ( $term, $oterm, $echo, $noecho, $fd_stdin ); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON; $noecho = $oterm & ~$echo; sub cbreak { $term->setlflag($noecho); $term->setcc( VTIME, 1 ); $term->setattr( $fd_stdin, TCSANOW ); } sub cooked { $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); } sub getone { my $key = ""; cbreak(); sysread( STDIN, $key, 1 ); cooked(); return $key; } } END { cooked() }

In reply to Re: Tab completion on the command line by Sandy
in thread Tab completion on the command line by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.