Ros2cd - a complete roscd replacement in ros2

Hello everyone,

we recently moved to ros2 but I quickly noticed the lack of an equivalent for the old roscd. For me, this was an essential functionality to navigate workspaces efficiently. I know there is colcon_cd but it is very limited in functionality and basically only works in the current workspace.

As I could not find any alternative, I just wrote my own:

Simply source the bash file and off you go. The provided script replicates the behavior of the old roscd command in ros2 (and shares the name because of muscle memory). The current working directory is changed to the same one where ros2 launch would execute a launch file from. If a sym-link install is found, it goes to the source directory instead.

Best regards,
Martin

9 Likes

Amazing, just tested it on Jazzy and Humble and it works great!

You would not believe the string of excuses saying why this is clearly impossible and a fool’s errand to get working I’ve heard every time I’ve asked anywhere why it’s missing in ROS 2. Glad we finally have it and hopefully it’s included as stock in the next release.

My smallest nitpick is that if you roscd metapackage it sends you to the src/metapackage/metapackage subpackage that defines it which is technically correct, but unlikely to be what one would actually want in that case. Maybe worth adding an automatic cd .. if the last two dirs are the same?

I am glad that you like it. I was quite surprised, too, that nobody had written such a script yet.

Glad we finally have it and hopefully it’s included as stock in the next release.

The default ros2 command is implemented in Python and python scripts can not change the current working directory, so adding it as a verb there is unfortunately not possible. However, it should be possible to distribute the script as a separate package through the build farm. If there is enough demand, I can look into that.

Maybe worth adding an automatic cd .. if the last two dirs are the same?

I am very hesitant to implement such kind of special behavior. It could lead to unexpected results, especially when package and folder have the same name but it is not a meta package.