gazebosim / gz-tools

Command line tools for the Gazebo libraries.
https://gazebosim.org
Apache License 2.0
14 stars 18 forks source link

Add bash-completion helper for command names #77

Closed scpeters closed 2 years ago

scpeters commented 2 years ago

🎉 New feature

Part of https://github.com/ignitionrobotics/ign-tools/issues/1.

Summary

This adds a bash-completion helper based on the script used by gazebo's gz command. It currently only autocompletes the names of ign commands using the output of ign --commands. Subsequent improvements may add support for autocompleting the -* arguments and ignition topic and service names. This pull request is intentionally simple to demonstrate the approach.

My goal is to emulate the approach taken by the hub command, which hosts its own completion scripts in its etc folder. hub does not install these scripts with make install since the install location varies with each operating system distribution. Instead, the installation path is encoded in the homebrew formula and debian metadata. This enables ign autocompletion support on these two platforms if bash-completion is enabled without requiring additional user action. The debian metadata and homebrew formula can be updated with the next prerelease.

Test it

Source the script in a terminal window and hit <TAB> after typing ign and see the list of available commands.

To test a prototype of the homebrew formula, checkout https://github.com/osrf/homebrew-simulation/commit/38ae6c1063c38adbb66ba3995b184f5af8cc2c89 and install ignition-tools with the --HEAD flag. If ignition-tools has dependent packages already installed, use the following:

brew remove ignition-tools --ignore-dependencies
brew install --HEAD ignition-tools

Checklist

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

scpeters commented 2 years ago

Nice! Works well for me! It would be interesting to document it somewhere, like the README, so users compiling from source know what to do.

added from-source instructions in https://github.com/ignitionrobotics/ign-tools/pull/77/commits/174a600699f34a07403b2330119a5896eb5a1ec5

I also wonder if there's a way of automatically sourcing this file for users compiling from source which is not specific to colcon. Maybe something within the ign command itself? Just a thought for the future.

I'm not sure, but I agree that would be nice. Let's keep that in mind for the future