From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12680 invoked from network); 12 May 2021 13:45:27 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 May 2021 13:45:27 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1620827127; b=EWCabzeJslvpIlqLrIWNg9pjpk3ATECkP0arJd6qj6a8g1GA7NGLmS1FpYsi02BABeJevlj+UY 0vQquaDUlvUwR5MQG/vdE9QmtFtn4dY+cEgwkBWivek+XVpfy1Qz6sPWGqJQQp12h7+JXaPg3N j2QRifC0vQjjWHzfsDHCbVvSmWCTW0BQiHHWi/+Smr69IIH3FqLcIK+djBXgSu0vpJB04R8jNW wTfMX3yL0pUvze/gV+Ia0Ojbwxj4HQHHy2+OL6M/xqtYzVpH0yxIJT97jZTygxbxSKQA0r1Lpn ZWoxi/i2b+oB1mJJEYJP9bWRYuZA2sQ+Cb/ocFT6ytfegQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f171.google.com) smtp.remote-ip=209.85.219.171; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1620827127; bh=G4fbxtbDvW70muRgc6kOizPTmIsbtwD9zYp+pgbCmG0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=yKaGozvsSMQq+QGl5nMLzLX8EnApSP2/Db4nN/bDmbzDVEF/oNCLW/H98+SEs/fcDriIDxaTSS RELL9G4+bCKbWAY/xNdfqx31FhF7lLBdKwfLNwJVmqX8FV/z9CW/pFKJqYnf+wl7FipgXO4I6r cGa1OMX4REZu+JhWFI+uPIJp1CEHH1HqZjTueK41y3zuW7NzJgquSHemMur+BiCiqWVNHIGBKS IDr8PEK/3f9k0VDx4gEYy9TS8rfd8GwyFZVPutvxIW2LWdYW4PH2wZHPn3TDjZbtaocBi5tH35 0X7D7udSClyGu1nQFs+cq3gmdavIgsjMNrd5gGbh42xCSA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=DmKhDw+02y2IrHY4JyBZb73l9rgglfbr72cIdR6rJts=; b=dqlnlu6ZHQZ5IPQvM6zIiJ1C2O p9CTTb/hZrjrFdEhuyBmoh4hYRVgY8xr126F5oX/JR+K04LUFxk9yPM0noulOrfVg2x4fKR4Ecjh6 au/wWPi7o3cUA6orLSILrywpm/9ofRK7Sf4t0H6x6y1flQUpjLIy6BQiRKJ5p8wmQ/Iwr88O7ClVR Rl3ba8M3tl3CdeieDr2rRtU1gAh5OtUyLPkFgBm8EqkfOvPjt9qBor2GaZe7xFHyqw1YGvGU9U3kc SYaz96tPsdQvUG59k88WjQX/p/EKQK/rrC3GPBJIjkAP3WMiA8rjH/hI3yu7BTvCJVOfOwW/JO2mv PeRHh4Kg==; Received: from authenticated user by zero.zsh.org with local id 1lgpAz-000ORg-MO; Wed, 12 May 2021 13:45:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f171.google.com) smtp.remote-ip=209.85.219.171; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-yb1-f171.google.com ([209.85.219.171]:42846) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lgpAA-000Nhs-9M; Wed, 12 May 2021 13:44:36 +0000 Received: by mail-yb1-f171.google.com with SMTP id r8so30773747ybb.9 for ; Wed, 12 May 2021 06:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DmKhDw+02y2IrHY4JyBZb73l9rgglfbr72cIdR6rJts=; b=YoFieNZl2rlUe6dpyZUHIe78tAEKKn05kgxMzotUrVSXPyLcYBG+cqYFzggp9613GW sfTqq52xcK5I+3QNF7pfzjWlsWDKayYNgzLzmzoAiOatlSx5EG/jalNBdadHABqebeO0 qJQZ2sipHdmP5xNmJ2uiP7c3zQBP1bHGuJ8HxAm59VcFmYz1bh2zJlLQDlcQypiF719g dcu6wLr5vNnXJAlUtpuM2znp3Nm43DzgAtqc3p0T+N/XDAWIjbAY5CV4LqT1/PyZqDXO 8LHeZvXz/j2eGDRxtITh/U/Xgpchld+a1iTjoJqDgk1nquIk5V4wW36bxeb/u3b1vP4v J3ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=DmKhDw+02y2IrHY4JyBZb73l9rgglfbr72cIdR6rJts=; b=Gdxhe5iAWA/PWmInxNpqRzozJOiCSQ47Kq2aTHztQSrViQmFb6St2gZOlJ3kIoF1Cd Zvg33j2MYoGYaE2zTThaq/gr0XSHfGBM2aWEFNNlC3/Y2hWfdezc/zYP5TeMxi4wTPhY KCIxT9p+GvZEqYVTM9d5+6I2PXCxTlL0H3D/vcnl3AE8GquG8N9LUODIE1WBAgwCR3Mt uLBv5tvsIwzkdSwA1uRd1dbTUtlhpTjd4D2At0L3tG5LKiaHohe57vm128TBdyAHThLV rBobUMHYEolGfqlvoFsBqCwcbCWxAxftYFSsF/MdH4SKUffoqOON17Z4ahkdCNi6NqZ0 ps3w== X-Gm-Message-State: AOAM531xD0w1PomRi8zwWz0hiz+cD4F9PC5YucEexLGGiVpuePsqGSYK oXTlLmDvzxI2n9RCn7SP60RF3A5JD27rPgkF6A0= X-Google-Smtp-Source: ABdhPJw41BQlo8LaR7SMozW1f3AkHIGz31k1F0ZbrO8/pyag66LIVhZMzqdGFq+0LI+7qdXVuI674bAFW56xwFKqAKM= X-Received: by 2002:a25:8249:: with SMTP id d9mr26737016ybn.471.1620827072775; Wed, 12 May 2021 06:44:32 -0700 (PDT) MIME-Version: 1.0 References: <27484ec7-fc56-4164-b9b6-edfb62df0514@www.fastmail.com> In-Reply-To: <27484ec7-fc56-4164-b9b6-edfb62df0514@www.fastmail.com> From: Philippe Proulx Date: Wed, 12 May 2021 09:44:06 -0400 Message-ID: Subject: Re: How to complete with _arguments() depending on an option and within a loop To: Daniel Shahaf Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 26725 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Tue, May 11, 2021 at 10:13 AM Daniel Shahaf wro= te: > > Philippe Proulx wrote on Mon, 10 May 2021 17:30 +00:00: > > $ prog --state=3Dfoo --meow --state=3Dbar cola --mix --lol=3D34 \ > > --state=3Dfoo --meow --zoom > > > > In a Zsh completion script, how would you complete the options above, > > knowing that: > =E2=8B=AE > > I managed to implement such a completion script "manually", with the > > `words` and `CURRENT` variables, compset(), and _describe() to add > > completions. It works, but I feel like I'm rewriting parts of > > _arguments(). > > > > Is there a known way to achieve this mostly with _arguments()? > > Look at _beep. It does basically what you're describing, and does use > _arguments for the core logic. > > I'd go for something along the lines of: > > _prog() { > local -a args=3D( --state=3D': :(foo bar)' ) > if ((CURRENT > 1)); then > case ${words[(Ib.CURRENT-1.)--state=3D*]} in > (*=3Dfoo) args+=3D( -meow -zoom );; > (*=3Dbar) args+=3D( --mix --lol :cola );; > esac > fi > (munge $words as _beep does) > _arguments : "${args[@]}" > } This seems fragile. For example (I know it's far-fetched here, but just to make my point), what if your device file is literally named `--new` in the current working directory, such that you would write: $ beep --device=3D--new or $ beep --device --new Now, completion doesn't work as expected: $ beep --device --new Zsh offers `--device` again, because the completion script "saw" the `--new` word, without taking any parsing into account. My point being: I'll still need to handle command-line parsing manually, including supporting both `--opt=3Darg` and `--opt arg` forms, etc. to find where the current state (equivalent of the `--new` option of beep(1)) really begins. Phil > > Cheers, > > Daniel