shithub: rc

ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /explorer/

View raw version
#!/bin/rc
# a plumber's file browser

#	wdir is /mnt/explorer
#	plumb to explorer

#	data matches [a-zA-Z¡-￿0-9_\-+.,!/]+
#	arg isdir $data
#	plumb to explorer
#	plumb client window explorer

rfork en
r = ()
v = ()
buttons = '{name} [mtime] [atime] [size]'
fn list{ls -Fp $v $r $dir}
fn display{
	echo unhide >/dev/wctl >[2]/dev/null
	echo current >/dev/wctl
	echo -n scroll >/dev/wctl
	>/dev/text{
		echo $dir
		echo $buttons '[reverse] [verbosity] [history] [new]'
		list
	}
	echo -n  >/dev/kbdin
}
ramfs -m /mnt/explorer
cd /mnt/explorer
echo -n /mnt/explorer >/dev/wdir
echo -n explorer >/dev/label
touch hist
</mnt/plumb/explorer while(>/dev/null{
	src = `{read}
	dst = `{read}
	wdir = `{read}
	type = `{read}
	attr = `{read}
	ndata = `{read}
	data = `''{read -c $ndata}
})switch($data){
case '[new]'
	window -cd $dir
case '[history]'
	cat hist >/dev/text
case '{name}'
case '[name]'
	buttons = '{name} [mtime] [atime] [size]'
	fn list{ls -Fp $v $r $dir}
	display
case '{mtime}'
case '[mtime]'
	buttons = '[name] {mtime} [atime] [size]'
	fn list{ls -Fpt $v $r $dir}
	display
case '{atime}'
case '[atime]'
	buttons = '[name] [mtime] {atime} [size]'
	fn list{ls -Fptu $v $r $dir}
	display
case '{size}'
case '[size]'
	buttons = '[name] [mtime] [atime] {size}'
	fn list{ls -Fp $v $dir | sort $r +4}
	display
case '[reverse]'
	if(~ $r -r)
		r = ()
	if not
		r = -r
	display
case '[verbosity]'
	if(~ $v -l)
		v = ()
	if not
		v = -l
	display
case *
	if(~ $wdir /mnt/explorer)
		wdir = $dir
	d = `{cleanname -d $wdir $data}
	if(test -d $d){
		dir = $d
		if(! ~ $dir `{sed -n '$p' hist})
			echo $dir >> hist
		display
	}
	if not
		plumb -s $src -w $wdir -t $type -a $attr $data
}