config

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

commit d831569e4cc74a471b7d85d3f0e5f77b1b8f8614
parent bc5fe1e43ee6a4e224017e0484857622c77e8a1e
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 18 Nov 2020 18:14:44 -0800

Add dictionary and thesaurus scripts

Add walt(ernative), wdef(inition), and wex(ists).

Diffstat:
MMakefile | 1-
Amodules/scripts/.local/bin/walt | 9+++++++++
Amodules/scripts/.local/bin/wdef | 23+++++++++++++++++++++++
Amodules/scripts/.local/bin/wex | 15+++++++++++++++
4 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -7,7 +7,6 @@ MODULES = aliases\ profile\ readline\ scripts\ - share\ sxiv\ tmux\ vim\ diff --git a/modules/scripts/.local/bin/walt b/modules/scripts/.local/bin/walt @@ -0,0 +1,9 @@ +#!/usr/bin/env dash +# thesaurus search utility. + +# pipe throught rs(1) for pretty formating. i.e.: +# $ get word | rs + +get() { grep -m1 "^${1:?No word.}," "${THESAURUS:?unset}" ;} + +get "$1" | tr ',' '\n' diff --git a/modules/scripts/.local/bin/wdef b/modules/scripts/.local/bin/wdef @@ -0,0 +1,23 @@ +#!/usr/local/bin/rc -e +# dictionary search tool. + +fn qdd { dd $* >[2] /dev/null } +fn err { printf $* >[1=2]; exit 1 } + +if (test -z $DICT_DIR) + err 'wdef: DICT_DIR: Undefined\n'; +if (test ! -d $DICT_DIR) + err 'wdef: ''%s'': Directory nonexistent.\n' $DICT_DIR + +word = $1 +file = $DICT_DIR/^`{ qdd 'bs=1' 'count=1' <<< $word | tr '[:upper:]' '[:lower:]' }^'.csv' +if (test ! -e $file) + err 'wdef: ''%s'': File nonexistent.\n' $file; + +{ + ifs = ' + ' + defs = `{ grep -i '^'$word^',' $file || err 'wdef: ''%s'': No match.' $word } + for (def in $defs) + printf '%s\n\n' `{ cut -d, -f2- <<< $def }; +} | fmt | $PAGER diff --git a/modules/scripts/.local/bin/wex b/modules/scripts/.local/bin/wex @@ -0,0 +1,15 @@ +#!/usr/local/bin/rc -e +# see if word exists. + +fn qdd { dd $* >[2] /dev/null } +fn err { printf $* >[1=2]; exit 1 } + +if (test -z $DICT_DIR) + err 'wis: ''DICT_DIR'': Unset'; +if (test ! -d $DICT_DIR) + err 'wis: ''%s'': Directory nonexistent.\n' $DICT_DIR; + +for (word in $*) { + 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 +}