HOME

TheInfoList



OR:

Command-line completion (also tab completion) is a common feature of
command-line interpreter A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
s, 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 animation 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 possible completions 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 command/filename with a trailing space. 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 Script may refer to: Writing systems * Script, a distinctive writing system, based on a repertoire of specific elements or symbols, or that repertoire * Script (styles of handwriting) ** Script typeface, a typeface with characteristics of handw ...
s or
batch file Batch may refer to: Food and drink * Batch (alcohol), an alcoholic fruit beverage * Batch loaf, a type of bread popular in Ireland * A dialect term for a bread roll used in North Warwickshire, Nuneaton and Coventry, as well as on the Wirra ...
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.


History

Tab completion showed up early in computing history; one of the first examples appeared in the
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. It was designed as part of Project Genie and marketed by Scientific Data Systems for the S ...
for the SDS 940, 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 A typographical error (often shortened to typo), also called a misprint, is a mistake (such as a spelling mistake) made in the typing of printed (or electronic) material. Historically, this referred to mistakes in manual type-setting (typography). ...
, and so was a mixed blessing. This feature was imitated by Tenex's developers who made an important change: Tenex used "escape recognition", in which the interpreter would not attempt to autocomplete unless the
escape key On computer keyboards, the Esc key (named ''Escape key'' in the international standard series ISO/IEC 9995) is a key used to generate the escape character (which can be represented as ASCII code 27 in decimal, Unicode U+001B, or ). The escape ...
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. The Tenex descendant
TOPS-20 The TOPS-20 operating system by Digital Equipment Corporation (DEC) is a proprietary OS used on some of DEC's 36-bit mainframe computers. The Hardware Reference Manual was described as for "DECsystem-10/DECSYSTEM-20 Processor" (meaning the DEC PDP- ...
moved command line completion from command interpreter to the operating system via the COMND JSYS system call, to make it available to other user applications. From there it was borrowed by Unix.


Example

To open the file with
Firefox Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current ...
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 Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "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 is not the only file in the current directory that starts with "i". The directory also contains files and . 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 eight 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 CMD 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 seven 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 A Unix shell is a command-line Interpreter (computing), interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting langua ...
s, including
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
(the default shell in most
Linux distribution A Linux distribution (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and, often, a package management system. Linux users usually obtain their operating system by downloading one ...
s) and ksh among many others, have a long-standing tradition of advanced and customizable completion capabilities. **
Bash Bash or BASH may refer to: Arts and entertainment * ''Bash!'' (Rockapella album), 1992 * ''Bash!'' (Dave Bailey album), 1961 * '' Bash: Latter-Day Plays'', a dramatic triptych * ''BASH!'' (role-playing game), a 2005 superhero game * "Bash" ('' ...
programmable completion, complete and compgen commands have been available since the beta version of 2.04 in 2000 and offers at least Pathname and filename completion. ** For KornShell 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, you type part of the name, and then ,. ** The
Z shell The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh. History ...
(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 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. **
Tcsh tcsh ( “tee-see-shell”, “tee-shell”, or as “tee see ess aitch”, tcsh) is a Unix shell based on and backward compatible with the C shell (csh). Shell It is essentially the C shell with programmable command-line completion, command-l ...
offers default file, command, and variable name completion activated using . The 'complete' builtin command provides fully programmable completion. The source code comes with a 'complete.tcsh' file containing many examples of its completion syntax. *
Windows PowerShell PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-so ...
, the extensible command shell from Microsoft, which is based on
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
and the
Microsoft .NET The Microsoft .NET strategy is a marketing plan that Microsoft followed in the early 2000s. Steve Ballmer described it as the company's "most ambitious undertaking since Internet Strategy Day in 1995". In support of this strategy, between 2000 and ...
framework, provides powerful and customizable completion capabilities similar to those of traditional Unix shells. *The command processor of
Windows NT Windows NT is a proprietary graphical operating system produced by Microsoft, the first version of which was released on July 27, 1993. It is a processor-independent, multiprocessing and multi-user operating system. The first version of Win ...
-based systems supports basic completion. It is possible to use a separate key-binding for matching directory names only. * enables file and directory name completion characters (^F and ^D by default). Use for more information. *
TweakUI Tweak UI is a free application, released in 1996 by Microsoft for customizing the Microsoft Windows operating system's user interface. Tweak UI modifies the Windows Registry in the same way as a user could edit it manually with a program such a ...
can be used to configure the keys used for file name and directory name completion. *The
MS-DOS MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few ope ...
command processor did not have command-line completion: pressing the tab key would just advance the
cursor Cursor may refer to: * Cursor (user interface), an indicator used to show the current position for user interaction on a computer monitor or other display device * Cursor (databases), a control structure that enables traversal over the records in ...
. However, various enhanced shells for MS-DOS, such as 4DOS, the
FreeDOS FreeDOS (formerly Free-DOS and PD-DOS) is a free software operating system for IBM PC compatible computers. It intends to provide a complete MS-DOS-compatible environment for running legacy software and supporting embedded systems. FreeDOS can ...
version of , or the Enhanced DOSKEY.COM feature Unix-style tab completion. *
Far Manager Far Manager (short for ''File and ARchive Manager'') is an orthodox file manager for Microsoft Windows and is a clone of Norton Commander. Far Manager uses the Win32 console and has a keyboard-oriented user interface (although limited mouse o ...
apart from its file management functions provides
command history Command history is a feature in many operating system shells, computer algebra programs, and other software that allows the user to recall, edit and rerun previous commands. Command line history was added to Unix in Bill Joy's C shell of 1978; ...
and line completion for Windows.


See also

*
Autocomplete Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing. In Android and iOS smartphones, this is called predictive text. In graphical user interfaces, users can typically press the ta ...
*
Command-line interface A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
*
Comparison of command shells A command shell is a command-line interface to interact with and manipulate a computer's operating system. General characteristics Interactive features Background execution Background execution allows a shell to run a command without us ...
*
Shell Shell may refer to: Architecture and design * Shell (structure), a thin structure ** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses ** Thin-shell structure Science Biology * Seashell, a hard o ...


References

{{Reflist


External links


Unix shells


A Bash completion overview - "Working more productively with bash 2.x/3.x" by Ian Macdonald


Windows command interpreters

''(Be sure to check the "Applies to" section in each article)'' *Windows Server 2003:
Directory name completion

Filename completionWindows XPWindows 2000/NT 4
User interface techniques Autocomplete