Sample Header Ad - 728x90

How to make the zsh "correct" functionality remember my spell-correction decisions

29 votes
2 answers
4857 views
I have enabled correction (I wouldn't call it *autocorrection* specifically because of this issue) in zsh by enabling setopt correct in my .zshrc. Now, when I type dtae in a terminal, I get: dtae zsh: correct 'dtae' to 'date' [nyae]? y Tue Mar 31 11:39:31 CEST 2015 At this point I would like zsh to remember my decision. So the next time I type dtae it should automatically correct to date . However, this does not happen, and zsh is again asking me what to do: dtae zsh: correct 'dtae' to 'date' [nyae]? Unless, of course, if at that time there exists an actual dtae command or alias. **Update:** I have managed to modify the zsh source code (file utils.c, function spckword) to create a custom file containing the aliases automatically created with the invocation of zsh's "correct" functionality: original: if (x == 'y' || x == ' ' || x == '\t') { *s = dupstring(best); if (hist) hwrep(best); } modified: if (x == 'y' || x == ' ' || x == '\t') { char *aliaspath = getenv("HOME"); strcat(aliaspath, "/.zsh_correct_aliases"); FILE *out = fopen(aliaspath, "ab+"); fprintf(out, "alias %s=\'", *s); *s = dupstring(best); fprintf(out, "%s\'\n", *s); fclose(out); if (hist) hwrep(best); } Upon executing dtae, the following line is added to the file ~/.zsh_correct_aliases: alias dtae='date' However, I don't know how to source the newly modified ~/.zsh_correct_aliases file in-place.
Asked by shrx (445 rep)
Mar 31, 2015, 09:43 AM
Last activity: May 11, 2021, 01:19 PM