shithub: lpa

ref: ecef9816dc8f772ca7f93cfcfe914759065e358f
dir: /lpa/

View raw version
#!/bin/rc

rfork ens

id=0
readonly=0
printlist=0

fn usage{
	echo 'usage: lpa [-n session | -r session | -l]'
	exit 'usage'
}

fn nosession{
	echo 'session '^$id^' does not exist'
	exit 'no such session'
}

while(~ $1 -*){
	switch($1){
	case -n
		if(! ~ $id 0)
			usage
		id=$2
		shift
	case -r
		if(! ~ $id 0)
			usage
		readonly=1
		id=$2
		shift
	case -l
		if(! ~ $id 0)
			usage
		printlist=1
	case -*
		usage
	}
	shift
}

if(! ~ $#* 0)
	usage

# Start LPA if it isn't already running
lpafs
# Make /mnt/lpa available to sam and rio..
plumb 'Local lpafs'

if(~ $printlist 1){
	echo `{cd /mnt/lpa; ls | grep -v '^new$'}
	exit
}

if(~ $id 0)
	id=`{cat /mnt/lpa/new}
if not{
	if(! test -d /mnt/lpa/$id/)
		nosession
}

cd /mnt/lpa/$id
label LPA session $id

if(~ $readonly 1)
	cat cons
if not{
	cat cons &
	while(line=`''{read}){
		n=`{tail -1l /dev/text | sed 's/^[ ]*//' | wc -r} # number of runes to delete
		awk 'END {
			for(i = 0; i < '^$n^'; i++)
				printf("\b");
		}' /dev/text
		echo -n $line > cons
	}
}