#!/usr/bin/perl use strict; use warnings; use File::Path qw(make_path); use constant VCX_DIR => '.vcx'; use constant BASE_DIR => VCX_DIR . '/bse'; use constant OBJ_DIR => VCX_DIR . '/obj'; use constant TMP_DIR => VCX_DIR . '/tmp'; my $cmd = $ARGV[0] // ''; if ($cmd eq 'init') { init_repo(); } elsif ($cmd eq 'status') { run_status(); } else { print "Usage: $0 [init|status]\n"; exit 1; } sub init_repo { my @dirs = (OBJ_DIR, BASE_DIR, TMP_DIR); foreach my $dir (@dirs) { if (!-d $dir) { make_path($dir); print "Created: $dir\n"; } } print "Repository ready\n"; } sub run_status { my $diff_cmd = "diff -x " . VCX_DIR . " -rq " . BASE_DIR . " ."; $diff_cmd .= " -X .vcxignore" if -e ".vcxignore"; my @output = `$diff_cmd`; foreach my $line (@output) { chomp $line; # Format output if ($line =~ /^Only in \Q@{[BASE_DIR]}\E: (.+)$/) { print "[D] $1\n"; } elsif ($line =~ /^Only in \.: (.+)$/) { print "[N] $1\n"; } elsif ($line =~ /^Files \Q@{[BASE_DIR]}\E\/(.+) and \.\/(.+) differ$/) { print "[M] $1\n"; } } }