zsh " /> zsh "> Paket shell completion for <a href="http://zsh.org/">zsh</a> | Paket
Logo Paket

Paket shell completion for zsh

Installation

Download

  1. Download the paket-completion.zsh file to a subdirectory of your home directory, preferably a directory with other function files.
  2. Rename it to _paket.
  3. Add the directory to your zsh fpath before running compinit.
$ target="$HOME/.zsh-completions"
$ mkdir "$target"
$ curl --fail --location --proto-redir -all,https --output "$target/_paket" \
  https://raw.githubusercontent.com/fsprojects/Paket/master/completion/paket-completion.zsh

In your ~/.zshrc:

fpath=($HOME/directory/where/_paket/resides $fpath)

Updating an existing installation

Just repeat the download from above.

Alternatively the completion script comes bundled with the paket-completion-update function that will download the current paket-completion.zsh to the same file as above, even if you changed its location after the initial download.

Please note: The paket-completion-update function requires curl to be installed. paket-completion-update is only available after your first paket completion per shell session (i.e. after the Paket completion functions have been autoloaded by zsh).

paket-completion-update supports an optional first parameter that allows you to override the default download root URL which is https://raw.githubusercontent.com/fsprojects/Paket/master/completion.

paket alias

Paket is a .NET tool. When it is a local tool of the repository, it is advised to create an alias and always run Paket from the repository root.

Somewhere in your ~/.zshrc:

alias paket='dotnet paket'

Also ensure that zsh completes aliases based on the expanded alias contents.

unsetopt completealiases

If you don't like alias completion, define that the paket alias should be completed using the _paket function defined in the _paket file.

setopt completealiases
compdef _paket paket

Configuration

You can configure some aspects of Paket completion. Add these to your ~/.zshrc.

Define where to look for paket

Depending on what should be completed the Paket executable will be run by the completion script. The completion script searches for Paket installed with dotnet tool install paket --tool-path .paket first, then for a local tool of ./.config/dotnet-tools.json (run with dotnet paket), then for a global tool (i.e. paket in the $PATH).

To override the list of possible locations for Paket installed with --tool-path, define the following paket-executable style. The list of values will be searched as defined.

# This is the default.
zstyle ':completion::complete:paket:*' paket-executable './.paket/paket'
# Useful for Paket developers: Prefer the locally built version in bin over the one in .paket.
zstyle ':completion::complete:paket:*' paket-executable './bin/net10.0/paket' './.paket/paket'

Enable infix matching for package IDs

By default paket find-packages will match infixes, which is not the default mode for Paket completion. I think it's unnatural to type

paket add FAK<tab>

which will be completed to

paket add Altairis.Fakturoid.Client

if infix matching is enabled.

If you want this behavior, enable infix matches:

zstyle ':completion::complete:paket:*' infix-match yes
zstyle ':completion::complete:paket:add:*' infix-match yes # Only for paket add.

Disable fallback (i.e. default zsh) completion for Paket commands that do not have a completion function

zstyle ':completion::complete:paket:*' use-fallback no

Disable verbose completion of main commands

zstyle ':completion::complete:paket:*' verbose no

Define the zsh completion cache policy for expensive operations that generate completions

Paket will e.g. issue HTTP requests when you complete a package ID or a version number. These take time so we take advantage of the zsh completion cache and store such results.

Enable the zsh completion cache globally, including completions for other commands that also leverage caching:

zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path instead/of/$HOME/.zcompcache # Optional.

To disable the cache for specific Paket commands to always get fresh results when completing e.g. paket add:

zstyle ':completion::complete:paket:add:*' use-cache off

The caches are stored under the cache-path as follows:

<cache-path>/paket/<expensive command>/<parameter>

e.g. <cache-path>/paket/find-packages/fak if you completed paket add FAK or paket add fak before.

The default cache policy caches results for 1 day (see _paket_cache_policy). To remove cached results you can either delete the <cache-path>/paket directory or provide a custom cache policy to control cache expiration for all or specific Paket commands:

zstyle ':completion::complete:paket:*' cache-policy _default_cache_policy
zstyle ':completion::complete:paket:find-packages:*' cache-policy _strict_cache_policy

_default_cache_policy () {
  # Rebuild if the cache is more than a week old.
  local cache="$1"
  local -a outdated
  # See http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
  outdated=( "$cache"(Nm+7) )
  (( $#outdated ))
}

_strict_cache_policy () {
  return 0 # 0 == always outdated, you should better use use-cache off.
}

There are two special default cache policies for completions relying on the existence of local files, e.g. paket.dependencies and paket.lock. For Paket commands that read these, the cache is invalidated as soon as the file's modification time is newer than the cache. (See _paket_cache_policy_dependencies_file and _paket_cache_policy_lock_file.)

Disable running Paket to get packages, versions etc. as completion arguments

zstyle ':completion::complete:paket:*' disable-completion yes

Disable only a single means to get completion values:

# Used by e.g. paket add:
zstyle ':completion::complete:paket:find-packages:' disable-completion yes
zstyle ':completion::complete:paket:find-package-versions:' disable-completion yes
zstyle ':completion::complete:paket:show-groups:' disable-completion yes

# Used by e.g. paket why:
zstyle ':completion::complete:paket:show-installed-packages:' disable-completion yes

Custom feed URLs for --source and paket push --url argument

zstyle ':completion::complete:paket:*' sources 'http://one.example.com/feed/v2'
zstyle ':completion::complete:paket:*' sources \
  'http://one.example.com/feed/v2' \
  'http://second.example.com/feed/v2'

Override list for a specific command:

zstyle ':completion::complete:paket:find-package-versions:*' sources \
  'http://another.example.com/feed/v2'
zstyle ':completion::complete:paket:push:*' sources \
  'https://myget.org/F/my-feed-name'

Type something to start searching.