Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In a shell that implements GNU Readline, I can click the key to get a list of possible completions to what I started typing. For example:

C:\>cd P<TAB>
PerfLogs\             Program Files (x86)\  Python27\
Program Files\        ProgramData\

How can I now choose which completion I wish to use?

I know that If I want "Program Files" in the above example, I can type in "rogram Files", but I'm lazy :).

Isn't there some way for me to hit a keyboard shortcut that will iterate through the possible completions so I can quickly choose one? Something similar to auto-completion / intellisense in modern IDEs?

Edit: Might my solution be to use GNU Readline's menu-complete command (described below)? But how do I bind it to a key combination?

menu-complete ()

    Similar to complete, but replaces the word to be completed with a single match
from the list of possible completions. Repeated execution of menu-complete steps 
through the list of possible completions, inserting each match in turn. At the end of 
the list of completions, the bell is rung (subject to the setting of bell-style) and 
the original text is restored. An argument of n moves n positions forward in the list 
of matches; a negative argument may be used to move backward through the list. This 
command is intended to be bound to TAB, but is unbound by default. 
share|improve this question
1  
You could just continue by typing r Tab (which will complete to Program) and then \ Tab to get to Program Files. The \ might be annoying to represent a single space, which is related to the convention to avoid spaces in file names in general. In this case it would in total be six keystrokes to reach Program Files: Pr Tab \ Tab. I'm testing this in Bash; you are obviously on a Windows system, though, but I would guess it works in the same way there. I don't know how to enable "intellisense" like completion. –  Daniel Andersson Aug 3 '13 at 14:05
    
@DanielAndersson Windows tab-complete works differently; each Tab gives you a different option, unlike bash, which requires you to input another character to narrow it down –  tapped-out Aug 3 '13 at 14:11

2 Answers 2

up vote 3 down vote accepted

In a shell that uses readline, you need to bind menu-complete to a key. It is not bound by default, complete is.

To do this, edit ~/.inputrc and add the following:

TAB: menu-complete

This will probably affect all programs that use readline. Use the following to only have this apply to bash:

$if Bash
   TAB: menu-complete
$endif
share|improve this answer
    
Many thanks! Any idea what do I do if I'm on Windows, using clink? :) code.google.com/p/clink –  urig Aug 3 '13 at 14:37
1  
@urig It should use the path in the INPUTRC environment variable, or the file _inputrc in your home directory. See rl_read_init_file in readline/readline/bind.c –  Daniel Beck Aug 3 '13 at 14:45
    
Found it! For clink, the inputrc file is somwhere like: C:\Program Files (x86)\clink\0.3.1\clink_inputrc_base –  urig Aug 3 '13 at 14:46
1  
@urig True -- just wanted to add that. This is what clink sets the INPUTRC environment variable to in clink/clink/dll/rl_env.c. It even appears to ignore any predefined INPUTRC as well, always overriding it. –  Daniel Beck Aug 3 '13 at 14:49

Command-line completion works in two different ways, depending on platform.

Windows (NT and later)

First of all, the Windows command processor (cmd.exe) does not implement GNU Readline. Despite this, it does support tab-completion.

Specifically, cmd.exe utilizes "rotating completion", where each Tab presents a different option.

In your example, pressing Tab would first give you PerfLogs, then Program Files, etc.

bash (and other Unix shells)

Most Unix shells utilize "prompting completion", where, as Daniel said above, you have to input another character to narrow the completion down.

See this section of the linked-above Wikipedia article for more details.

share|improve this answer
    
Thanks, I did not know how Windows handled this. Haven't used the command-line in that context extensively since the actual MS-DOS days. –  Daniel Andersson Aug 3 '13 at 14:26
    
Actually, Windows command line iterates through completion options - This is where I've gotten used to this functionality :) –  urig Aug 3 '13 at 14:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.