9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] Manpage Previews
@ 2019-06-07  6:23 vp
  2019-06-07 14:09 ` Stanley Lieber
  0 siblings, 1 reply; 8+ messages in thread
From: vp @ 2019-06-07  6:23 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]

Binding over the system manual path is a nice Plan 9™ code avoidance
tactic, which got tired really quickly for me during some sources
expeditions.

My solution was adding the -f flag to the man(1) utility which
disables the searching behaviour and treats the arguments as paths to
the troff source files, for example:

	man -f /sys/man/1/man 
	
The resulting diff is weird to look at since I've hoisted a big chunk
of code into a function, so I attach the whole script instead.

[-- Attachment #2: man --]
[-- Type: text/plain, Size: 2172 bytes --]

#!/bin/rc
# man - print manual pages
rfork e

. /sys/man/fonts

out=cat
search=yes
cmd=n
sec=()
files=()

fn usage {
	echo 'Usage: man [-bfnpPStw] [section ...] title ...' >[1=2]
	exit
}

fn roff {
	preproc=()
	postproc=cat
	x=`{doctype $2}
	if (~ $1 t){
		opts=-Tutf
		if(~ $x *grap*)
			preproc=($preproc grap)
		if(~ $x *pic*)
			preproc=($preproc pic)
	}
	if not{
		opts='-N -rL1000i'
		if (grep -s '^\.(2C|sp *[0-9]*\.)' $2)
			postproc=col
	}
	if(~ $x *eqn*)
		preproc=($preproc eqn)
	if(~ $x *tbl*)
		preproc=($preproc tbl)
	preproc=`{echo $preproc | sed 's/ /|/g'}
	if(~ $#preproc 0)
		preproc=cat
	{echo -n $FONTS | cat $2} | eval $preproc | troff $opts -$MAN | $postproc
}

fn doman {
	cmd=$1; shift
	for(i){
		switch($cmd){
		case w
			echo $i
		case t
			roff t $i
		case p
			roff t $i | grep -v '^x X html'
		case P
			roff t $i
		case n
			roff n $i | sed '
				${
       				       /^$/p
				}
				//N
				/^\n$/D'
		case b
			x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
			if(~ $x(2) 0intro) x=($x(1) intro)
			roff n $i | sed '
				${
       				       /^$/p
				}
				//N
				/^\n$/D' |
			plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
		}
	} | $out
}

d=no
while(~ $d no){
	if(~ $#* 0) usage
	if(test -d /sys/man/$1){
		sec=($sec $1)
		shift
	}
	if not
		switch($1){
		case -b ; cmd=b ; shift
		case -f ; search=file ; shift
		case -n ; cmd=n ; shift
		case -P ; cmd=P ; out=page ; shift
		case -p ; cmd=p ; out=proof ; shift
		case -S ; search=no ; shift
		case -t ; cmd=t ; shift
		case -w ; cmd=w ; shift
		case * ; d=yes
		}
}
if(~ $#* 0) usage

if(~ $search file){
	doman $cmd $*
	exit
}
if(~ $#sec 0)
	sec=`{ls -pd /sys/man/[0-9]*}
if(~ $search yes){
	pat='^('^`{echo $* | sed 's/ /|/g'}^') '
	for(i in /sys/man/$sec)
		if(/bin/test -f $i/INDEX){
			try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //' | sort -u}
			if(! ~ $#try 0)
				files=($files $i/$try)
		}
}
if(~ $#files 0)
	for(i){
		if(~ $i intro) i=0intro
		for(n in $sec){
			try=`{echo /sys/man/$n/$i | tr A-Z a-z}
			if (/bin/test -f $try)
				files=($files $try)
		}
	}
if(~ $#files 0){
	echo 'man: no manual page' >[1=2]
	exit 'no man'
}
doman $cmd $files

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
  2019-06-07  6:23 [9front] Manpage Previews vp
@ 2019-06-07 14:09 ` Stanley Lieber
  2019-06-07 21:17   ` Silas McCroskey
  0 siblings, 1 reply; 8+ messages in thread
From: Stanley Lieber @ 2019-06-07 14:09 UTC (permalink / raw)
  To: 9Front

[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]

     when you get tired of doing something manually, put it in a script. when you get tired of running the script manually, add it to your profile, or to another script that you’ll be running anyway. when all that fails, program the shell interactively! making all this easy is a major feature of the system.  

  
i do a lot of stuff (maybe too much) in my profile, and in other scripts that run when i setup network mounts or launch rio (both are separate and are triggered manually); everything from polluting my environment with tons of utility variables (mainly, shorthand for various frequently used long path names) and functions, to binding all kinds of local and remote directories over non-standard locations. it eases the need for a lot of otherwise necessary code. thankfully, the plan 9 tools don’t care, and are happy to go on with their work while remaining completely ignorant of how i’ve wrecked the place.
  

  
here’s a completely unrelated example of this way of thinking:
  

  
since there is no shell completion in rio, i’m constantly creating tiny, single-character variables (mostly containing the results of shell globbing) so that i can manipulate those values in various ways without having to type out long strings of characters. this comes in very handy when (for instance) running a disgusting app ->  ssh ->  tmux ->  drawterm -G rube goldberg connection to plan 9 from a touchscreen mobile device.
  

  
what i’m advocating here may seem like simply transplanting effort from automation over to your consciousness, and therefore wasting more of your precious mental processing capabilities (read: limited and already stretched attention span), but consider that in many cases you’d have to decide things like which flag to invoke, how to use it, and its proper arguments anyway.
  

  
and code that doesn’t exist never fails.
  

  
sl
  

     

