rst-block-comments.bash 747 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. files="$(git ls-files Modules | grep -v ' ' | xargs grep -l '^#.rst:$')"
  3. perl -i -e '
  4. use strict;
  5. use warnings;
  6. my $rst = 0;
  7. while (<>) {
  8. if ($rst) {
  9. if (/^# (.*)$/) {
  10. print "$1\n";
  11. } elsif (/^#$/) {
  12. print "\n";
  13. } else {
  14. $rst = 0;
  15. print "#]=======================================================================]\n";
  16. print $_;
  17. }
  18. } elsif (/^#\.rst:$/) {
  19. $rst = 1;
  20. print "#[=======================================================================[.rst:\n";
  21. } else {
  22. print $_;
  23. }
  24. if ($rst && eof) {
  25. $rst = 0;
  26. print "#]=======================================================================]\n";
  27. }
  28. }
  29. ' $files