Module bpaf::_documentation::_2_howto::_1_completion

source ·
Available on crate feature extradocs only.
Expand description

 

← Testing your parsers

↑ HOWTO - practical, oriented to solving problems guides ↑

§Dynamic shell completion

bpaf implements shell completion to allow to automatically fill in not only flag and command names, but also argument and positional item values.

  1. Enable autocomplete feature:

    bpaf = { version = "0.9", features = ["autocomplete"] }
    
  2. Decorate argument and positional parsers with Parser::complete to provide completion functions for arguments

  3. Depending on your shell generate appropriate completion file and place it to whereever your shell is going to look for it, name of the file should correspond in some way to name of your program. Consult manual for your shell for the location and named conventions:

    1. bash

      $ your_program --bpaf-complete-style-bash >> ~/.bash_completion
      
    2. zsh: note _ at the beginning of the filename

      $ your_program --bpaf-complete-style-zsh > ~/.zsh/_your_program
      
    3. fish

      $ your_program --bpaf-complete-style-fish > ~/.config/fish/completions/your_program.fish
      
    4. elvish

      $ your_program --bpaf-complete-style-elvish >> ~/.config/elvish/rc.elv
      
  4. Restart your shell - you need to done it only once or optionally after bpaf major version upgrade: generated completion files contain only instructions how to ask your program for possible completions and don’t change even if options are different.

  5. Generated scripts rely on your program being accessible in $PATH

 

← Testing your parsers

↑ HOWTO - practical, oriented to solving problems guides ↑