shithub: x

Download patch

ref: 7760194f148720cc9d9432d47090ad4f1954a297
parent: 20ecadc4bee20598de971afda585621f6d89471b
author: kvik <kvik@a-b.xyz>
date: Tue Apr 14 09:29:52 EDT 2020

Factor out the usage fn into lib.rc; convert scripts

--- a/cd
+++ b/cd
@@ -1,2 +1,8 @@
 #!/bin/rc
+rfork e
+. /sys/lib/x/lib.rc
+usage = '
+	x/cd
+'
+
 echo cd `{x/path -r}
--- /dev/null
+++ b/lib.rc
@@ -1,0 +1,9 @@
+fn die {
+	>[1=2] echo $0: $*
+	exit $"*
+}
+
+fn usage {
+	>[1=2] echo -n 'usage:' $usage
+	exit 'usage'
+}
--- a/man
+++ b/man
@@ -1,16 +1,12 @@
 #!/bin/rc
-# x/man -- print manual pages from remote systems
 rfork e
+. /sys/lib/x/lib.rc
+usage = '
+	x/man [-b] [man-flags] [section] title
+'
 
 flags=()
-section=()
 width=72
-
-fn usage {
-	>[1=2] echo usage: x/man [-b] [man-flags] [section] title
-	exit usage
-}
-
 out='stdout'
 section=()
 title=()
--- a/mkfile
+++ b/mkfile
@@ -1,20 +1,26 @@
 BIN=/bin
-MAN=/sys/man/1
+MAN=/sys/man
+LIB=/sys/lib
 RC=path run mnt cd man vt
 
 all:VQ:
 	echo 'An unsightly package appears: "Meal, Mk-install-to-Eat."'
 
-install:V: ${RC:%=%.install} $MAN/x
+install:V: ${RC:%=%.install} lib.rc.libinstall $MAN/1/x
 
 %.install:V: % $BIN/x
 	cp $stem $BIN/x
-$BIN/x:
-	mkdir -p $BIN/x
 
-$MAN/x: x.man
-	cp x.man $MAN/x
+%.libinstall:V: % $LIB/x
+	cp $stem $LIB/x
 
+$BIN/x $LIB/x:
+	mkdir -p $target
+
+$MAN/1/x: x.man
+	cp x.man $MAN/1/x
+
 uninstall:V:
 	rm -rf $BIN/x
+	rm -rf $LIB/x
 	rm -f $MAN/x
--- a/mnt
+++ b/mnt
@@ -1,11 +1,9 @@
 #!/bin/rc
-
 rfork e
-
-fn usage {
-	echo usage: x/mnt [[user@]host ...] >[1=2]
-	exit usage
-}
+. /sys/lib/x/lib.rc
+usage = '
+	x/mnt [[user@]host ...] 
+'
 
 fn mnt {
 	user=(root $user)
--- a/path
+++ b/path
@@ -1,6 +1,10 @@
 #!/bin/rc
-# x/path -- extract datums from the path
 rfork e
+. /sys/lib/x/lib.rc
+usage = '
+	x/path [-Pprl]
+'
+
 if(! ~ $$#* -*)
 	wd=$$#*
 if not
--- a/run
+++ b/run
@@ -1,5 +1,10 @@
 #!/bin/rc
 rfork e
+. /sys/lib/x/lib.rc
+usage = '
+	x/run [ssh-flags] command
+'
+
 flags=()
 while(~ $1 -* && ! ~ $1 --){
 	flags=($flags $1)
--- a/vt
+++ b/vt
@@ -1,4 +1,10 @@
 #!/bin/rc
+rfork e
+. /sys/lib/x/lib.rc
+usage = '
+	x/vt [command]
+'
+
 rpath=`{x/path -P}
 cmd=`{awk 'BEGIN{
 	x = ENVIRON["*"]