Contents
- 1 What should the first line of a zsh completion file look like?
- 2 How to tell zsh which function to use for completing a command?
- 3 Where do I find zsh completions in Ubuntu?
- 4 Why is the host name included in zsh?
- 5 How to force file completion everywhere in zshrc?
- 6 How to get zsh to match all directories?
What should the first line of a zsh completion file look like?
The first line of a completion function file can look something like this: This tells zsh that the file contains code for completing the foobar command. This is the format that you will use most often for the first line, but you can also use the same file for completing several different functions if you want.
How to tell zsh which function to use for completing a command?
You can also use the compdef command directly (e.g. in your ~/.zshrc file) to tell zsh which function to use for completing a command like this: or to use the same completions for several commands: or if you want to supply arguments:
How to make zsh not remove-V from the suggestions?
To make zsh not remove -v from the suggestions, if it has already been given, simply add a star in the right place. When an option, such as –file-of-filenames takes a path as an argument, zsh should provide the user with a list of applicable files.
Is there a separator for getopt in zsh?
By default, zsh assumes that an option has to be whitespace separated from its argument. Given a + there can also be no separation, and an = allows for an equality sign. Furthermore, getopt allows short option stacking and — as a separator.
Where do I find zsh completions in Ubuntu?
For an Ubuntu package, the appropriate place is /usr/share/zsh/vendor-completions. For something installed under /usr/local, that’s /usr/local/share/zsh/site-functions. That’s all you need to do. The one thing that isn’t transparent is if you need to change the #compdef line in an upgrade, or if you remove or rename some files.
Why is the host name included in zsh?
The host name is included for the sake of people whose home directory is shared between machines and who may have different software installed on different machines. The zsh version is included because the cache file is incompatible between versions (it includes code that changes from version to version).
How to make custom zsh completions in Ubuntu?
.zcompdump is a cache file used by compinit. ~/.zcompdump is the default location; you can choose a different location when running compinit. Oh-my-zsh calls compinit with the -d option to use a different cache file name given by the variable ZSH_COMPDUMP, which defaults to
Where are the completion functions for commands stored?
Completion functions for commands are stored in files with names beginning with an underscore _, and these files should be placed in a directory listed in the $fpath variable. You can add a directory to $fpath by adding a line like this to your ~/.zshrc file: The first line of a completion function file can look something like this:
How to force file completion everywhere in zshrc?
In the completion function, one route would be to cut out the current word I want to complete, complete it, and then re-insert the completion back into the line if that’s possible. It could also be more like _precommand which shifts the second word to the first word so that normal command completion works.
How to get zsh to match all directories?
What this does is tell zsh to match any number of directories to any depth, including the current directory. To find all the (*.sh) and (*.py) files in the current directory and sub-directories in a list suitable for parsing (i.e., perhaps in a script), you would use:
When to use Extended Globbing characters in zsh?
If you do decide to use extended globbing, be aware of special characters in file names and the need to quote them. For instance, if you want to copy files from a remote site using scp, you don’t want zsh to expand any wildcards locally; you want that wildcard passed to scp for files on the remote end to match, so instead of:
What happens if there are no matches in zsh?
If there are no matches, zsh will return an error; if there is nothing to pass to the ls program (or any other program), the program will not even be called by zsh. There are other useful patterns, such as the (**/) pattern.