Last active
July 6, 2022 11:07
-
-
Save StrixROX/3ce3b49c838d76e1be014dd138cdc583 to your computer and use it in GitHub Desktop.
Bash snippet to create and remove ROS workspaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.bash_aliases | |
| # ... | |
| # Assuming you already have ROS installed... | |
| # First create an empty file ~/.ros_workspaces using: | |
| # `touch ~/.ros_workspaces` | |
| # (I used this file to automatically source the devel/setup.bash | |
| # script from all my ROS workspaces on startup) | |
| alias dirros='cd <path>' | |
| # path = path to the folder that will contain all your ROS workspaces. | |
| # (I used to store all my ROS workspaces in ~/ros folder) | |
| # Create and initialise ROS workspace | |
| # Usage: | |
| # `roscreate myworkspace` | |
| roscreate() { | |
| dirros | |
| if [ -d `pwd`/$1 ]; | |
| then | |
| echo "Workspace $1 already exists." | |
| else | |
| mkdir $1 && cd $1 | |
| mkdir src && cd src | |
| catkin_init_workspace | |
| cd .. | |
| catkin_make | |
| echo "source `pwd`/devel/setup.bash" >> ~/.ros_workspaces | |
| source ./devel/setup.bash | |
| fi | |
| } | |
| # Delete ROS workspace | |
| # Usage: | |
| # `rospurge myworkspace` | |
| rospurge() { | |
| dirros | |
| if [ -d ./$1 ]; | |
| then | |
| rm -r ./$1 | |
| grep -v "`pwd`/$1/devel/setup.bash" ~/.ros_workspaces > tmpfile | |
| cp -f ./tmpfile ~/.ros_workspaces | |
| rm ./tmpfile | |
| echo "Workspace $1 removed." | |
| else | |
| echo "Workspace $1 does not exist." | |
| fi | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.bashrc | |
| # add this in your .bashrc file to automatically source the devel/setup.bash | |
| # from all your ROS workspaces saved in ~/.ros_workspaces on startup | |
| # ... | |
| if [ -f ~/.ros_workspaces ]; then | |
| . ~/.ros_workspaces | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.ros_workspaces | |
| # (example file) | |
| source /home/strix/catkin_ws/devel/setup.bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment