diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2019-08-13 07:21:27 +0100 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-08-13 07:21:27 +0100 |
commit | 70f56adcaec396bef02c3d2d263124eba8daddb0 (patch) | |
tree | 34f3d3ed39f7451f0c04190f0c1842356f327214 /bin/src-register-all | |
parent | fba258370244cb90e7efd26849fe6e44d14dce04 (diff) | |
download | dotfiles-70f56adcaec396bef02c3d2d263124eba8daddb0.tar.gz |
factor out code in src-register-all to a lib
Diffstat (limited to 'bin/src-register-all')
-rwxr-xr-x | bin/src-register-all | 61 |
1 files changed, 3 insertions, 58 deletions
diff --git a/bin/src-register-all b/bin/src-register-all index 5736ccd6..411cace7 100755 --- a/bin/src-register-all +++ b/bin/src-register-all @@ -1,70 +1,15 @@ #!/usr/bin/env perl # src-register-all -- add new all new git/hg repos in ~/src to ~/.mrconfig - -# Copyright (C) 2019 Sean Whitton -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or (at -# your option) any later version. # -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - - - # This script must be as portable as possible (inc. its shebang). We # do assume that the path separator is a forward slash, rather than # using catfile(), because .mrconfig assumes that too use strict; use warnings; +use lib "$ENV{HOME}/src/dotfiles/lib/perl5"; -use Cwd; -use File::Find; - -chdir; -my @known_repos; -open my $fh, "<", ".mrconfig"; -while (<$fh>) { - if (/^\[(src\/.+)\]$/) { - push @known_repos, $ENV{HOME}."/$1"; - } -} -find({wanted => \®ister, preprocess => \&skip}, "src"); - -sub skip { - my $cwd = getcwd(); - # once we've found a repo, don't search inside it for more repos - return () if is_repo($cwd); - my @entries; - # don't process repos mr already knows about - foreach my $entry (@_) { - my $entry_path = $cwd."/$entry"; - push @entries, $entry - unless grep /\A$entry_path\z/, @known_repos; - } - return @entries; -} -sub register { - return unless is_repo($_); - chdir $_; - my $register_out = `mr -c $ENV{HOME}/.mrconfig register 2>&1`; - unless ($? == 0) { - print STDERR "mr register: $File::Find::name\n"; - print STDERR $register_out."\n"; - exit 1; - } - chdir ".."; -} +use Local::Homedir; -sub is_repo { - my $repo = shift; - return -d "$repo/.git" || -d "$repo/.hg"; -} +exit src_register_all(); |