shithub: bin.rc

ref: 4e18dc77f2ab9257b363ccb480a69cb9def901ba
dir: /bin/new/

View raw version
#!/bin/rc -e
rfork e
fn usage {>[1=2] echo 'usage:' $usage && exit 'usage'}
usage='new [file]'

mode = 755
skeldir = $home/skel
skel = $skeldir/rc
while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -m
		mode = $2
		shift
	case --*
		skel = $skeldir/`{echo $1 | sed 's/^--//'}
	}
	shift
}
if(~ $1 --)
	shift

files = $*
if(~ $#files 0)
	files =`{fortune <{</lib/words awk 'length($0) == 3 {print tolower($0)}'}}

for(f in $files){
	if(~ $f */*)
		mkdir -p `{echo $f | sed 's@(.*)/.*$@\1@'}
	if(test -e $f)
		>[1=2] echo 'file exists:' $f
	if not{
		echo $f
		cat $skel >$f
		chmod $mode $f
		plumb -d edit $f
	}
}