Skip to content

Tab Completion Scripts

00JCIV00 edited this page Apr 7, 2024 · 7 revisions

Tab Completion Scripts can be generated for Bash, Zsh, and Powershell. These scripts allow users to press Tab to complete the next Command or Option available for your project based on the current input.

Examples

Configuration

Tab Completion Scripts are configured with the cova.generate.TabCompletionConfig struct which can be set up directly in the Meta Doc Config using the cova.generate.MetaDocConfig.tab_complete_config field. Within the Config, there are self-explanatory fields for configuring the following categories:

  • Generated Filepath
  • Header & Name Strings
  • Argument Inclusion Toggles
  • Cova Message & Installation Instruction Toggles

Installation & Usage

Note, the following instructions are included (nearly verbatim) in each Tab Completion Script of the corresponding shell by default. This behavior can be toggled with cova.generate.TabCompletionConfig.add_install_instructions.

Bash

Bash Completion Installation Instructions for your project:

  1. Place this script in a directory like /etc/bash_completion.d/ (Linux) or /usr/local/etc/bash_completion.d/ (Mac, if using Homebrew and bash-completion)

  2. Ensure the script has executable permissions:

    • chmod +x project-name-completion.bash
  3. Source this script from your .bashrc or .bash_profile by adding:

    • . /path/to/project-name-completion.bash
  4. Restart your terminal session or source your profile again:

    • source ~/.bashrc  # or ~/.bash_profile

Zsh

Zsh Completion Installation Instructions for your project:

  1. Place this script in a directory specified in your $fpath, such as ~/.zsh/completion/

  2. Ensure the script has executable permissions:

    • chmod +x project-name-completion.zsh
  3. Add the script's directory to your $fpath in your .zshrc if not already included:

    • fpath=(~/.zsh/completion $fpath)
  4. Enable and initialize completion in your .zshrc if you haven't already:

    • autoload -Uz compinit && compinit
  5. Restart your terminal session or source your .zshrc again:

    • source ~/.zshrc

Powershell

PowerShell Completion Installation Instructions for your project:

  1. Load the completion script into your current PowerShell session:

    • . .\project-name-completion.ps1
  2. Ensure your Execution Policy allows the script to be run. Example:

    • Set-ExecutionPolicy RemoteSigned
  3. To ensure this completion script is loaded automatically in future sessions, add the above sourcing command to your PowerShell profile:

    • Notepad $PROFILE
    • Add the line: . C:\path\to\project-name-completion.ps1
  4. Restart your PowerShell session or source your profile again:

    • . $PROFILE