Enabling Shell Completion

Introduction

Shell completion enhances the user experience by providing auto-completion for commands in the terminal. K0s supports shell completion for the following shells:

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:

  1. mkdir ~/.bash_completion.d
  2. k0s completion bash >~/.bash_completion.d/k0s
  3. cat <<'EOF' >~/.bashrc
  4. for compFile in ~/.bash_completion.d/*; do
  5. [ ! -f "$compFile" ] || source -- "$compFile"
  6. done
  7. unset compFile
  8. EOF

Then restart the shell or source ~/.bashrc.

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:

  1. echo "autoload -Uz compinit; compinit" >>~/.zshrc

Place the completion script in a custom site-functions folder:

  1. mkdir -p -- ~/.local/share/zsh/site-functions
  2. k0s completion zsh >~/.local/share/zsh/site-functions/_k0s

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:

  1. mkdir -- "$ZSH_CUSTOM/plugins/k0s"
  2. cat <<'EOF' >"$ZSH_CUSTOM/plugins/k0s/k0s.plugin.zsh"
  3. k0s completion zsh >| "$ZSH_CACHE_DIR/completions/_k0s" &|
  4. EOF
  5. omz plugin enable k0s

Then restart the shell.

fish

One-shot usage: k0s completion fish | source.

This is a recipe to load completions for each new shell. Adjust to your personal needs:

  1. mkdir -p -- "${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions"
  2. k0s completion fish >"${XDG_CONFIG_HOME:-$HOME/.config}/fish/completions/k0s.fish"

Then restart the shell.

powershell

Save the completion script into a file:

  1. k0s completion powershell > C:\path\to\k0s.ps1

You can import it like so:

  1. 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.