shithub: x

ref: 28a6ca4c43f4b78df9aec8f8be3c26849480a0f6
dir: /path/

View raw version
#!/bin/rc
# x/path -- extract datums from the path
rfork e
if(! ~ $$#* -*)
	wd=$$#*
if not
	wd=`{pwd}
for(arg){
	switch($arg){
	case -P
		echo $wd | sed 's,/[^/]+/[^/]+(.*),\1,'
	case -p
		echo $wd | sed 's,/[^/]+/[^/]+/(.*),\1,'
	case -r
		echo $wd | sed 's,(/[^/]+/[^/]+).*,\1,'
	case -l
		echo $wd | awk -F/ '{if($3) print $3; else print $0}'
	}
	shift
}