| --- | |
| title: Shell completion | |
| description: How to enable shell completion for Pyrefly | |
| --- | |
| {/* | |
| * Copyright (c) Meta Platforms, Inc. and affiliates. | |
| * | |
| * This source code is licensed under the MIT license found in the | |
| * LICENSE file in the root directory of this source tree. | |
| */} | |
| Generate a completion script with `pyrefly completion --shell <shell>`. Supported | |
| shells are `bash`, `zsh`, `fish`, `powershell`, and `elvish`. The script is written | |
| to standard output. | |
| ## Bash | |
| Add this to `~/.bashrc`: | |
| ```bash | |
| source <(pyrefly completion --shell bash) | |
| ``` | |
| ## Zsh | |
| Add this to `~/.zshrc` after initializing completion with `compinit`: | |
| ```zsh | |
| autoload -Uz compinit | |
| compinit | |
| source <(pyrefly completion --shell zsh) | |
| ``` | |
| ## Fish | |
| Save the script in the completions directory: | |
| ```fish | |
| mkdir -p ~/.config/fish/completions | |
| pyrefly completion --shell fish > ~/.config/fish/completions/pyrefly.fish | |
| ``` | |
| ## PowerShell | |
| Add this to your profile (`$PROFILE`): | |
| ```powershell | |
| pyrefly completion --shell powershell | Out-String | Invoke-Expression | |
| ``` | |
| ## Elvish | |
| Save the script and load it from `~/.config/elvish/rc.elv`: | |
| ```sh | |
| mkdir -p ~/.config/elvish/lib | |
| pyrefly completion --shell elvish > ~/.config/elvish/lib/pyrefly.elv | |
| ``` | |
| ```elvish | |
| use pyrefly | |
| ``` | |
| Restart your shell after setup. Regenerate saved completion files after upgrading | |
| Pyrefly to include any new commands and options. |