Command line completion
Encyclopedia
Command line completion (also tab completion) is a common feature of command line interpreters, in which the program automatically fills in partially typed commands.

Command line interpreters are programs that allow a user to interact with the underlying operating system by typing commands at a command prompt using a command line interface (CLI), in contrast to pointing and clicking a mouse in a Graphical User Interface (GUI). Command line completion allows the user to type the first few characters of a command, program, or filename, and press a completion key (normally ) to fill in the rest of the item. The user then presses or to run the command or open the file.

Command line completion is useful in several ways, as illustrated by the animated image accompanying this article. Commonly-accessed commands, especially ones with long names, require fewer keystrokes to reach. Commands with long or difficult to spell filenames can be entered by typing the first few characters and pressing a completion key, which completes the command or filename. In the case of multiple possible completions, some command-line interpreters, especially Unix shells, will list all filenames beginning with those few characters. The user can type more characters and press again to see a new, narrowed-down list if the typed characters are still ambiguous, or else complete the filename. An alternate form of completion rotates through all matching results when the input is ambiguous.

Completable elements may include commands, arguments, file names and other entities, depending on the specific interpreter and its configuration. Command line completion generally only works in interactive mode. That is, it cannot be invoked to complete partially typed commands in script
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

s or batch file
Batch file
In DOS, OS/2, and Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter....

s, even if the completion is unambiguous. The name tab completion comes from the fact that command line completion is often invoked by pressing the tab key
Tab key
Tab key on a keyboard is used to advance the cursor to the next tab stop.- Origin :The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form"...

.

History

Tab completion showed up early in computing history; one of the first examples appeared in the Berkeley Timesharing System
Berkeley Timesharing System
The Berkeley Timesharing System was a pioneering time-sharing operating system implemented between 1964 and 1967 at the University of California, Berkeley...

 for the SDS 940
SDS 940
The SDS 940 was Scientific Data Systems' first machine designed to support time sharing directly, and was based on the SDS 930's 24-bit CPU built primarily of integrated circuits. It was announced in February 1966 and shipped in April, becoming a major part of Tymshare's expansion during the 1960s...

, where if a typed string were ambiguous, the interpreter would do nothing, but if the string was not ambiguous, it would automatically complete it without any command from the user. This feature did not work well with the all too frequent typos
Typographical error
A typographical error is a mistake made in, originally, the manual type-setting of printed material, or more recently, the typing process. The term includes errors due to mechanical failure or slips of the hand or finger, but usually excludes errors of ignorance, such as spelling errors...

, and so was a mixed blessing. This feature was imitated by Tenex
TOPS-20
The TOPS-20 operating system by Digital Equipment Corporation was the second proprietary OS for the PDP-10 mainframe computer. TOPS-20 began in 1969 as the TENEX operating system of Bolt, Beranek and Newman...

's developers who made an important change: Tenex used "escape recognition", in which the interpreter would not attempt to autocomplete unless the escape key
Esc key
On computer keyboards, the Esc key is a key labeled Esc or Escape that is used to generate the ASCII Escape character , the character code traditionally used to initiate an escape sequence...

 was struck (thus the name) by the user. The domain was also expanded from only program names on the Berkeley system to both program names and files on Tenex. From there it was borrowed by Unix.

Example

To open the file introduction-to-command-line-completion.html with Firefox one would type:

firefox introduction-to-command-line-completion.html

This is a long command to type. Instead we can use command line completion.

Prompting completion

The following example shows how command line completion works in bash. Other command line shells may perform slightly differently.

First we type the first three letters of our command:

fir

Then we press and because the only command in our system that starts with "fir" is "firefox", it will be completed to:

firefox

Then we start typing the file name:

firefox i

But this time introduction-to-command-line-completion.html is not the only file in the current directory that starts with "i". The directory also contains files introduction-to-bash.html and introduction-to-firefox.html. The system can't decide which of these filenames we wanted to type, but it does know that the file must begin with "introduction-to-", so the command will be completed to:

firefox introduction-to-

Now we type "c":

firefox introduction-to-c

After pressing it will be completed to the whole filename:

firefox introduction-to-command-line-completion.html

In short we typed:

firic

This is just 8 keystrokes, which is considerably less than 52 keystrokes we would have needed to type without using command line completion.

Rotating completion

The following example shows how command line completion works with rotating completion, such as Windows's Command Prompt
Command Prompt
Command Prompt is the Microsoft-supplied command-line interpreter on OS/2, Windows CE and on Windows NT-based operating systems...

 uses.

We follow the same procedure as for prompting completion until we have:

firefox i

We press once, with the result:

firefox introduction-to-bash.html

We press again, getting:

firefox introduction-to-command-line-completion.html

In short we typed:

firi

This is just 7 keystrokes, comparable to prompting-style completion. This works best if we know what possibilities the interpreter will rotate through.

