config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 9ba490ae6c9c31692e7744aa25110e7d2ba0f780
parent 4d0d4569d0165a5eb16f2c710fcd30cdb8a95698
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 18 Nov 2020 20:35:06 -0800

Improve and reformat

Use $0 to get program name rather than hardcoding it in.

Handle grep errors and spread `&&' and `||' over multiple lines.

Diffstat:
Mmodules/scripts/.local/bin/wex | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/modules/scripts/.local/bin/wex b/modules/scripts/.local/bin/wex @@ -1,15 +1,24 @@ #!/usr/local/bin/rc -e -# see if word exists. +# see if a word exists. fn qdd { dd $* >[2] /dev/null } fn err { printf $* >[1=2]; exit 1 } +name = `{ basename $0 } + if (test -z $DICT_DIR) - err 'wis: ''DICT_DIR'': Unset'; + err '%s: ''DICT_DIR'': Unset' $name; if (test ! -d $DICT_DIR) - err 'wis: ''%s'': Directory nonexistent.\n' $DICT_DIR; + err '%s: ''%s'': Directory nonexistent.\n' $DICT_DIR $name; for (word in $*) { + # could run in parellel. file = $DICT_DIR/^`{ qdd 'bs=1' 'count=1' <<< $word | tr '[:upper:]' '[:lower:]' }^'.csv' - grep -iqm1 '^'$word^',' $file && printf '%s: Defined.\n' $word || printf '%s: Undefined.\n' $word + grep -iqm1 '^'$word^',' $file && { + printf '%s: `%s` Exists.\n' $name $word; + } || { + if (test $status(1) '!=' 1) + exit + printf '%s: `%s` Nonexistent.\n' $name $word + } }