shithub: riscv

Download patch

ref: 242e1dc5528474848c36ee68044b62f7da962241
parent: ed318aac59f3f13775782ca0b6eb22431866d17d
author: Jacob Moody <moody@posixcafe.org>
date: Wed Dec 25 22:54:31 EST 2024

vdiff: accept diff as filename argument and man page touch-up (thanks humm)

--- a/sys/man/1/vdiff
+++ b/sys/man/1/vdiff
@@ -8,37 +8,45 @@
 ]
 [
 .B -p
-.I strip
+.I nstrip
 ]
+[
+.I file
+]
 .SH DESCRIPTION
 .I vdiff
-reads unified diff output from standard input and displays a colored version. Each file diff is displayed in a separate block that can be collapsed by a click on the file name. Right clicking on a line will send a 
+reads unified diff output from
+.I file
+or standard input and displays a colored version.
+Each file within the diff is displayed in a separate block that can be collapsed by clicking on the file name.
+Right clicking on a line will send a
 .IR plumb (6)
 message to the
 .B edit
-port. Pressing
+port.
+Pressing
 .B q
 or
 .B del
 will exit
-.B vdiff.
+.I vdiff.
 .PP
 The
-.B \-b
+.B -b
 flag changes the color scheme to white text on a black background.
 .PP
 The
-.B \-p
-.I nstrip
+.B -p
 flag removes
 .I nstrip
-path elements from path before plumbing.
+path elements from the path before plumbing.
 .SH EXAMPLE
-% git/diff |vdiff
+.EX
+% git/diff | vdiff
+.EE
 .SH SOURCE
-/sys/src/cmd/vdiff.c
+.B /sys/src/cmd/vdiff.c
 .SH SEE ALSO
 .IR diff (1)
 .SH HISTORY
 vdiff first appeared in 9front (January, 2024).
-
--- a/sys/src/cmd/vdiff.c
+++ b/sys/src/cmd/vdiff.c
@@ -585,7 +585,7 @@
 void
 usage(void)
 {
-	fprint(2, "%s [-b] [-p n]\n", argv0);
+	fprint(2, "usage: %s [-b] [-p nstrip] [file]\n", argv0);
 	exits("usage");
 }
 
@@ -615,6 +615,16 @@
 		usage();
 		break;
 	}ARGEND;
+	switch(argc){
+	default:
+		usage();
+	case 1:
+		close(0);
+		if(open(argv[0], OREAD) < 0)
+			sysfatal("open: %r");
+	case 0:
+		break;
+	}
 
 	parse(0);
 	if(nblocks==1 && blocks[0]->nlines==0){
--