Completion in different command line interfaces

  • Unix shell
    Unix shell
    A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems...

    s, including bash (the default shell in Linux
    Linux
    Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

     and Mac OS X
    Mac OS X
    Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

    ) and ksh
    Ksh
    KSH or ksh may refer to:*Kenyan shilling, the currency of Kenya*Korn shell, a Unix shell developed by David Korn in the early 1980s*Kölsch language , a Ripuarian dialect spoken in Germany, the Hungarian Central Statistical Office*Shahid Ashrafi Esfahani Airport , in Kermanshah, Iran...

     among many others, have a long-standing tradition of advanced and customizable completion capabilities (see the external links section below for some examples).
    • For Korn shell users, file name completion depends on the value of the EDITOR variable. If EDITOR is set to vi, you type part of the name, and then ,. If EDITOR is set to emacs
      Emacs
      Emacs is a class of text editors, usually characterized by their extensibility. GNU Emacs has over 1,000 commands. It also allows the user to combine these commands into macros to automate work.Development began in the mid-1970s and continues actively...

      , you type part of the name, and then ,.
    • The Z shell
      Z shell
      The Z shell is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting...

       (zsh) pioneered the support for fully programmable completion, allowing users to have the shell automatically complete the parameters of various commands unrelated to the shell itself, which is accomplished by priming the shell with definitions of all known switches as well as appropriate parameter types. This allows the user to e.g. type tar xzf and have the shell complete only tarred gzip archives from the actual filesystem, skipping files which are incompatible with the input parameters. A modern zsh installation comes with completion definitions for over five hundred commands.
  • Windows PowerShell
    Windows PowerShell
    Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework...

    , the extensible command shell from Microsoft, which is based on object-oriented programming
    Object-oriented programming
    Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

     and the Microsoft .NET framework provides powerful and customizable completion capabilities similar to those of traditional Unix shells.
  • The cmd.exe
    Cmd.exe
    Command Prompt is the Microsoft-supplied command-line interpreter on OS/2, Windows CE and on Windows NT-based operating systems...

    command processor of Windows NT
    Windows NT
    Windows NT is a family of operating systems produced by Microsoft, the first version of which was released in July 1993. It was a powerful high-level-language-based, processor-independent, multiprocessing, multiuser operating system with features comparable to Unix. It was intended to complement...

    -based systems supports basic completion. It is possible to use a separate key-binding for matching directory names only.
  • cmd.exe
    Cmd.exe
    Command Prompt is the Microsoft-supplied command-line interpreter on OS/2, Windows CE and on Windows NT-based operating systems...

     /F:ON
    enables file and directory name completion characters (^F and ^D by default). Use cmd.exe
    Cmd.exe
    Command Prompt is the Microsoft-supplied command-line interpreter on OS/2, Windows CE and on Windows NT-based operating systems...

     /?
    for more info.
  • TweakUI
    TweakUI
    Tweak UI is a free user interface customization application first released by Microsoft in 1996 to aid end users in customizing the Microsoft Windows operating system. By itself, it does not do anything that would not otherwise be possible...

     can be used to configure the keys used for file name and directory name completion.
  • The MS-DOS
    MS-DOS
    MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...

     command processor COMMAND.COM
    COMMAND.COM
    COMMAND.COM is the filename of the default operating system shell for DOS operating systems and the default command line interpreter on Windows 95, Windows 98 and Windows Me...

    did not have command line completion: pressing the tab key would just advance the cursor
    Cursor (computers)
    In computing, a cursor is an indicator used to show the position on a computer monitor or other display device that will respond to input from a text input or pointing device. The flashing text cursor may be referred to as a caret in some cases...

    . Before the release of Windows
    Microsoft Windows
    Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

     however, various enhanced shells for MS-DOS, such as 4DOS
    4DOS
    4DOS is a command line interpreter by JP Software, designed to replace the default command interpreter COMMAND.COM in DOS and Windows 95/98/Me. The 4DOS family of programs are meant to replace the default command processor. 4OS2 and 4NT replace CMD.EXE in OS/2 and Windows NT respectively...

    , or the FreeDOS
    FreeDOS
    FreeDOS is an operating system for IBM PC compatible computers. FreeDOS is made up of many different, separate programs that act as "packages" to the overall FreeDOS Project...

     version of COMMAND.COM, featured Unix-style tab completion.

See also

  • Autocomplete
    Autocomplete
    Autocomplete is a feature provided by many web browsers, e-mail programs, search engine interfaces, source code editors, database query tools, word processors, and command line interpreters. Autocomplete involves the program predicting a word or phrase that the user wants to type in without the...

  • Command line interface
  • Comparison of computer shells
    Comparison of computer shells
    A command shell is a command line interface computer program to an operating system.- General characteristics :- Interactive features :- Programming features :- Syntax :- Data types :- String and filename matching :...

  • Shell
    Shell (computing)
    A shell is a piece of software that provides an interface for users of an operating system which provides access to the services of a kernel. However, the term is also applied very loosely to applications and may include any software that is "built around" a particular component, such as web...


Unix shells


Windows command interpreters

(Be sure to check the "Applies to" section in each article)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK