Assorted shell commands for using ros with bash.
- Author: Jeremy Leibs
- License: BSD
- Repository: ros
The rosbash package contains some useful bash functions and adds tab-completion to a large number of the basic ros utilities.
To enable rosbash, make sure that it gets sourced in your bashrc:
This is done by default when following most of the standard install instructions
The rosbash package includes limited support for zsh and tcsh by way of sourcing the roszsh or rostcsh files respectively. We currently do not provide documentation on these shells, though much of the functionality is similar to the bash shell extensions.
Command line utilities
rosbash includes the following command line utilities:
roscd - change directory starting with package, stack, or location name
rosed - edit a file in a package
roscp - copy a file from a package
rospd - pushd equivalent of roscd
rosd - lists directories in the directory-stack
rosls - list files in a ros package
roscd allows you to change directories using a package name, stack name, or special location. You can continue to use a relative path after the package name to go further into the package.
roscd roscpp roscd roscpp/include/ros
Additionally, the ROS_LOCATIONS environment variable can be used to add additional special locations for use with roscd. ROS_LOCATIONS is a colon-separated list of key=path pairs.
For example, adding the following to your .bashrc file:
Will then allow you to type:
$ roscd dev
and end up in ~/ros/dev.
rosed allows you to easily edit files in a ROS package by typing the package name and the name of the file you want to edit:
$ rosed roscpp_tutorials add_two_ints_server.cpp
Note: you can specify ANY file in a package, including those further down within the file hierarchy. If you specify an ambiguous file you will be prompted to select one.
$ rosed roscpp CMakeLists.txt You have chosen a non-unique filename, please pick one of the following: 1) ~/ros/ros/core/roscpp/test/CMakeLists.txt 2) ~/ros/ros/core/roscpp/CMakeLists.txt 3) ~/ros/ros/core/roscpp/src/CMakeLists.txt 4) ~/ros/ros/core/roscpp/src/libros/CMakeLists.txt #?
The default editor for rosed is vim. To use a different editor, set the EDITOR environment variable. E.g., in your ~/.bashrc:
export EDITOR='emacs -nw'
This example makes emacs the default editor.
roscp allows you to conveniently copy a file from a package. Similar to rosed you can specify any file in the package regardless of hierarchy.
$ roscp roscpp_tutorials talker.cpp .
Will end up copying the file from ~/ros/pkgs/ros_tutorials/roscpp_tutorials/talker/talker.cpp
rospd is the pushd equivalent of roscd. It allows you to keep multiple locations in a directory-stack while still using ros package names. You can then use the number of any directory in your directory stack to jump back there.
leibs@bar:~$ rospd hokuyo_node/ 0 ~/ros/pkgs/laser_drivers/hokuyo_node 1 ~ leibs@bar:~/ros/pkgs/laser_drivers/hokuyo_node$ rospd roscpp_tutorials/ 0 ~/ros/pkgs/ros_tutorials/roscpp_tutorials 1 ~/ros/pkgs/laser_drivers/hokuyo_node 2 ~ leibs@bar:~/ros/pkgs/ros_tutorials/roscpp_tutorials$ rospd laser_pipeline/ 0 ~/ros/dev/laser_pipeline 1 ~/ros/pkgs/ros_tutorials/roscpp_tutorials 2 ~/ros/pkgs/laser_drivers/hokuyo_node 3 ~ leibs@bar:~/ros/dev/laser_pipeline$ rospd 1 0 ~/ros/pkgs/ros_tutorials/roscpp_tutorials 1 ~/ros/pkgs/laser_drivers/hokuyo_node 2 ~ 3 ~/ros/dev/laser_pipeline
rosd lists the directories in your directory stack. This is for use with rospd.
leibs@bar:~/ros/pkgs/laser_drivers/hokuyo_node$ rosd 0 ~/ros/pkgs/laser_drivers/hokuyo_node 1 ~ 2 ~/ros/dev/laser_pipeline
rosls allows you to view the contents of a package, stack, or location.
$ rosls roscpp $ rosls roscpp/include/ros
rosbash enables tab-completion for a number of ros utilities including: roscd, rospd, rosls, rosmake, rosrun, rosed, roscp, roslaunch, rosupdate, rosbag, rosparam, rosnode, rostopic, rosservice, rosmsg.
There are a couple of generic completion rules that may be appropriate for other utilities. Looking through the rosbash source may provide insights into replicating similar functionality for other nodes, however, the code is not yet nicely generalized or re-usable. In a future release of ROS, we plan to incorporate a more generically re-usable tab-completion framework into rosbash and the other common shells used by ROS.