[-- Attachment #2: Type: text/html, Size: 2038 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
  2019-06-07 14:09 ` Stanley Lieber
@ 2019-06-07 21:17   ` Silas McCroskey
  2019-06-08 16:48     ` Stanley Lieber
  0 siblings, 1 reply; 8+ messages in thread
From: Silas McCroskey @ 2019-06-07 21:17 UTC (permalink / raw)
  To: 9front

Couldn't you also just `nroff -man' directly and avoid `man' altogether?

What is `man' really buying you here, if you're not searching the index?

- sam-d

On Fri, Jun 7, 2019 at 7:10 AM Stanley Lieber <sl@stanleylieber.com> wrote:
>
> when you get tired of doing something manually, put it in a script. when you get tired of running the script manually, add it to your profile, or to another script that you’ll be running anyway. when all that fails, program the shell interactively! making all this easy is a major feature of the system.
>
> i do a lot of stuff (maybe too much) in my profile, and in other scripts that run when i setup network mounts or launch rio (both are separate and are triggered manually); everything from polluting my environment with tons of utility variables (mainly, shorthand for various frequently used long path names) and functions, to binding all kinds of local and remote directories over non-standard locations. it eases the need for a lot of otherwise necessary code. thankfully, the plan 9 tools don’t care, and are happy to go on with their work while remaining completely ignorant of how i’ve wrecked the place.
>
> here’s a completely unrelated example of this way of thinking:
>
> since there is no shell completion in rio, i’m constantly creating tiny, single-character variables (mostly containing the results of shell globbing) so that i can manipulate those values in various ways without having to type out long strings of characters. this comes in very handy when (for instance) running a disgusting app -> ssh -> tmux -> drawterm -G rube goldberg connection to plan 9 from a touchscreen mobile device.
>
> what i’m advocating here may seem like simply transplanting effort from automation over to your consciousness, and therefore wasting more of your precious mental processing capabilities (read: limited and already stretched attention span), but consider that in many cases you’d have to decide things like which flag to invoke, how to use it, and its proper arguments anyway.
>
> and code that doesn’t exist never fails.
>
> sl
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
  2019-06-07 21:17   ` Silas McCroskey
@ 2019-06-08 16:48     ` Stanley Lieber
  0 siblings, 0 replies; 8+ messages in thread
From: Stanley Lieber @ 2019-06-08 16:48 UTC (permalink / raw)
  To: 9front

as someone who recently had to edit the man pages for print, i do heartily recommend proofing changes with man -P before committing.

sl




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
@ 2019-06-09 20:11 umbraticus
  0 siblings, 0 replies; 8+ messages in thread
From: umbraticus @ 2019-06-09 20:11 UTC (permalink / raw)
  To: 9front

> Couldn't you also just `nroff -man' directly and avoid `man' altogether?
> What is `man' really buying you here, if you're not searching the index?

man does some extra work to remove nroff's pagination, but yeah...

umbraticus


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
@ 2019-06-09 18:26 vp
  0 siblings, 0 replies; 8+ messages in thread
From: vp @ 2019-06-09 18:26 UTC (permalink / raw)
  To: 9front

It only took me a weekend and a nudge to realize that:

	troff -man manual.man | page

is all I need.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
@ 2019-06-07  5:55 ori
  0 siblings, 0 replies; 8+ messages in thread
From: ori @ 2019-06-07  5:55 UTC (permalink / raw)
  To: sl, 9front

>      Can’t you just bind your work directory over /sys/man/[n]?  

Point.

Forget that patch, then.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9front] Manpage Previews
  2019-06-07  5:44 ori
@ 2019-06-07  5:51 ` Stanley Lieber
  0 siblings, 0 replies; 8+ messages in thread
From: Stanley Lieber @ 2019-06-07  5:51 UTC (permalink / raw)
  To: 9Front

[-- Attachment #1: Type: text/plain, Size: 90 bytes --]

     Can’t you just bind your work directory over /sys/man/[n]?  

  
sl
  

     

[-- Attachment #2: Type: text/html, Size: 129 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-09 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07  6:23 [9front] Manpage Previews vp
2019-06-07 14:09 ` Stanley Lieber
2019-06-07 21:17   ` Silas McCroskey
2019-06-08 16:48     ` Stanley Lieber
  -- strict thread matches above, loose matches on Subject: below --
2019-06-09 20:11 umbraticus
2019-06-09 18:26 vp
2019-06-07  5:55 ori
2019-06-07  5:44 ori
2019-06-07  5:51 ` [9front] " Stanley Lieber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).