Skip to content

Instantly share code, notes, and snippets.

@icolwell
Created January 26, 2024 03:56
Show Gist options
  • Save icolwell/e05d8f62f66cf82e862346c655b55a98 to your computer and use it in GitHub Desktop.
Save icolwell/e05d8f62f66cf82e862346c655b55a98 to your computer and use it in GitHub Desktop.
Easily switch between ROS1 and ROS2 terminal environments
#!/bin/bash
# This script is meant to be sourced by your bashrc
# It gives you the "rs" function for easily switching between ROS1 and ROS2
rs()
{
ROS_VER="${1:-1}"
if [ "$ROS_VER" == "1" ]; then
clear_ros_env
# ROS1 env setup goes here
source /opt/ros/noetic/setup.bash
echo "ROS 1 Environment Sourced"
elif [ "$ROS_VER" == "2" ]; then
clear_ros_env
# ROS2 env setup goes here
source /opt/ros/foxy/setup.bash
echo "ROS 2 Environment Sourced"
else
echo "Choose ROS version 1 or 2"
fi
}
clear_ros_env()
{
for ros_env_var in $(env | grep ROS_ | cut -d "=" -f1); do
unset "$ros_env_var"
done
unset CMAKE_PREFIX_PATH
unset COLCON_PREFIX_PATH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment