File indexing completed on 2024-04-28 05:49:10

0001 #!/usr/bin/perl -w
0002 
0003 use strict;
0004 use warnings;
0005 use File::Find;
0006 use File::Spec;
0007 
0008 # only param: directory we shall collect stuff recursively in
0009 my $dir = shift;
0010 if (!defined($dir)) {
0011     die "Usage: metaproject.pl <directory>\n";
0012 }
0013 
0014 # collect all .kateprojects below the passed directory
0015 my @projects;
0016 sub find_project
0017 {
0018     if ($File::Find::name =~ /^.+\/\.kateproject/) {
0019         push @projects, $File::Find::dir;
0020     }
0021 }
0022 find(\&find_project, $dir);
0023 
0024 # construct kate project json file
0025 open P, ">$dir/.kateproject";
0026 print P "{\n";
0027 print P "    \"files\": [\n";
0028 
0029 # insert all projects we found
0030 print P "        { \"projects\": [";
0031 my $first = 1;
0032 foreach my $project (sort @projects) {
0033     # compute relative project path, skip ourself
0034     my $relproject = File::Spec->abs2rel($project, $dir);
0035     $relproject =~ s/[\/\\]?\.kateproject$//;
0036     next if ($relproject eq "" || $relproject eq ".");
0037 
0038     # add to our projects list
0039     if ($first == 0) {
0040         print P ",";
0041     }
0042     print P "\n            \"".$relproject."\"";
0043     $first = 0;
0044 }
0045 print P " ]\n        } ]\n";
0046 
0047 # be done ;)
0048 print P "}\n";
0049 close P;