shell-utils/app/spchk

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-07-15 19:21:25 +00:00
#!/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 "No arguments provided"
exit 1
fi
if [[ "$1" =~ ^[0-9]+$ ]]; then
zenity --info --text="<b>ERROR</b> only words, please!"\
--icon-name=error \
--window-icon="/home/gmgauthier/.local/bin/img/xmark.png" 2> /dev/null
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
zenity --info --text="<b>CORRECT!</b> " \
--icon-name=info \
--window-icon="/home/gmgauthier/.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/gmgauthier/.local/bin/img/caution-48.png" 2> /dev/null
fi