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=-1.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14188 invoked from network); 29 Aug 2020 18:34:06 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 29 Aug 2020 18:34:06 -0000 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=S0eO3XGxQJ527rjvLom3KBVVAAjslsOz0IDKwsAMSgg=; b=jt1IWJRCo/CHVaZBl0Ea8FyOOi jxnMRnJSgca33zEnymaGiTv3jF5I4cnRevBba1GmeHDDtkJ/hq4LeBQMUx8o00N+b0Vkodov7xQrt YKl52kRUHbno1qMfz6XEAgI/b7bY6swrsp/18LDHaP4s9Wl6fsWB3dAlkvj3JHEYKtoEUXl7EkiAA Zq4wOmbVir4Cx+9lWwFhjxfivrGmeKViy7+ENHKGWsE3eU2/G2L23T7Rdke6oE1ExGtw0MR1+lir/ UdpXeytfYTUCRlzXh6XnjiAYcEkoyagTv7QtFRSpzNy3TuABa7kJpoLCOBRlnZYB6bS0VKjUQKFYi OldvUeRA==; Received: from authenticated user by zero.zsh.org with local id 1kC5fs-000Een-Tl; Sat, 29 Aug 2020 18:34:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f54.google.com) smtp.remote-ip=209.85.210.54; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=skipped; arc=none Received: from mail-ot1-f54.google.com ([209.85.210.54]:45578) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kC5fQ-000EHo-DA; Sat, 29 Aug 2020 18:33:33 +0000 Received: by mail-ot1-f54.google.com with SMTP id 5so2034000otp.12 for ; Sat, 29 Aug 2020 11:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=S0eO3XGxQJ527rjvLom3KBVVAAjslsOz0IDKwsAMSgg=; b=KdO91D/2c8+qE2h2ychSyDyZ8feUORt7PY/Vw0BRKuq+CnOVfLgtTS9zb2/Pjzu+Gr vReON7INfupP8iA99AZykpJxg9FsyjzonQeYx7xnlzmoC5kLD32JtNREGI09yJPt+owW TUP9YrLk9F8Hb5fghTanc1dgRiAXZQBfxXCuYIIeADyIqS0rcWhvPT9sXmFs/FSeJqB4 k4OO6bnXXb1r3njdFf4CsZgOThnU+GAAvS/OBEItqXYJx1kya3A/L75p2cn6HehxSVV8 ZyEnOvNrcG/aiFF6+GU5h51jhXcY78QMPU1d+Uz9gypgjEf5KaY5D22EmwfYW1ZDFGWe 4RSA== 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; bh=S0eO3XGxQJ527rjvLom3KBVVAAjslsOz0IDKwsAMSgg=; b=sheUB4XFTt/n0yLuEb29CnNw6oMxEaEDyN+GwkKviK6gnazXDzR7KMCzEHJcbIn28s QMuR0MBzEM3crKRhU3tXPIBl6Z+G4KYMbllXfmqbXtQ8ZdzkLPuXxCZdFAcUpy83JZom ca/203BCBh5TXfQG1KLVS2UV91LkkKBByrK5e8Lys4XKN+5f0NLqlcJogsey0ppEn1fR YKowCpgPC0Vg4/hpIFU1s29sa6RnxOAvG9FVbI9OGN5+NSqojzHwiY6vzrKXF/PG9PAi pj9Lt4vFNGJj9Df7IMyJ77Q5DlYeIV73ZXQiAc5pa6eID5hG0OqSy+4kqRO8eGOJQw0g A0KQ== X-Gm-Message-State: AOAM532Cxly0NbwbLZoR6wVjjbPj2MRSiNW9BTevpIujcemPbiK9xNn4 PxqYePshhhmGBO8TxSTS0Nz/r13xZ0DERHLJQiT6Zg== X-Google-Smtp-Source: ABdhPJwmaGsUqQmKYBRV3d5LOllN8PsEjm+YSt8zSwyG1QArkFqdmJsQlvkU/qybgx1+5yhe9TuXmxB2eN6KnDBK6Cw= X-Received: by 2002:a05:6830:12d1:: with SMTP id a17mr2891811otq.229.1598726010877; Sat, 29 Aug 2020 11:33:30 -0700 (PDT) MIME-Version: 1.0 References: <301108111.164161.1598719628682.ref@mail.yahoo.com> <301108111.164161.1598719628682@mail.yahoo.com> In-Reply-To: <301108111.164161.1598719628682@mail.yahoo.com> From: Bart Schaefer Date: Sat, 29 Aug 2020 11:33:19 -0700 Message-ID: Subject: Re: detect if command has a completion function To: vapnik spaknik Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26047 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: Archived-At: On Sat, Aug 29, 2020 at 9:47 AM vapnik spaknik wrote: > > The reason I need this capability is to help with a function I've written for cleaning up .zshrc files. > ... I wrote a function which checks the commands mentioned in those "compdef _gnu_generic" lines, and removes any that are not present on the system: Don't bother removing the compdef lines, just remove their results. That way you won't have to add things back again if you install one of those missing programs. completed=( ${(k)_comps:#([^[:alnum:]]*)} ) installed=( ${(k)builtins} ${(k)functions} ${(k)commands} ) not_installed=( ${completed:|installed} ) unset '_comps['${^not_installed}']' Just be sure you have done all your zmodloads and autoloads before executing the above, or you'll remove completions for some builtins and functions. Older zsh will not have the ${name:|arrayname} syntax so you might have to resort to not_installed=( ${completed:#${~:-(${(j:|:)${(q)installed}})}} )