#!/bin/rc # rc (plan9 shell) helper for wrappers # # 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 { d=`{dirname $0} found=false p=() 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 pwd exec $* }