From fdddcc5e95d227762849c741e7a5cdbdbe01669a Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 20 Jan 2018 19:37:07 +0100 Subject: dicewords: support dictionary --- dicewords | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/dicewords b/dicewords index 3a450fa..49d9230 100755 --- a/dicewords +++ b/dicewords @@ -1,11 +1,40 @@ -#!/bin/sh +#!/bin/bash + +set -e +set -u + +usage() { + echo "Usage: $0 [-d &2 + exit 1 + esac +done +shift $(($OPTIND - 1)) count=${1:-6} -if [ "$count" = "-h" ]; then - echo "Usage: $0 [count]" +if ! [[ $dictionary == *"/"* ]]; then + dictionary=/usr/share/dict/"$dictionary" fi -egrep '^[a-z]{1,6}$' /usr/share/dict/american-english | shuf | head -n "$count" | tr '\n' '-' | sed -e 's/-$//' -echo +if ! [ -e "$dictionary" ]; then + echo >&2 "$dictionary does not exist" + exit 1 +fi +egrep '^[a-z]{1,6}$' "$dictionary" | shuf | head -n "$count" | tr '\n' '-' | sed -e 's/-$//' +echo -- cgit v1.2.3