1

I'm on macOS and using zsh. I have about a hundred Markdown files which I would like to spell check from the command line. It seems like aspell is the right way to do this, however I want to be able to bail out of the spell checking before it's reached the end of the last file.

I would have thought that this would be a common use case, but I can't see a way to do this. aspell only checks one file at a time. There are SO questions which provide solutions to loop through files, with either shell loops or find XXX -exec. You CAN use b or Ctrl-C to abort a single file in aspell. But aspell returns 0 even when you abort, so I can't use that to check if the user wants to stop the loop.

Really, the only solution that springs to mind is to output a confirmation line between each file to ask if the user wants to continue. This strikes me as really cumbersome, especially since it would be output even if the file in question didn't have any misspelled words which aspell needed to correct!

Is there some way to either determine that the user has aborted the aspell session (and thus stop the loop), or else intercept Ctrl-C before it reaches aspell so that the script can set a flag and gracefully stop at the end of the current iteration? I'm happy to use Python to manage the iteration if that helps matters.

ALTERNATIVELY, is there a better spell checking tool out there which doesn't have the limitations of the now quarter-century-old aspell?

Nick K9
  • 141

0 Answers0