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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 517 invoked from network); 17 Mar 2022 16:37:46 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 17 Mar 2022 16:37:46 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1647535066; b=AZ4HY38fxFNQf+Gpjg3xDr9SU5siAolqFfnVr9/KIG89sAx1MRRrI2/zK7W1+FNdyhIepHyvgS LvUW6m7M6nQGW0rHXJEfPuuRDEDss3SqNaBWO6pyCKAVUsh9g4hfcKsxaYxRzfm/ac3AYoN2JO 1yrXmhMLlDvRS9SGVdTeVxIIDlB51DVQE1POSv/C9uANgnCbsJsaxa2/uP6/9uhajlO4wei+u+ eftR0Ii5631IizNmlnYrQsBXXBqs64rPs5sCbOjUStxDcaw+ztSTVbJEdjbynPWmEnf4JXm9ZU Kg4+pAsSxYGIjW2w1k3mOxLAeu3kgWGVHkGJemnx5mrXLg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1647535066; bh=eB7YArh7fsu08eXIWiKylIOFNghHwBfCTp356Y5gKtE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature:DKIM-Signature:DKIM-Signature; b=GsmO/Wv+rYuEIx6oQjcaBZyJWUlkH1EZIQjyeQfDLcsVvN6JssQIaJH0GHACi+tCo5UNIosDA0 Neok/sGctik55TaAUkqGSdH91QJuAVRsDKSOa2qu0FWFG0VvJua8lSnxKtEzFOl0CDTa6KqiWs dZEzM7RL8CeLtO0OmA2Cunh8e1EtlPOuB3YITl2sdqkCrQssstlS6j1a4RnvRCD1zigG8rRTY2 C9eM0E3Va8RN9He0aEHTAlb3IrwCnLMoso2dIJLBz5JLiecRJqiHAdMc04GQ3CuJ6qoBFz0SQ9 /IhJmfIYjOLEfXH/92YV6oYD2Dnom89O/6Kc9oeK9xAG9Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=AjlUFECavQs95Yn3dip0oqjufni7XE1gbcvkIBKsGRI=; b=PMgyIn7+XEh7foQ0D2vfN3Jd+/ JAdhNj4M2ICj3CLUEYx0zx4s88X1z7WBqR/qDx9FFgKxT7Xb0zK7Iz8TxqM+a858CM+tSrsNuagqc PfQcaOH1eWon2RzIx/RPMzB3LMcmD6QGQsiPwhLOlyLmso4ZiTT+0sTY9lUqA35WreFgnaVI8TZQF D/LXBeHqMoUdJ3EelRlma69NWEdt+fPjDndZZiMJFgh37XR8k/ufBjsVcdtSMDu5ujk/is/OQdsq7 7FCHlSVSJRaMs5YBmvGlmyIlGRhASmY9FnMkSS72XzaC+l3O3d2+Qf+RuHOJaupZHFElA5tYVQ6gC ZEt7B/3A==; Received: from authenticated user by zero.zsh.org with local id 1nUt8D-000O2d-KF; Thu, 17 Mar 2022 16:37:45 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:36063) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1nUt0x-000Mee-O7; Thu, 17 Mar 2022 16:30:17 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 854D95C03B0; Thu, 17 Mar 2022 12:30:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 17 Mar 2022 12:30:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=AjlUFECavQs95Y n3dip0oqjufni7XE1gbcvkIBKsGRI=; b=gT7daBgWMIhE2z1AcQY3v4K4rt+xW7 4FTcb9pwFAbzupU1uN5/b5qyyzneIqjXQlAG4QIIuRpZqyyIrWCEcHLD1aCEITTX QLuCXXGpdl+3jUt+Q/I7htdFaIU80MjaFpAEGqGbpk2poxyHGRXKiLGTDUsJHbPn 4CycARGEYoo5+GT+3KgzHLuCziUCeVGS31PHj8hxshf9GPjW8g6gZUSlkkB+4xp5 mysnQXisctO/8QzA/pl7+3Kc3I5lLhlMTCjLTRRvi5yEP/3wC4VEmvgiVeJszgPG SYg66h3J0qoUYUB5aJ11S4IThIsD2Z1xX7fLV8rUYuXh1l1kJcR6OMJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=AjlUFECavQs95Yn3d ip0oqjufni7XE1gbcvkIBKsGRI=; b=k7ljHaqmIOZPhylkiGf79Mliy8mBb/X1N I3CXcTBewxXFyxyIM7YSq2YhJ7mdLF8+AMpx4D1n1KR3Y1SBFpOCB5pHtTrjYjwL SVOMzmcO91PZ1A9msExBzV3iMtXVF8J2VFdQyf/OH6nGGSwpkg1roisqHXLyU7LW kYiwUG+dK211A42N0+Ox/W6kcgL8815qzIJR/uIStat7iTSUJ5JTinDBg7GX0rNU 6V/h0gTQksg/sfWIqPwsAuED6ji+j8WKh2P3icOrVJjR0ffBQd1pV2xzqpo9qNz1 NvEv4BsgT57AGDW66S86F18GaKpQo94uJceqBPZdLkMOsrZG/Jrzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefgedgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjfgesthdttddttdervdenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnheptdekveetveeuieevudeuhfffjefhfedthfffuddtgeegvdej hfdtkeffgffghfegnecuffhomhgrihhnpehgvghtqdhnrghtshdrihhonecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghl rdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 17 Mar 2022 12:30:14 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4KKCKw2zsFz278; Thu, 17 Mar 2022 16:30:12 +0000 (UTC) Date: Thu, 17 Mar 2022 16:30:12 +0000 From: Daniel Shahaf To: Phil Pennock Cc: Zsh Users Subject: Re: More-verbose tab-completion idiom? Message-ID: <20220317163012.GT7687@tarpaulin.shahaf.local2> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 27575 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: Phil Pennock wrote on Wed, Mar 16, 2022 at 22:21:44 -0400: > On 2022-03-16 at 18:20 -0700, Bart Schaefer wrote: > > but that assumes you don't have colons or commas or braces in the keys > > or descriptions. > > Alas, one of the fields is almost guaranteed to be a URL, thus > containing a colon, and all of those are fair game in the description > field. > > In case anyone is interested: while nats(1) (open-source, part of the > CNCF "NATS" project) is changing fast enough that we probably don't want > the completion shipping with zsh at this time, here's a copy of the > completion I'm using today: > > https://get-nats.io/zsh.complete.nats Review in unidiff form. Meant as suggestions to pick and choose from. I forgot to annotate a few other function definitions with the same "don't unconditionaly redefine" idiom. Cheers, Daniel [[[ --- https://get-nats.io/zsh.complete.nats +++ https://get-nats.io/zsh.complete.nats @@ -23,7 +23,7 @@ # extra-verbose is documented as for features which will slow completion speed. if zstyle -t ":completion:${curcontext}:" extra-verbose; then - if (( $+commands[jq] )); then + if type jq > /dev/null; then nats_everbose=1 else : # should we report this back as an error somehow? @@ -32,15 +32,16 @@ local -r nats_ctxdir="${XDG_CONFIG_HOME:-$HOME/.config}/nats/context" -nats_contexts=( "$nats_ctxdir"/*(:t:r) ) +nats_contexts=( "$nats_ctxdir"/*(N:t:r) ) # TODO: come up with a cache expiration strategy and integrate this with use-cache # or at least a global variable. +(( ${+functions[_nats_context_names]} )) || _nats_context_names() { if (( nats_everbose )); then described_contexts=() for nctx in "${nats_contexts[@]}"; do - described_contexts+=("${nctx//:/\\:}:$(jq -r .description < "$nats_ctxdir/$nctx.json")") + described_contexts+=("${nctx//:/\\:}:$(_call_program jq "jq -r .description < \"${(q)nats_ctxdir}/${(q)nctx}.json\"")") done _describe nats-contexts described_contexts else @@ -55,7 +56,7 @@ ;; esac -nats_decorate_flags_desc=( +nats_decorate_flags_desc=( # this assumes zsh is-at-least 5.5 [context]='NATS user context' [tlscert]='TLS client auth public certificate' [tlskey]='TLS client auth private key' @@ -86,12 +87,12 @@ # We populate a complete set first, so that even if we don't have more details below, # we can still tab-complete it; it will just be missing some data -nats_commands=( $(${words[1]} --completion-bash ${words[1]}) ) +nats_commands=( $(_call_program completion-bash "${words[1]} --completion-bash ${words[1]}") ) # Most flags can appear anywhere; this is not a git-style "top command flags" # vs "subcommand flags", but instead "one pool of flags which gains extra # entries for some subcommands". -nats_flags=( $(${words[1]} --completion-bash ${words[1]} --) ) +nats_flags=( $(${words[1]} --completion-bash ${words[1]} --) ) # TODO add _call_program _nats_decorate_flags() { #zle -M "decorating ..."; zle -R local flag directive @@ -135,7 +136,7 @@ ;; (after-command) curcontext=${curcontext%:*:*}:nats-$words[1]: - nats_sub=( $("$cmdword" --completion-bash "${words[@]}") ) + nats_sub=( $("$cmdword" --completion-bash "${words[@]}") ) # TODO add _call_program if [[ ${#nats_sub} -eq 0 ]]; then # terminal nats_flags=( $("$cmdword" --completion-bash "${words[@]}" --) ) ]]] > (I know that I'm misusing the per-flag description by listing it twice in > this way for the two different location but I haven't yet come up with > an easier-to-maintain approach) > > -Phil >