zsh-users
 help / color / mirror / code / Atom feed
* howto correct 7etc to /etc ?
@ 2004-10-05 23:58 Andy Spiegl
  2004-10-06 16:03 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Spiegl @ 2004-10-05 23:58 UTC (permalink / raw)
  To: ZSH User List

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.

Can that be done?  My first guess was to take _expand_dots and modify it
but I must admit that I am still not enough of a zsh-guru to be able to do
it by myself.

Thanks for any hint,
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Acupuncture is a jab well done.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: howto correct 7etc to /etc ?
  2004-10-05 23:58 howto correct 7etc to /etc ? Andy Spiegl
@ 2004-10-06 16:03 ` Bart Schaefer
  2004-10-06 21:36   ` Andy Spiegl
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-10-06 16:03 UTC (permalink / raw)
  To: ZSH User List; +Cc: Andy Spiegl

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: howto correct 7etc to /etc ?
  2004-10-06 16:03 ` Bart Schaefer
@ 2004-10-06 21:36   ` Andy Spiegl
  2004-10-07  2:50     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Spiegl @ 2004-10-06 21:36 UTC (permalink / raw)
  To: ZSH User List

> Then you add _7slash to your completer style after _correct, so that it's
> only tried if some other correction isn't found first.
Hey, great!  I didn't think it would be that easy.  I really love zsh!

Hm, would it also possible to expand this mechanism to also correct this
more complicated example:
 $ cd /etc7apache<TAB>

Thanks a lot once again Bart,
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Pro is to con as progress is to Congress.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: howto correct 7etc to /etc ?
  2004-10-06 21:36   ` Andy Spiegl
@ 2004-10-07  2:50     ` Bart Schaefer
  2004-10-07  8:42       ` Andy Spiegl
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-10-07  2:50 UTC (permalink / raw)
  To: ZSH User List; +Cc: Andy Spiegl

On Wed, 6 Oct 2004, Andy Spiegl wrote:

> Hm, would it also possible to expand this mechanism to also correct this
> more complicated example:
>  $ cd /etc7apache<TAB>

Probably something like this:

function _7slash {
   local noseven=${words[CURRENT]//7/\/}
   if [[ $words[CURRENT] != $noseven ]]
   then
     compadd -U -X 'Correct 7 to /' -f $noseven
   fi
}

There's all sorts of room for improvement here ... it could look only at 
the part to the left of the cursor depending on styles or the setting of
the complete_in_word option; etc.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: howto correct 7etc to /etc ?
  2004-10-07  2:50     ` Bart Schaefer
@ 2004-10-07  8:42       ` Andy Spiegl
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Spiegl @ 2004-10-07  8:42 UTC (permalink / raw)
  To: ZSH User List

> Probably something like this:
Works great, but it replaces _all_ sevens with slashes
no matter whether there is an existing directory with that name. :-(

But thanks anyway,
 Andy.

-- 
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 "Silence is consent."  - Sir Thomas Moore, before his execution.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-10-07  8:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-05 23:58 howto correct 7etc to /etc ? Andy Spiegl
2004-10-06 16:03 ` Bart Schaefer
2004-10-06 21:36   ` Andy Spiegl
2004-10-07  2:50     ` Bart Schaefer
2004-10-07  8:42       ` Andy Spiegl

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).