-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overhaul shell completion docs #3961
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,108 @@ | ||
# Enabling Shell Completion | ||
|
||
Generate the k0s completion script using the `k0s completion <shell_name>` command, for Bash, Zsh, fish, or PowerShell. | ||
## Introduction | ||
|
||
Sourcing the completion script in your shell enables k0s autocompletion. | ||
Shell completion enhances the user experience by providing auto-completion for | ||
commands in the terminal. K0s supports shell completion for the following | ||
shells: | ||
|
||
## Bash | ||
- `bash`, [GNU Bash](https://www.gnu.org/software/bash/) | ||
- `zsh`, [the Z-shell](https://www.zsh.org/) | ||
- `fish`, [the friendly interactive shell]((https://fishshell.com/)) | ||
- `powershell`, [Microsoft PowerShell](https://learn.microsoft.com/powershell/) | ||
|
||
```shell | ||
echo 'source <(k0s completion bash)' >>~/.bashrc | ||
## General Usage | ||
|
||
To generate a completion script for your shell, use the following command: `k0s | ||
completion <shell_name>`. Sourcing the completion script in your shell enables | ||
k0s autocompletion. | ||
|
||
## bash | ||
|
||
One-shot usage: `source <(k0s completion bash)`. | ||
|
||
This is a recipe to load completions for each new shell. Adjust to your personal | ||
needs: | ||
|
||
```bash | ||
mkdir ~/.bash_completion.d | ||
k0s completion bash >~/.bash_completion.d/k0s | ||
|
||
cat <<'EOF' >~/.bashrc | ||
for compFile in ~/.bash_completion.d/*; do | ||
[ ! -f "$compFile" ] || source -- "$compFile" | ||
done | ||
unset compFile | ||
EOF | ||
``` | ||
|
||
To load completions for each session, execute once: | ||
Then restart the shell or source `~/.bashrc`. | ||
|
||
```shell | ||
k0s completion bash > /etc/bash_completion.d/k0s | ||
## zsh | ||
|
||
One-shot usage: `source <(k0s completion bash)`. | ||
|
||
Following a recipe to load completions for each new shell. Adjust to your | ||
personal needs. If shell completion is not already enabled in your zsh | ||
environment you will need to enable it: | ||
|
||
```zsh | ||
echo "autoload -Uz compinit; compinit" >>~/.zshrc | ||
``` | ||
|
||
## Zsh | ||
Place the completion script in a custom `site-functions` folder: | ||
|
||
If shell completion is not already enabled in Zsh environment you will need to enable it: | ||
```zsh | ||
mkdir -p -- ~/.local/share/zsh/site-functions | ||
k0s completion zsh >~/.local/share/zsh/site-functions/_k0s | ||
``` | ||
|
||
```shell | ||
echo "autoload -U compinit; compinit" >> ~/.zshrc | ||
Edit `~/.zshrc` and add the line `fpath+=(~/.local/share/zsh/site-functions)` | ||
somewhere before `compinit` is called. After that, restart the shell. | ||
|
||
When using [Oh My ZSH!], you can create a [custom plugin]: | ||
|
||
```zsh | ||
mkdir -- "$ZSH_CUSTOM/plugins/k0s" | ||
cat <<'EOF' >"$ZSH_CUSTOM/plugins/k0s/k0s.plugin.zsh" | ||
k0s completion zsh >| "$ZSH_CACHE_DIR/completions/_k0s" &| | ||
EOF | ||
omz plugin enable k0s | ||
``` | ||
|
||
To load completions for each session, execute once: | ||
Then restart the shell. | ||
|
||
[Oh My ZSH!]: https://ohmyz.sh/ | ||
[custom plugin]: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-plugins | ||
|
||
## fish | ||
|
||
One-shot usage: `k0s completion fish | source`. | ||
|
||
This is a recipe to load completions for each new shell. Adjust to your personal | ||
needs: | ||
|
||
```shell | ||
k0s completion zsh > "${fpath[1]}/_k0s" | ||
mkdir -p -- "${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions" | ||
k0s completion fish >"${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions/k0s.fish" | ||
``` | ||
|
||
**Note**: You must start a new shell for the setup to take effect. | ||
Then restart the shell. | ||
|
||
## Fish | ||
## powershell | ||
|
||
```shell | ||
k0s completion fish | source | ||
Save the completion script into a file: | ||
|
||
```powershell | ||
k0s completion powershell > C:\path\to\k0s.ps1 | ||
``` | ||
|
||
To load completions for each session, execute once: | ||
You can import it like so: | ||
|
||
```shell | ||
k0s completion fish > ~/.config/fish/completions/k0s.fish | ||
```powershell | ||
Import-Module C:\path\to\k0s.ps1 | ||
``` | ||
|
||
To automatically load the module for each new shell session, add the above line | ||
to your shell profile. You can find the path to your profile via `Write-Output | ||
$profile`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to find some references about the idiomatic way of including user-managed bash shell completions, but I didn't really find anything. The
bash_completion.d
stuff seems to be used, but there doesn't seem to be "the way of doing it". That's why I tried to give an example with the caveat "adjust to your personal needs". Checking if the folder has already been set up in .bashrc or some other place is not a piece of cake. That's why I opted for not doing it.If you think checking would be better, then I'd probably change this to some descriptive block where to put the snippet, similar to the examples for zsh.
WDYT?