summaryrefslogtreecommitdiff
path: root/bin/src-unregister
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-14 10:03:56 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-14 10:03:56 -0700
commit1bafdbac6145da0ab7a0622ca1707847e4d83edf (patch)
treed585ebbc42e83387c8369f30e669c22d10bc7553 /bin/src-unregister
parent86d385ae83a4274c72b1693a2534e8f7157bdf47 (diff)
downloaddotfiles-1bafdbac6145da0ab7a0622ca1707847e4d83edf.tar.gz
first version of src-unregister
Diffstat (limited to 'bin/src-unregister')
-rwxr-xr-xbin/src-unregister58
1 files changed, 42 insertions, 16 deletions
diff --git a/bin/src-unregister b/bin/src-unregister
index 7ad1cb03..b48ac45d 100755
--- a/bin/src-unregister
+++ b/bin/src-unregister
@@ -11,19 +11,45 @@
use warnings;
use strict;
-
-
-# if [ "$#" -ne 1 ]; then
-# echo >&2 "$(basename $0): usage: $(basename $0) REPO"
-# exit 1
-# fi
-
-# (
-# cd $HOME/src
-# repo="$1"
-
-# mr -d $repo status
-# echo
-
-# echo "Are you sure you want to delete?"
-# )
+use Capture::Tiny 'tee_stdout';
+use Term::UI;
+use Tie::File;
+
+die "need at least one argument" if ( @ARGV < 1 );
+chdir "$ENV{'HOME'}/src/";
+my $term = Term::ReadLine->new('brand');
+
+foreach my $repo ( @ARGV ) {
+ die "$repo does not exist" if ! ( -d $repo );
+}
+
+foreach my $repo ( @ARGV ) {
+ (my $output, undef) = tee_stdout { system "mr -m -d $repo status" };
+ my $confirm = 1;
+ if (length($output)) {
+ $confirm = $term->ask_yn(
+ prompt => 'Delete unclean repo $repo?',
+ default => 'n',
+ );
+ }
+ if ($confirm) {
+ my $in_block = 0;
+ tie my @lines, 'Tie::File', "$ENV{'HOME'}/src/.mrconfig"
+ or die "could not open ~/src/.mrconfig";
+ for (my $i = 0; $i < @lines; $i++) {
+ if ($lines[$i] =~ m/^\[(.*)\]$/) {
+ if ($1 eq $repo) {
+ $in_block = 1;
+ } else {
+ $in_block = 0;
+ }
+ }
+ if ($in_block) {
+ splice @lines, $i, 1;
+ $i--;
+ }
+ }
+ untie @lines;
+ system "rm -rf $repo";
+ }
+}