add dictionary and speller

This commit is contained in:
Greg Gauthier 2024-03-01 11:03:48 +00:00
parent 66f81cf5eb
commit 04153c29be
4 changed files with 107 additions and 7 deletions

View File

@ -74,12 +74,6 @@ function cecho(){
On_ICyan='\033[0;106m' # Cyan
On_IWhite='\033[0;107m' # White
#RED="\033[0;31m"
#GREEN="\033[0;32m" # <-- [0 means not bold
#YELLOW="\033[1;33m" # <-- [1 means bold
#CYAN="\033[1;36m"
# ... Add more colors if you like
NC="\033[0m" # No Color
# printf "${(P)1}${2} ${NC}\n" # <-- zsh

24
scripts/dictionary Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
mkdir -p "${HOME}"/.local/tmp
searchterm=$(zenity --entry --text "Enter word to define" --title "Dictionary" 2> /dev/null);
dict -h localhost -d gcide "${searchterm}" > "${HOME}"/.local/tmp/"${searchterm}".txt 2>&1
content=$(cat "${HOME}"/.local/tmp/"${searchterm}".txt);
if [[ "${content}" == *"No definitions found"* ]]; then
icon=""${HOME}"/.local/bin/img/caution-48.png"
else
icon=""${HOME}"/.local/bin/img/checkmark-32.png"
fi
zenity --text-info \
--window-icon="${icon}" \
--filename="${HOME}"/.local/tmp/"${searchterm}".txt \
--font="IBM Plex Mono Medium 11" \
--width=750 \
--height=600 2> /dev/null
sleep 0.5
rm -rf "${HOME}"/.local/tmp/"${searchterm}".txt

35
scripts/spchk Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
function parseResults() {
oIFS=$IFS
IFS=":"
declare -a fields=($1)
export QUERYTERM=$(echo "${fields[0]}"|awk '{print $1}');
export LISTCOUNT=$(echo "${fields[0]}"|awk '{print $2}');
export WORDLIST=$(echo "${fields[1]}"|sed 's/^\s*\|\s*$//g');
IFS=$oIFS
unset oIFS
}
if [ $# -eq 0 ]; then
>&2 echo "Please provide a word for spell checking. Include quotes."
exit 1
fi
if [[ "$1" =~ ^[0-9]+$ ]]; then
cecho IWhite On_IRed "ERROR. Only Words Please. No Numbers!"
exit 1;
fi
export RESULT=$(echo "$@"|aspell -a|sed "1 d"); # Deletes the header line
export FIXED="${RESULT/& }" # Removes ampersand causing parsing errors.
if [[ "${FIXED}" == *"*"* ]]; then
cecho IBlack On_IGreen "CORRECT!"
else
parseResults "${FIXED}"
cecho IBlack On_IRed "INCORRECT!"
cecho Black On_Yellow "There are ${LISTCOUNT} suggested corrections for '${QUERYTERM}': ${WORDLIST}. "
fi

47
scripts/speller Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
function parseResults() {
oIFS=$IFS
IFS=":"
declare -a fields=($1)
export QUERYTERM=$(echo "${fields[0]}"|awk '{print $1}');
export LISTCOUNT=$(echo "${fields[0]}"|awk '{print $2}');
export WORDLIST=$(echo "${fields[1]}"|sed 's/^\s*\|\s*$//g');
IFS=$oIFS
unset oIFS
}
searchterm=$(zenity --entry --text="Enter search term:" --title="Speller" --width=300 --height=40 2> /dev/null);
if [ -z "${searchterm}" ] | [ "${searchterm}" == " " ]; then
zenity --info --text="<b>ERROR</b> No search term provided!"\
--icon-name=error \
--window-icon="${HOME}/.local/bin/img/xmark.png" 2> /dev/null
exit 1;
fi
if [[ "${searchterm}" =~ ^[0-9]+$ ]]; then
zenity --info --text="<b>ERROR</b> only words, please!"\
--icon-name=error \
--window-icon="${HOME}/.local/bin/img/xmark.png" 2> /dev/null
exit 1;
fi
export RESULT=$(echo "$searchterm"|aspell -a|sed "1 d"); # Deletes the header line
export FIXED="${RESULT/& }" # Removes ampersand causing parsing errors.
if [[ "${FIXED}" == *"*"* ]]; then
zenity --info --text="<b>CORRECT!</b> " \
--icon-name=info \
--window-icon="${HOME}/.local/bin/img/check-mark-11-16.png" 2> /dev/null
else
parseResults "${FIXED}"
message="<b>There are ${LISTCOUNT} suggested corrections for '${QUERYTERM}':</b> ${WORDLIST}"
zenity --info --text="${message}"\
--icon-name=warning \
--window-icon="${HOME}/.local/bin/img/caution-48.png" 2> /dev/null
fi