shithub: x

ref: 5e8c2b307bc565be7e9f03ce24957745d38cc555
dir: /path/

View raw version
#!/bin/rc
rfork e
. /sys/lib/x/lib.rc
usage = '
	x/path [-Pprl]
'

if(! ~ $$#* -*)
	wd=$$#*
if not
	wd=`{pwd}
wd=`{cleanname $wd}
for(arg){
	switch($arg){
	case -P
		sed='s,/[^/]+/[^/]+/[^/]+(.*),\1,'
	case -p
		sed='s,/[^/]+/[^/]+/[^/]+/(.*),\1,'
	case -r
		sed='s,(/[^/]+/[^/]+/[^/]+).*,\1,'
	case -l
		sed=()
		echo $wd | awk -F/ '{if($4) print $4; else print $0}'
	}
	shift
}
if(! ~ $sed ''){
	if(! ~ $wd /x/*)
		exit 'invalid path'
	if not
		echo $wd | sed $"sed
}