Credit: https://github.com/fritzone/lxf-shell
Part Seven!
Final part next issue, subscribe on page 16!
Part Seven!
Final part next issue, subscribe on page 16!
OUR EXPERT
Ferenc Deák
feels this project is his Sistine Chapel, only with less of the Pope shouting at him and more Mancunian editors.
QUICK UP Discover the full project and much more at its GitHub site: https://github. com/fritzone/lxf-shell
Command line completion is like having a butler in
the terminal, ready to anticipate your every command and whisk it into action with a few keystrokes. It’s a bit like magic. Type a snippet of a command or file path, press Tab, and voilà! The rest appears as if summoned by a wizard’s incantation. Or by a few lines of code hidden in plain sight, like we will present in this iteration of our shell saga.
Command line completion comes in two flavours: Tab completion: The old faithful. Just tap the Tab key, and our shell does its best to complete your command or file path faster than you can say, “Abracadabra.” If there’s more than one possibility, just stress the Tab key a little bit more, and it circles through all the available commands or directories.
Option completion:
Think of this as the fancier cousin of Tab completion. Tap Tab twice very quickly after you have entered a command, and a menu appears, like a delightful spread at a dinner party, offering a selection of completion options upon which to feast your eyes.
Classical Tab completion
1
The easiest and most widely supported by current shells of these two different completion mechanisms is the classical Tab completion, which enables users to complete the current command line with a single press of the Tab key with the most appropriate command that can be guessed from the context of the typed-in sequence. However, even in this simple scenario, we have to consider several alternatives:
1.
The user typed in a partial sequence of a command, which is matched upon a list of the commands that are available at that certain location. This location, however, must also include all the directories in the PATH environment variable.
The Fish shell showing off its skills with its own options autocomplete, complete with descriptions.
2.
The user typed in a directory name, then pressed Tab after it. This would give an indication to our shell that it needs to enumerate all the files in that
specific directory and offer them within the Tab completion options.
3.
The user typed in a partial command, preceded by a relative or absolute directory. In this case, we need to identify all the possible completions in the directory, and cycle through them accordingly.