bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] programmable completion for "empty" commands


From: Matthias Kramm
Subject: [patch] programmable completion for "empty" commands
Date: Sat, 13 Mar 2004 09:02:59 +0100
User-agent: Mutt/1.4i

Hi All,

I've poked around a bit in bash in an attempt to give me a programmable
completion on a "empty" command line.

That means, if I do

    % bash
    $

and then just press <TAB>, I used to get a pretty useless

    Display all 1783 possibilities? (y or n)

regardless of completion settings.

With some twitching in bashline.c (function attempt_shell_completion()),
I was able to modify this behaviour so that with doing

    complete -F mycompletions ""

and pressing <TAB> on the empty line as above, I get
whatever completions the "mycompletions" function returns.

This is immensly helpful together with menu-completion, as I can then,
with a single keypress (possible-completions), summon a number of often used 
command lines, and execute one of them by pressing the key mapped to
menu-completion a few times.

A patch with the changes I made is attached.  I'd love to hear your opinions
about this.
Any chance of having it included in the standard bash distribution?

Greetings

Matthias


*** bashline.c.old      Sat Mar  6 16:52:44 2004
--- bashline.c  Sat Mar  6 17:57:45 2004
***************
*** 970,976 ****
  
  #if defined (PROGRAMMABLE_COMPLETION)
    /* Attempt programmable completion. */
!   if (!matches && in_command_position == 0 && prog_completion_enabled &&
        (progcomp_size () > 0) && current_prompt_string == ps1_prompt)
      {
        int s, e, foundcs;
--- 970,976 ----
  
  #if defined (PROGRAMMABLE_COMPLETION)
    /* Attempt programmable completion. */
!   if (!matches && (in_command_position == 0 || text[0]==0) && 
prog_completion_enabled &&
        (progcomp_size () > 0) && current_prompt_string == ps1_prompt)
      {
        int s, e, foundcs;
***************
*** 984,990 ****
        s = find_cmd_start (start);
        e = find_cmd_end (end);
        n = find_cmd_name (s);
!       if (e > s)
        prog_complete_matches = programmable_completions (n, text, s, e, 
&foundcs);
        else
        foundcs = 0;
--- 984,990 ----
        s = find_cmd_start (start);
        e = find_cmd_end (end);
        n = find_cmd_name (s);
!       if (e > s || text[0]==0)
        prog_complete_matches = programmable_completions (n, text, s, e, 
&foundcs);
        else
        foundcs = 0;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]