Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Command-line completion
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Software feature}} [[Image:Command-line-completion-example.gif|right|thumb|402px|Example of command-line completion in [[Bash (Unix shell)|Bash]].]] [[Image:Powershell Intellisense example for the Get-Process cmdlet.gif|right|thumb|402px|Example of command-line completion in [[PowerShell]] with [[Intellisense]].]] '''Command-line completion''' (also '''tab completion''') is a common feature of [[command-line interpreter]]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 {{keypress|Tab}}) to fill in the rest of the item. The user then presses {{keypress|Return}} or {{keypress|Enter}} 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 {{keypress|Tab}} 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|interactive mode]]. That is, it cannot be invoked to complete partially typed commands in [[shell script|script]]s or [[batch file]]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]] 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 [[Typographical error|typos]], and so was a mixed blessing. This feature was imitated by [[TENEX (operating system)|Tenex]]'s developers who made an important change: Tenex used "escape recognition", in which the interpreter would not attempt to autocomplete unless the [[Esc key|escape key]] 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.<ref>{{Cite web|url=http://www.opost.com/dlm/tenex/hbook.html|title=Origins and Development of TOPS-20|website=www.opost.com|access-date=2006-09-10|archive-date=2020-08-01|archive-url=https://web.archive.org/web/20200801165237/http://www.opost.com/dlm/tenex/hbook.html|url-status=dead}}</ref> The Tenex descendant [[TOPS-20]] 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.<ref>[http://kermit.columbia.edu/kermit/dec20/assembler-guide.txt DECSYSTEM-20 Assembly Language Guide]</ref> From there it was borrowed by Unix. ==Example== To open the file {{Mono|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 (Unix shell)|Bash]]. Other command line shells may perform slightly differently. First we type the first three letters of our command: fir Then we press {{keypress|Tab}} 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 {{Mono|introduction-to-command-line-completion.html}} is not the only file in the current directory that starts with "i". The directory also contains files {{Mono|introduction-to-bash.html}} and {{Mono|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 {{keypress|Tab}} it will be completed to the whole filename: firefox introduction-to-command-line-completion.html In short we typed: fir{{keypress|Tab}}i{{keypress|Tab}}c{{keypress|Tab}} 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 (Windows)|CMD]] uses. We follow the same procedure as for prompting completion until we have: firefox i We press {{keypress|Tab}} once, with the result: firefox introduction-to-bash.html We press {{keypress|Tab}} again, getting: firefox introduction-to-command-line-completion.html In short we typed: fir{{keypress|Tab}}i{{keypress|Tab}}{{keypress|Tab}} 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]]s, including [[Bash_(Unix_shell)|Bash]] (the default shell in most [[Linux distribution]]s) and [[KornShell|ksh]] among many others, have a long-standing tradition of advanced and customizable completion capabilities.<ref name="auto">{{Cite web|url=http://www.caliban.org/bash/index.shtml|title=Working more productively with bash 2.x/3.x|website=www.caliban.org}}</ref> ** [[Bash_(Unix_shell)|Bash]] programmable completion, <code>complete</code> and <code>compgen</code> commands<ref>{{Cite web|url=https://tiswww.case.edu/php/chet/bash/bashref.html#Programmable-Completion|title=Bash Reference Manual|website=tiswww.case.edu}}</ref> have been available since the beta version of 2.04<ref name="auto"/> in 2000<ref>{{Cite web|url=https://ftp.swin.edu.au/gnu/bash/|title=Index of /gnu/bash|website=ftp.swin.edu.au}}</ref> 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 {{keypress|Escape}},{{keypress|\}}. If EDITOR is set to [[Emacs]], you type part of the name, and then {{keypress|Escape}},{{keypress|Escape}}. ** The [[Z shell]] (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 {{kbd|tar xzf {{keypress|Tab}}}} 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]] offers default file, command, and variable name completion activated using {{keypress|Tab}}. 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]], the extensible command shell from Microsoft, which is based on [[object-oriented programming]] and the [[Microsoft .NET]] framework, provides powerful and customizable completion capabilities similar to those of traditional Unix shells.<ref>{{Cite web|url=http://thepowershellguy.com/blogs/posh/archive/2007/06/02/powertab-flash-exampes.aspx|title=The PowerShell Guy|website=thepowershellguy.com}}</ref><ref>{{Cite web|url=http://thepowershellguy.com/blogs/posh/pages/powertab.aspx|title=The PowerShell Guy|website=thepowershellguy.com}}</ref>{{Citation needed|date=June 2008}}{{^|the examples given are neither RS, nor suitable presentation to support the comment}} *The {{Mono|[[cmd.exe]]}} command processor of [[Windows NT]]-based systems supports basic completion. It is possible to use a separate key-binding for matching directory names only. *{{kbd|[[cmd.exe]] /F:ON}} enables file and directory name completion characters (^F and ^D by default). Use {{kbd|[[cmd.exe]] /?}} for more information. *[[TweakUI]] can be used to configure the keys used for file name and directory name completion.<ref>{{Cite web|url=https://www.microsoft.com/en-us/research/people/simonpj/|title=Simon Peyton Jones at Microsoft Research|website=[[Microsoft]] }}</ref> *The [[MS-DOS]] command processor {{Mono|[[COMMAND.COM]]}} did not have command-line completion: pressing the tab key would just advance the [[cursor (computers)|cursor]]. However, various enhanced shells for MS-DOS, such as [[4DOS]], the [[FreeDOS]] version of {{Mono|COMMAND.COM}}, or the Enhanced [[DOSKEY.COM]] feature Unix-style tab completion. *[[Far Manager]] apart from its file management functions provides [[command history]] and line completion for Windows. ==See also== *[[Autocomplete]] *[[Command-line interface]] *[[Comparison of command shells]] *[[Shell (computing)|Shell]] ==References== {{Reflist}} ==External links== ===Unix shells=== *[http://www.caliban.org/bash/ A Bash completion overview - "Working more productively with bash 2.x/3.x" by Ian Macdonald] *[http://zsh.sourceforge.net/Doc/Release/Completion-System.html The zsh completion system, chapter from the Z Shell Manual] *[https://web.archive.org/web/20150215141808/http://www.tcsh.org/tcsh.html/Completion_and_listing.html Completion and listing from the TCSH Manual] ===Windows command interpreters=== ''(Be sure to check the "Applies to" section in each article)'' *Windows Server 2003: *#[https://web.archive.org/web/20070301005158/http://technet2.microsoft.com/WindowsServer/en/Library/0a3f5948-84f2-4531-b74a-04dd94227c8d1033.mspx Directory name completion] *#[https://web.archive.org/web/20070228004411/http://technet2.microsoft.com/WindowsServer/en/Library/f0326a26-8ff7-421c-ba8a-4c9ca945e21f1033.mspx Filename completion] *[http://support.microsoft.com/?kbid=310530 Windows XP] *[http://support.microsoft.com/?kbid=244407 Windows 2000/NT 4] [[Category:User interface techniques]] [[Category:Autocomplete]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite web
(
edit
)
Template:Kbd
(
edit
)
Template:Keypress
(
edit
)
Template:Mono
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:^
(
edit
)