All pastes #1243283 Raw Edit

Untitled

public text v1 · immutable
#1243283 ·published 2008-11-02 16:19 UTC
rendered paste body
#!/bin/rc


# rc (plan9 shell) helper for wrappers, v1.1
# 
# suppose you want to make wrapper for `git', also named `git'
# you place it in a private directory, and include in $PATH
# 
# now this wrapper can't simply call `git', for it would call itself
# but you don't want it to use a hardcoded path, either, for obvious reasons
#
# solution: use this wrappper. it removes from $path the path it resides, and re-runs `git'
#
# released into public domain by dexen deVries, Sun Nov  2 14:03:27 CET 2008
# be warned, that a more elegant solution is possible (but i dunno how to implement it)
 
 
fn err {
	echo $* >[1=2]
}


fn xSubSame {
	cmd=$1; shift
	d=`{dirname $0}
	found=false
	p=()
	orig=$path
	for ( i in $path ) {
		if ( ~ $d $i )
			found=true
		if not
			p=( $p $i )
	}
	if ( ! $found ) {
		err 'Dir of current program `'$d''' not found in path `'$"path''''
		exit 1
	}
	path=$p ex=`{which $cmd}
	path=$orig
	exec $ex $*
}