X-Git-Url: https://git.madduck.net/code/myrepos.git/blobdiff_plain/69a60fb0a34b214c9ff6d55350b4663b4452c397..ebc88f26c7cbe202c2738bfc30423280c80f172b:/mr

diff --git a/mr b/mr
index 3f04b5b..17f9585 100755
--- a/mr
+++ b/mr
@@ -22,6 +22,8 @@ B<mr> [options] diff
 
 B<mr> [options] log
 
+B<mr> [options] run command [param ...]
+
 B<mr> [options] bootstrap url [directory]
 
 B<mr> [options] register [repository]
@@ -102,6 +104,10 @@ Show a diff of uncommitted changes.
 
 Show the commit log.
 
+=item run command [param ...]
+
+Runs the specified command in each repository.
+
 =back
 
 These commands are also available:
@@ -216,7 +222,9 @@ Be verbose.
 
 =item --quiet
 
-Be quiet.
+Be quiet. This supresses mr's usual output, as well as any output from
+commands that are run (including stderr output). If a command fails,
+the output will be shown.
 
 =item -k
 
@@ -621,23 +629,36 @@ sub action {
 		}
 	}
 	else {
+		my $actionmsg;
 		if (! $no_chdir) {
-			print "mr $action: $fulldir\n" unless $quiet;
+			$actionmsg="mr $action: $fulldir";
 		}
 		else {
 			my $s=$directory;
 			$s=~s/^\Q$fulldir\E\/?//;
-			print "mr $action: $fulldir (in subdir $s)\n" unless $quiet;
+			$actionmsg="mr $action: $fulldir (in subdir $s)";
 		}
+		print "$actionmsg\n" unless $quiet;
 
 		my $hookret=hook("pre_$action", $topdir, $subdir);
 		return $hookret if $hookret != OK;
 
 		$command="set -e; ".$lib.
 			"my_action(){ $command\n }; my_action ".
-			join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
+			join(" ", map { s/\\/\\\\/g; s/"/\"/g; '"'.$_.'"' } @ARGV);
 		print "mr $action: running >>$command<<\n" if $verbose;
-		my $ret=system($command);
+		my $ret;
+		if ($quiet) {
+			my $output = qx/$command 2>&1/;
+			$ret = $?;
+			if ($ret != 0) {
+				print "$actionmsg\n";
+				print STDERR $output;
+			}
+		}
+		else {
+			$ret=system($command);
+		}
 		if ($ret != 0) {
 			if (($? & 127) == 2) {
 				print STDERR "mr $action: interrupted\n";
@@ -693,7 +714,17 @@ sub hook {
 	my $shell="set -e;".$lib.
 		"my_hook(){ $command\n }; my_hook";
 	print "mr $hook: running >>$shell<<\n" if $verbose;
-	my $ret=system($shell);
+	my $ret;
+	if ($quiet) {
+		my $output = qx/$shell 2>&1/;
+		$ret = $?;
+		if ($ret != 0) {
+			print STDERR $output;
+		}
+	}
+	else {
+		$ret=system($shell);
+	}
 	if ($ret != 0) {
 		if (($? & 127) == 2) {
 			print STDERR "mr $hook: interrupted\n";
@@ -1411,7 +1442,7 @@ sub register {
 	$ENV{MR_REPO}=~s/.*\/(.*)/$1/;
 	$command="set -e; ".$config{$directory}{DEFAULT}{lib}."\n".
 		"my_action(){ $command\n }; my_action ".
-		join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV);
+		join(" ", map { s/\\/\\\\/g; s/"/\"/g; '"'.$_.'"' } @ARGV);
 	print "mr register: running >>$command<<\n" if $verbose;
 	exec($command) || die "exec: $!";
 }
@@ -1688,6 +1719,8 @@ darcs_log = darcs changes "$@"
 git_bare_log = git log "$@"
 fossil_log = fossil timeline "$@"
 
+run = "$@"
+
 svn_register =
 	url=`LC_ALL=C svn info . | grep -i '^URL:' | cut -d ' ' -f 2`
 	if [ -z "$url" ]; then