Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 2.24 KB

File metadata and controls

67 lines (49 loc) · 2.24 KB

Shell completion — running it locally during development

On a real install (.deb / Homebrew) shell completions are installed automatically. During development you instead build and load them from the source tree using the helper scripts in scripts/.

The completion scripts are regenerated by build.rs on every cargo build (into completions/), and the helpers rebuild, copy/source them, and reload completion in your current shell.

The dynamic value completion (param/log variable names, flash targets, config keys) calls back into cfcli __complete, so the cfcli on your PATH must be the build you just made — the helpers put target/debug first for you.

zsh

The script must be sourced (it drops the cached _cfcli function and re-runs compinit in your current shell):

source scripts/refresh-completions.zsh

Run it again after any change to the CLI. If you execute it instead of sourcing it, it only does the file prep — open a new terminal afterwards.

bash

Also sourced (registers the completion in your current shell):

source scripts/refresh-completions.bash

Testing the dynamic values without hardware

Param/log completion reads ~/.config/cf-cli/cf-cli-completion.json, which is written on every successful connection. To test without a Crazyflie, connect once (e.g. cfcli param list) or seed the file by hand:

mkdir -p ~/.config/cf-cli
cat > ~/.config/cf-cli/cf-cli-completion.json <<'JSON'
{"log":[{"name":"stabilizer.roll"},{"name":"pm.vbat"}],
 "param":[{"name":"kalman.resetEstimation","readonly":false},
          {"name":"deck.bcLighthouse4","readonly":true}]}
JSON

A real connection overwrites this file.

You can also check the data path directly, independent of any shell glue:

cfcli __complete param-names
cfcli __complete log-names stab
cfcli __complete flash-targets

Don't cross shells

Use the .zsh helper in zsh and the .bash helper in bash. Sourcing the bash completion in zsh (or vice versa) registers the wrong machinery and produces errors like compgen: I need arguments / bad output format specification. The helpers guard against this and refuse to run in the wrong shell; if it already happened, just open a fresh terminal.