Tuesday, September 22, 2015

To rename ROS package systematically

Not specific to ROS, but still nice to have a memo like this for myself.

A couple of scripts can be used when you change the name of your ROS package "foo" to "bar".

1:  cd /tmp && cp -R `rospack find foo` .  
2:  (shopt -s nullglob && _() { for P in "$1"*/; do Q="${P//[Ff][Oo][Oo]/bar}"; mv -- "$P" "$Q"; _ "$Q"; done } && _ ./)  
3:  find . -type f -print0 | xargs -0 sed -i 's/foo/bar/g'  

Line by line:
  • At first line, you copy the entire package to somewhere safe; this prevents changing CVS data (.git, .svn etc.) without knowing. 
  • 2nd line is influenced by this thread 
  • So as the 3rd line (this thread)

If you want to change the packages you've already "released", see this thread.

----

Update 2024/10/21 If the targeted files are under (a local) git repository, there's much more user-friendly command (thanks to superuser.com#1110337).

git grep -lz foo | xargs -0 sed -i '' -e 's/foo/bar/g'



No comments:

Post a Comment