shithub: x

Download patch

ref: 9bd6366c2795decf34b2367ecf8e492d3a399835
parent: 17ecec63f2109a344a2e610668017c5af5f9914d
author: kvik <kvik@a-b.xyz>
date: Tue Apr 14 06:14:03 EDT 2020

Add and document the new -b option to x/man

This makes x/man -b behave similar to Plan 9 man(1)'s -b option:
forwarding the formatted page via plumber(4), eventually ending
up (probably) in user's editor.

With or without the new option output is now filtered through
col -b to remove gunk.

--- a/man
+++ b/man
@@ -7,23 +7,53 @@
 width=72
 
 fn usage {
-	echo usage: x/man [flags] [section] title ...
+	>[1=2] echo usage: x/man [-b] [man-flags] [section] title
 	exit usage
 }
 
-while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
-	flags=($flags $1)
+out='stdout'
+section=()
+title=()
+while(~ $1 -* && ! ~ $1 --){
+	switch($1){
+	case -b
+		out='plumb'
+	case *
+		flags=($flags $1)
+	}
 	shift
 }
 if(~ $1 --)
 	shift
-if(~ $#* 0)
-	usage
-if(echo $1 | grep -s '^[0-9][0-9A-Za-z]*'){
-	section=$1
-	shift
+if(~ $#* 2){
+	section = $1; shift
 }
-if(~ $#section 0)
+title = $1
+if(~ $#title 0)
+	usage
+
+if(~ $out 'plumb')
+	fn output {
+		t = /tmp/xman
+		mkdir -p $t
+		col -b >$t/tmp.$pid
+		if(~ $#section 0){
+			<$t/tmp.$pid awk -F'[)(]' '
+				NR == 1 {printf($2) >"/env/section"}
+			'
+			section = `{cat /env/section}
+		}
+		if(~ $#section 0)
+			section = ''
+		mkdir -p $t/$section
+		mv $t/tmp.$pid $t/$section/$title
+		plumb $t/$section/$title
+	}
+if not
+	fn output {col -b}
+
+{if(~ $#section 0)
 	x/run 'MANWIDTH='$width man $flags $*
 if not
 	x/run 'MANWIDTH='$width man $flags -s $section $*
+}| output
--- a/x.man
+++ b/x.man
@@ -18,7 +18,10 @@
 .RB [ cmd ]
 .PP
 .B x/man
-.RI [ section ] title
+.RI [ -b ]
+.RI [ man-flags ]
+.RI [ section ]
+.I title
 .PP
 .B x/path
 .B -lpPr
@@ -121,14 +124,11 @@
 
 .PP
 .B x/man
-is a shortcut for displaying the manual pages from the remote
-systems.
-By default the manual pages are printed to the
-standard output; the option
-.I -p
-changes this to redirect the output into a temporary file
-.B /tmp/man/$title.$section.txt
-which is then plumbed for viewing in an editor.
+displays formatted manual pages from remote systems on its
+standard output.
+With
+.I -b
+the page is saved to a file and plumbed.
 
 .PP
 .B x/path