shithub: bin.rc

ref: c57c8ab75d68d973e7b032792c6b729efcc13a93
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
	}
}