#!\usr\bin\perl -w # NAME: shwgiturl.pl # AIM: Open the git config file, and output only the url use strict; use warnings; use File::Basename; # split path ($name,$dir,$ext) = fileparse($file [, qr/\.[^.]*/] ) use File::stat; use Time::gmtime; sub prt($) { print shift; } sub path_d2u($) { my ($du) = shift; $du =~ s/\\/\//g; return $du; } sub get_git_parent($) { my $path = shift; $path = path_d2u($path); my @arr = split("/",$path); my ($p,$n); $p = ''; foreach $n (@arr) { if ($n eq '.git') { return $p; } $p = $n; } return ""; } sub get_YYYYMMDD($) { my ($t) = shift; my @f = (localtime($t))[0..5]; my $m = sprintf( "%04d/%02d/%02d", $f[5] + 1900, $f[4] +1, $f[3]); return $m; } sub process_in_file($) { my ($inf) = @_; if (! open INF, "<$inf") { #pgm_exit(1,"ERROR: Unable to open file [$inf]\n"); prt("ERROR: Unable to open file [$inf]\n"); return; } my @lines = ; close INF; my $lncnt = scalar @lines; #prt("Processing $lncnt lines, from [$inf]...\n"); my ($line,$inc,$lnn,$sb,$dtt); my $p = get_git_parent($inf); $dtt = ''; if ($sb = stat($inf)) { $dtt = get_YYYYMMDD($sb->mtime); } $lnn = 0; foreach $line (@lines) { chomp $line; $lnn++; if ($line =~ /\s*url\s*=\s*(.+)$/) { $inc = $1; prt("$p: $inc $dtt\n"); } } } if (@ARGV) { parse_args(@ARGV); } else { prt("No command given! Need file name...\n"); } exit(0); sub parse_args { my (@av) = @_; my ($arg); while (@av) { $arg = $av[0]; if (-f $arg) { process_in_file($arg); } else { prt("Arg $arg NOT A FILE!\n"); } shift @av; } } # eof