Skip to content

Instantly share code, notes, and snippets.

@Zejnilovic
Created May 3, 2019 05:48
Show Gist options
  • Save Zejnilovic/045e0b54e9daa24220cf3aa770e29173 to your computer and use it in GitHub Desktop.
Save Zejnilovic/045e0b54e9daa24220cf3aa770e29173 to your computer and use it in GitHub Desktop.
Script to easily switch between settings files - written for maven, easily changeable to support others.
#!/usr/bin/perl
# Perl script to fast switch between maven settings. Applicable to other programs as well.
# Expects an original file like settings.xml and reference files like settings.xml.alfa1
# and settings.xml.alfa2. These are in the same $m2Folder. When run gives user list of
# postfixes of the original file to chose from (alfa1, alfa2). And that file will
# overwrite the original settings.xml
use warnings;
use File::Copy;
$m2Folder = $ENV{'M2'};
opendir my $dir, $m2Folder or die "Cannot open directory: $!";
my @files = readdir $dir;
closedir $dir;
print "Possible settings for maven are:\n";
my $i=1;
my @viable_files;
foreach $file (@files) {
next unless ($file =~ m/settings\.xml\./);
my $printable = substr $file, 13;
print "$i) $printable\n";
$i = $i + 1;
push @viable_files, $file;
}
print "To exit - Ctrl+C\n";
my $choice = <STDIN>;
chomp $choice;
copy("$m2Folder/$viable_files[$choice-1]", "$m2Folder/settings.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment