Plan 9 from Bell Labs’s /usr/web/sources/contrib/yk/lab/unix9/dircpu

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
# Tells the best cpu to run commands based on context.
#
# To publish: cp $% /n/sources/contrib/yk/lab/unix9/

rfork e

if(~ $#* 1)
	dir = $1
if not {
	if(~ $#dir 0 && ! ~ $#% 0){	# sam, acme
		if(~ $"% */)	# acme
			dir = $"%
		if not
			dir = `{basename -d $"%}
	}
	if(~ $#dir 0 || ~ $dir '')
		dir = `{pwd}
}

if(! ~ $dir /n/*)
	exit 'not remote'

r = `{echo $dir | sed 's!^(/n/[^/]*).*!\1!'}
if(remote = `{cat $r/etc/hostname >[2]/dev/null}) {
	if(ruser = `{
		ls -ld $r/proc/self |
		sed 's/^[^ ]+ [^ ]+ [^ ]+ ([^ ]+) .*/\1/'
	})
		echo $ruser@$remote
	if not
		echo $remote
	exit
}

# allow unmounted remotes
remote = `{basename $r}
if(! ~ $remote local remote other sources) {
	echo $remote
	exit
}

exit 'unknown'

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].