Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bash completion #1

Closed
osrf-migration opened this issue Apr 19, 2016 · 8 comments
Closed

Add bash completion #1

osrf-migration opened this issue Apr 19, 2016 · 8 comments
Assignees
Labels
enhancement New feature or request OOBE 📦✨ Out-of-box experience

Comments

@osrf-migration
Copy link

osrf-migration commented Apr 19, 2016

Original report (archived issue) by Louise Poubel (Bitbucket: chapulina, GitHub: chapulina).


Pressing tab twice should complete with possible commands. Take the gz tool for example, pressing tab twice displays options such as camera, topic, etc.

@osrf-migration osrf-migration added major enhancement New feature or request labels Apr 15, 2020
@chapulina chapulina removed the major label May 30, 2020
@chapulina chapulina added the OOBE 📦✨ Out-of-box experience label Dec 20, 2021
@chapulina chapulina added this to Inbox in Core development via automation Dec 20, 2021
@chapulina chapulina moved this from Inbox to To do in Core development Dec 20, 2021
@chapulina chapulina moved this from To do to In progress in Core development Jan 5, 2022
@scpeters
Copy link
Member

scpeters commented Jan 6, 2022

To start investigating this, I looked briefly at ros2cli, since it does a very good job of tab-completing in bash. It uses argcomplete, which is based in python and automatically works for packages that express their arguments using argparse. The following files is all that is needed to enable bash-completion:

That command is sourced as part of the general ros2 setup script, I believe because of the following configuration file:

If only we could just use argcomplete for ign! Unfortunately it does not currently use python. ign uses Ruby to look for *.yaml files in the IGN_CONFIG_PATH and parses these YAML files to determine the list of commands that can be executed. These command are implemented as Ruby files that either dlopen a c++ library to call a function or pass the CLI arguments to a C++ executable.

I think a first step would be to implement autocomplete for just the names of commands available in IGN_CONFIG_PATH. Once that is working, we can figure out how support autocomplete for the arguments to each command.

An additional reference is the gz completion script used in gazebo classic.

@scpeters
Copy link
Member

scpeters commented Jan 6, 2022

or pass the CLI arguments to a C++ executable.

Our executables are currently using a fork of cli11 for argument parsing, which has an open feature request to support autocompletion: CLIUtils/CLI11#343.

@scpeters
Copy link
Member

scpeters commented Jan 6, 2022

If only we could just use argcomplete for ign! Unfortunately it does not currently use python.

There is a way to use argcomplete with programs not written in python using the --external-argcomplete-script, but it requires writing a python script with the argument parsing logic replicated using argparse.

@scpeters
Copy link
Member

I've started in #77 by porting a portion of the gz completion script that autocompletes from a list of valid ign commands determined with ign --commands. It is a minimal set of functionality to demonstrate the approach.

@Bi0T1N
Copy link

Bi0T1N commented Jan 12, 2022

If only we could just use argcomplete for ign! Unfortunately it does not currently use python. ign uses Ruby to look for *.yaml files in the IGN_CONFIG_PATH and parses these YAML files to determine the list of commands that can be executed. These command are implemented as Ruby files that either dlopen a c++ library to call a function or pass the CLI arguments to a C++ executable.

Actually the Ruby class also supports shell completion.
But is there any reason to stay with Ruby? The Ruby cmd classes could be implemented in Python with the same mechanism (argparse with argcomplete) as in ROS2. Also, I think there are more people familiar with Python than Ruby.
I'm not sure if this is the only use of Ruby in Ignition but replacing Ruby would also reduce the number of dependencies (Python is needed for the (new) scripting interface via pybind11 anyway).

@chapulina
Copy link
Contributor

But is there any reason to stay with Ruby?

One reason at the moment is that we don't have the time to port it to another language, which would be a large effort, so we'd need a strong reason to do so.

I'm not sure if this is the only use of Ruby in Ignition

@mabelzhang
Copy link
Contributor

mabelzhang commented Jun 3, 2022

Followup tasks to #87, which adds bash completion to second-level flags, i.e. cmd subcommand --flag:

@azeey azeey self-assigned this Oct 31, 2023
@azeey
Copy link
Contributor

azeey commented Nov 7, 2023

As of gazebosim/gz-transport#451, I believe all commands have bash completion now, so I'll go ahead and close this issue.

@azeey azeey closed this as completed Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OOBE 📦✨ Out-of-box experience
Projects
Archived in project
Core development
In progress
Development

No branches or pull requests

6 participants