#!/bin/sh ## Generate ten lines (or a specified number) of random names in columns. ## Usage: namegen [LINES] ## ## namegen 0.4 Copyright 2005-7 by Adam Katz, redistribute under the GPL v2+ # Note, Sun /bin/sh is not posix-compliant. Use /bin/ksh or /bin/bash instead. type apg >/dev/null 2>&1 || apg() { echo "You'd get better results with APG (Automated Password Generator)..." >&2 sed `echo "$*"|sed 's/.*-n//'`0q /dev/urandom |strings \ |tr '[A-Z]' '[a-z]' |sed -e 's/[^a-z]//g' -e "s/....../&\n/g" -e '/..../!d' } lines=`echo ${1:-10} |sed 's/[^0-9]//g'` [ -z "$lines" ] && sed -e '/^## /!d' -e 's///' `which $0 || echo $0` && exit 1 eval `resize 2>/dev/null` # get window width # if 'aspell list' will list mispelled words (and not real words), use it [ "`echo vgqvq word |aspell list 2>/dev/null`" = vgqvq ] && spell="aspell list" ( for name in ` apg -M l -m4 -x6 -n"$(($lines*200))" \ |grep "[rstln]" |grep "[aieo]" \ |egrep -v "cr?$|c[^khr]|[aieou]{2}|[bcdfgjkmnpqtvwxz]{2}" \ |${spell:-cat} `; do while [ ${#name} -lt 7 ]; do name=" $name"; done # spacing for columns i="$((${i:-1} + 1))" # count words per line printf "$name" [ $i -gt "$((${COLUMNS:-80}/7))" ] && echo "" && i=1 # line full -> new line [ $? = 0 ] && lines="$(($lines - 1))" && [ 0 = "$lines" ] && exit 0 # done? done) # done when $lines has shrunk to zero (as above) or we're out of names