Plan 9 from Bell Labs’s /usr/web/sources/contrib/yk/lab/unix/x

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


#!/Users/yarek/plan9/bin/rc
#
# Executes a command over SSH, taking care of the following, along the way:
# - the remote host name is your environment, $CPU, or deduced with dircpu
# - the remote working directory is deduced from local one, withing certain convention
# - the remote command line is escaped to preserve argument lists as is
# - the remote environment is initialized from your profiles
#
# To publish: cp $% /n/sources/contrib/yk/lab/unix/
#

. /Users/yarek/plan9/bin/9.rc

fn quotesh {
	whatis '*' | sed 's!\*=!!; s!^[(]!!; s![)]$!!; s!''''!''\\''''!g'
}

xflags = ()
if(~ $1 -*) {
	xflags = $1
	shift
}

if(~ $#CPU 0)
	CPU = `{dircpu}
if(! ~ $#CPU 1){
	echo >[2=1] 'x: pick one CPU'
	exit usage
}

remdir = `{pwd | sed '
	s#(^' ^ $HOME ^ '|^)/(n)/(remote|local|'$CPU^')($|/)#/#
	s#^'$HOME^'$#.#
'}

pre = ()
if(~ $#xnoprofile 0)
	pre = ($pre 'service=x; . /etc/profile; . ./.profile;')
if(~ $#xnocwd 0)
	pre = ($pre '{ \cd '$remdir^'; } >&2;')

nl  = '
'
argv = ()
# rewrite absolute pathnames in the arguments
for(arg) {
	if(~ $arg */n/^(remote local $CPU)^/* && test -e $arg) {
		IFS=$nl {
			arg = `{echo $arg | sed 's!(^' ^ $HOME ^ '|^)/(n)/[^/]*/!/!'}
		}
	}
	argv = ($argv $arg)
}
ifs='' {
	* =  ($pre `{quotesh $argv})
}
ssh $xflags $CPU $*

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.