Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: howto correct 7etc to /etc ?



On Wed, 6 Oct 2004, Andy Spiegl wrote:

> I'd like to configure my completion so that when I type
>  $ ls 7etc<TAB>
> 
> it corrects the mistyped 7 to   (note: on German keyboards / is shift-7)
>  $ ls /etc
> but only if the 7 is the first character of a path and if there isn't any
> real file or directory that starts with a 7.  Unfortunately "_correct"
> doesn't do the job in this case.

Something like this should do it:

function _7slash {
   if [[ $words[CURRENT] = 7(#b)(*)(#e) ]]
   then
     compadd -U -X 'Correct leading 7 to /' -f /$match[1]
   fi
}

Then you add _7slash to your completer style after _correct, so that it's 
only tried if some other correction isn't found first.


If you want _correct_word (bound to ^Xc) to use _7slash, you have to edit 
that function to append _7slash to the arguments of the _main_complete 
call.  Arguably _correct_word should examine a style for the list of 
completers to use (possibly in addition to _correct rather than instead of 
it), but presently it does not.



Messages sorted by: Reverse Date, Date, Thread, Author