wm: infra

ref: 4124e6fda5da5ceeffa321074fbcbdcc72697c8d
dir: /plan9/pasted/

View raw version
#!/bin/rc
# wm/pasted path
# a simple pastebin, use with aux/listen

fn genrand {
	rand = `{dd -quiet 1 -if /dev/random -bs 1 -count 2 | xd -1 | awk '{$1=""; print $0}' | tr -d ' '}
	# not to override  non-empty files
	if(test -s $dir/$rand){
		genrand
	}
}

if(~ $#* 0) {
	echo 'usage: wm/pasted dir [prefix]' >[1=2]
	exit usage
}
if not
	dir = $1

if(~ $#* 2)
	prefix = $2
if not
	prefix = ''


genrand $1
echo $prefix^$rand
touch $dir/$rand
chmod +at $dir/$rand
read -m -c `{echo '1024 * 1024 * 8'| bc} > $dir/$rand

# remove some of empty entries
if(! test -s $dir/$rand)
	rm $dir/$rand
if not
	chmod go-w $dir/$rand