zsh-users
 help / color / mirror / code / Atom feed
* zsh completion with _files
@ 2014-10-07 15:43 Cornelius Kölbel
  2014-10-07 16:02 ` Oliver Kiddle
  2014-10-07 16:09 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Cornelius Kölbel @ 2014-10-07 15:43 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 918 bytes --]

Hi,

i am writing my own zsh completion for a program.
I started today and used _arguments, _describe, compadd and _files so far.
I used tests for the previous and the pre-previous word like
$words[$#words-1 or 2] .

Now I am wondering how I can achieve this:

If the user types a "@" this marks that after the at-sign filenames are
allowed to be entered.
So I need to check the current word and compare it accordingly.

I realized that it might work this way:

        local curr=$words[$#words]

        case $curr in
        @*)
                _files
        ;;
        esac

But then it is looking for files starting with @.
So I wonder if there is any parameter telling the _files function to
drop the first character.
I see there is many documentation, but I did not find anything it it -
maybe since I do not know what to search for...

THanks a lot and kind regards
Cornelius


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: zsh completion with _files
  2014-10-07 15:43 zsh completion with _files Cornelius Kölbel
@ 2014-10-07 16:02 ` Oliver Kiddle
  2014-10-07 16:21   ` Cornelius Kölbel
  2014-10-07 16:09 ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2014-10-07 16:02 UTC (permalink / raw)
  To: Cornelius Kölbel; +Cc: zsh-users

Cornelius Kölbel wrote:
> 
> I used tests for the previous and the pre-previous word like
> $words[$#words-1 or 2] .

That might not be want you want if the cursor is in the middle of the
line rather than at the end. You might want $words[CURRENT] or
$words[CURRENT-1], etc.

> I realized that it might work this way:
> 
>         local curr=$words[$#words]
> 
>         case $curr in
>         @*)
>                 _files
>         ;;
>         esac

> But then it is looking for files starting with @.

You need to move the @ character from the PREFIX to the IPREFIX
variable. There's a shortcut for this using the compset command:
  if compset -P '@'; then
    _files
  else
    ...

Oliver


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

* Re: zsh completion with _files
  2014-10-07 15:43 zsh completion with _files Cornelius Kölbel
  2014-10-07 16:02 ` Oliver Kiddle
@ 2014-10-07 16:09 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2014-10-07 16:09 UTC (permalink / raw)
  To: zsh-users

On Oct 7,  5:43pm, Cornelius Kolbel wrote:
}
} If the user types a "@" this marks that after the at-sign filenames are
} allowed to be entered.
} So I need to check the current word and compare it accordingly.

You're probably looking for

    compset -P '*@'

Look at the manual section on "Completion Builtin Commands".  _arguments
et al. will handle calling "compadd" for you in most cases, but you have
to set up the prefixes and suffixes if there are words (in the zsh syntax
sense) from which you want to complete substrings.


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

* Re: zsh completion with _files
  2014-10-07 16:02 ` Oliver Kiddle
@ 2014-10-07 16:21   ` Cornelius Kölbel
  0 siblings, 0 replies; 4+ messages in thread
From: Cornelius Kölbel @ 2014-10-07 16:21 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

Hi Bart, hi Oliver,

thanks a lot, that did the trick...

Kind regards
Cornelius

Am 07.10.2014 um 18:02 schrieb Oliver Kiddle:
> Cornelius Kölbel wrote:
>> I used tests for the previous and the pre-previous word like
>> $words[$#words-1 or 2] .
> That might not be want you want if the cursor is in the middle of the
> line rather than at the end. You might want $words[CURRENT] or
> $words[CURRENT-1], etc.
>
>> I realized that it might work this way:
>>
>>         local curr=$words[$#words]
>>
>>         case $curr in
>>         @*)
>>                 _files
>>         ;;
>>         esac
>> But then it is looking for files starting with @.
> You need to move the @ character from the PREFIX to the IPREFIX
> variable. There's a shortcut for this using the compset command:
>   if compset -P '@'; then
>     _files
>   else
>     ...
>
> Oliver



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2014-10-07 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-07 15:43 zsh completion with _files Cornelius Kölbel
2014-10-07 16:02 ` Oliver Kiddle
2014-10-07 16:21   ` Cornelius Kölbel
2014-10-07 16:09 ` Bart Schaefer

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).