Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Last active August 29, 2015 14:03
Show Gist options
  • Save tokuhirom/fb8689be9ab740fec985 to your computer and use it in GitHub Desktop.
Save tokuhirom/fb8689be9ab740fec985 to your computer and use it in GitHub Desktop.
repos
e() { cd $(repos-list --null | peco --null) }
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Path;
use File::Basename;
my $base = "$ENV{HOME}/src";
my $repos = shift or pod2usage;
if ($repos =~ /\Agit\@([^:]+):(.*)\.git\z/) {
clone($repos, "$1/$2");
} else {
die "Unsupported repository type: $repos\n";
}
exit;
sub clone {
my ($url, $path) = @_;
mkpath(dirname($path));
exec('git', 'clone', $url, "$base/$path");
die $!;
}
__END__
=head1 SYNOPSIS
% repos-clone git@github.com:tokuhirom/nanobench.git
=head1 DESCRIPTION
List up cloned repositories from ~/src/.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $p =
Getopt::Long::Parser->new(
config => [qw(posix_default no_ignore_case auto_help)]);
$p->getoptions('null!' => \my $null,);
my $base = "$ENV{HOME}/src";
for my $d (glob("$base/*/*/*")) {
next unless -d $d;
(my $base = $d) =~ s!^$base/!!;
if ($null) {
print "$base\0$d\n";
} else {
print "$d\n";
}
}
__END__
=head1 DESCRIPTION
List up cloned repositories from ~/src/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment