Cod It is a new command line completion daemon written in Go for Bash and Zsh. The tool can detect
--help Generate auto-completion for commands that do not support auto-completion.
Command-line completion (tab completion/auto-completion) is a common feature in the command-line interpreter, in which, when the completion key (usually Tab) is pressed, the program will automatically fill in some of the commands entered. By using it, common commands can be accessed with fewer keystrokes, and commands/file names with long names or names that are difficult to spell can be easily and automatically completed.
The elements that can be completed are not only commands and file names, but also command parameters, which is exactly what Cod does. It parses the output
--help Used for a specific command, and based on this command, it generates automatic completion for the Bash or Zsh shell. Some commands already support the automatic completion of parameters (for example,
ls -Types of
ls --fu then press
Tab automatic completion
ls --full-time), but some people are unwilling, and Cod can help in this situation.
Cod supports Zsh on macOS and Linux, and only supports Bash on Linux. Bash on macOS is not supported because according to the description of the Cod project, the version of Bash bundled with macOS is too old, and Cod does not support it. There is no mention of Windows in the project description, and no Windows binaries, so it may not support Windows, but I’m not sure because I don’t use Windows.
How cod works
|Demonstration terminal record, showing how Cod adds the auto-completion function to the scrcpy command (the auto-completion function is not available by default)|
When you visit
--help For a program/command, Cod will detect it and ask if it should learn this command. If you allow, Cod will resolve
--help Output and use it to complete the parameters of the command in the future.
For special cases where Cod cannot detect that you have invoked command help, please use Cod
learn To learn it, let’s look at a real example: scrcpy (this can be seen in the demo terminal with a few lines recorded above). This is a tool that displays the Android device screen on the desktop and remotely controls it. The scrcpy command has many options/parameters, such as
--window-borderless, And more features, but there is no built-in auto-complete function support.
To let Cod learn scrcpy command options/parameters, let’s run:
When running with
--help Parameter, Cod asks whether it should learn the command:
┌──> /usr/bin/scrcpy --help └─── cod: learn this command? [yn?] > y cod: learned completions: "--always-on-top" "-b" and 35 more
y Let it learn this command.
Now that Cod has learned the command parameters, let’s try it. Types of
In the terminal, then press
Tab. The parameter should be automatically filled as
--always-on-topYou might also like: Bash’s incomplete path expansion (complete)
Except as already mentioned
learn Subcommand, cod has some other options, for example
update (Update known commands),
list (List known commands) and so on. This is the Cod help/usage screen:
usage: cod  [ ...] Shell autocomplete generator based on `--help' texts. Flags: --help Show context-sensitive help (also try --help-long and --help-man). --version Show application version. Commands: help [...] learn ... list [...] remove ... update ... init example-config  daemon 
Go to Cod project page More information on how to use and configure it.
You can download the source code and build Cod, or download and install pre-built binaries (for macOS and Linux).
To install the Cod binary file on Linux, extract the cod-Linux.tgz file, open a terminal in the folder where the Cod binary file was extracted, and then use this command to install it to
/usr/local/bin (Make sure this is in your
PATH, Or install it in another location):
sudo install cod /usr/local/bin
You also need to add a line on your computer
~/.zshrc File to source cod:
- For Bash: open
~/.bashrcUse a text editor and add a new line at the end of the file, which contains:
source <(cod init $$ bash)
- For Zsh: open
~/.zshrcUse a text editor and add a new line at the end of the file:
source <(cod init $$ zsh)
Save the file and get the modified file
~/.bashrc (Use the following command:
source ~/.zshrc) File or open a new terminal, Cod is ready to use.