Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:30:24+00:00 2026-05-14T08:30:24+00:00

I’d like to write small scripts which feature incremental search (find-as-you-type) on the command

  • 0

I’d like to write small scripts which feature incremental search (find-as-you-type) on the command line.

Use case: I have my mobile phone connected via USB, Using gammu –sendsms TEXT I can write text messages. I have the phonebook as CSV, and want to search-as-i-type on that.

What’s the easiest/best way to do it? It might be in bash/zsh/Perl/Python or any other scripting language.

Edit:
Solution: Modifying Term::Complete did what I want. See below for the answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:30:25+00:00Added an answer on May 14, 2026 at 8:30 am

    Following Aiden Bell’s hint, I tried Readline in Perl.
    Solution 1 using Term::Complete (also used by CPAN, I think):

    use Term::Complete;   
    my $F; 
    open($F,"<","bin/phonebook.csv"); 
    my @terms = <$F>; chomp(@terms); 
    close($F);
    
    
    my $input;
    while (!defined $input) {
       $input = Complete("Enter a name or number: ",@terms);
       my ($name,$number) = split(/\t/,$input);
       print("Sending SMS to $name ($number).\n");
       system("sudo gammu --sendsms TEXT $number");
    }
    

    Press \ to complete, press Ctrl-D to see all possibilities.

    Solution 2: Ctrl-D is one keystroke to much, so using standard Term::Readline allows completion and the display off possible completions using only \.

    use Term::ReadLine;
    
    my $F;
    open($F,"<","bin/phonebook.csv");
    my @terms = <$F>; chomp(@terms);
    close($F);
    
    my $term = new Term::ReadLine;
    $term->Attribs->{completion_function} = sub { return @terms; };
    
    my $prompt = "Enter name or number >> ";
    
    my $OUT = $term->OUT || \*STDOUT;
    while ( defined (my $input = $term->readline($prompt)) ) {
       my ($name,$number) = split(/\t/,$input);
       print("Sending SMS to $name ($number).\n");
       system("sudo gammu --sendsms TEXT $number");
    }
    

    This solution still needs a for completion.

    Edit: Final Solution
    Modifying Term::Complete (http://search.cpan.org/~jesse/perl-5.12.0/lib/Term/Complete.pm) does give me on the fly completion.

    Source code: http://search.cpan.org/CPAN/authors/id/J/JE/JESSE/perl-5.12.0.tar.gz
    Solution number 1 works with this modification. I will put the whole sample online somewhere else if this can be used by somebody

    Modifications of Completion.pm (just reusing it’s code for Control-D and \ for each character):

    170c172,189

            my $redo=0;
    
                    @match = grep(/^\Q$return/, @cmp_lst);
                    unless ($#match < 0) {
                        $l = length($test = shift(@match));
                        foreach $cmp (@match) {
                            until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
                                $l--;
                            }
                        }
                        print("\a");
                        print($test = substr($test, $r, $l - $r));
                              $redo = $l - $r == 0;
                              if ($redo) { print(join("\r\n", '', grep(/^\Q$return/, @cmp_lst)), "\r\n"); }
                        $r = length($return .= $test);
                    }
                        if ($redo) { redo LOOP; } else { last CASE; }
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.