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,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31415 invoked from network); 21 Nov 2021 04:47:40 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Nov 2021 04:47:40 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1637470060; b=r/E1Rn/dKrXCaIn/hwPd43Qo+rx1AFgJw0uHatAe7XHe58906ETtwYbSMGjatgvLvlK3UOlbaf p3MIzTP1mfOHjEvOp89U1IKnBytN3t0yKooA98je0Iq6aBhX87lcEY8r482L0cwGCSDgRQPOdN fGWCukpOIWQgmVsDH2+RnT4nQ5eMBBpwik1vT0S6uSVg7afUykal7p7OYR+qBtE1/jl8jYR7rw 8ArGGA1nbibP5yhMSOVQsbO9eTe66aze0FA2NZevjxpLwnKU2eNirz3LcXkd5c9Cjz13AgzIkT ONw5m0K8v1VylsYoyhE31GlEVtM1OKsVbkDeWPCz5nTjfw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 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-20210803; t=1637470060; bh=D7qfApaKr8+o9VYbdrEjV/wIcMibYPFfoysALohWz94=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=fvTS0pMvG7mb11yp7leHYFYDc01PuNt910cgAKsCiju+uNlahnQZk1VMXywhi2GbtMtQzimWhT Am4AAPKOo0fpvXKuVtdxDPrHAfuScjX2AUWdN8KO29eIyF+hGv7+bnFY+vkBF22F1COQKEa0cN GGQOnFujckJ7/Oy160QnRZ29VqnnrOmY6fNbdw0FWySjcw5hg4FpKUaY4bZ3EwbICee+dp1wsO uuZLlMcJ+250Sj074K6DxWu2I0ZmHsQHRUgoltqodvYnJL04z8pUxe+PJz7WVyM7AhBdEdEEVN DNMSPDeM8qNONhKRo9WAWr3qy9IWumAwpjBhE9+M6e4g5A==; 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:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=6Gf6dWqzPVEN310sQa5O3esDFY9D3bYENTdjN1Da2P4=; b=McuzZTbepyNwQgqE+581pqg4VI 2LiyxqWpn4f/46k4Fi6JYyORYq/vj7OTF46pkupeh54aa0FaFHiTYrhU/hPStwbwkalmm1ikbavzu 3PPoxfZrVKAIC8vKPGU9TQnDlMyELsRDzfoAJWXQwa6bGzaVmc+FO6NHvY1AmVx0jNidjNumJB9eJ WpNK4/IOBxnbPv33bwjLRPNrep69lBgng4ChQo2Jt+fmkjGjCEdPJ1mwDHAO4QEs2/WiXOPk13Z06 jTN1pNPatM55LiZzyFz+ZwR0eWSJFLtHe80fxNCsMTshVc1LQ+DW4jC/91A/iiALLxE+b8jJM5SNr nrOV3fkw==; Received: from authenticated user by zero.zsh.org with local id 1moelP-0004sQ-5W; Sun, 21 Nov 2021 04:47:39 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f47.google.com ([209.85.221.47]:42971) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1moekf-0004CG-RX; Sun, 21 Nov 2021 04:46:54 +0000 Received: by mail-wr1-f47.google.com with SMTP id c4so25915360wrd.9 for ; Sat, 20 Nov 2021 20:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=6Gf6dWqzPVEN310sQa5O3esDFY9D3bYENTdjN1Da2P4=; b=SzHhikEsDVAsN8mK/oed6CnDbgOEQYt6YrVRzHh81lZW/G/lFiZ92klZE9F+MPTLyt MsU/C3AQA71r944S2OSxVmFA6WbQTTk2a3k3BJGsoGOTMF0BjOQhwC63gM0ZaiwyL0AA sXLccOPdL4hDVFXlOLtDEXAOt1VuXCckKwYK6FCLtAKTPi/iy2Up5C5RlGFb4BIfv+EL toqh3m14MNn5ZycdAKT0Ui67rHKdev5r6Clo+342mXaZIdkIFCRq55+4rGa0ifi3lEoC jpCTwMbZ3ozGJ8kQgXX4MPfb2r/E8QaSJAo78zYo1ar3VCE59ioxLXd58G4CDjOxIjO/ 2Fxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=6Gf6dWqzPVEN310sQa5O3esDFY9D3bYENTdjN1Da2P4=; b=qhpSZnIvMGvoIkrm1fZMJZ2DpJsUsMPfeMllC8NR3jtEj74fu4zUwXjoSHNeadk6vk Ai9kx2zO4M9xMqyQWm3KpExbzFY6lUy61WyiFW1qxfc61L656988quNmAXoXRh6DnQLO ELHypBDRzQlJNflD20gzlVw0g4v4Z2TzEVO2agpDyUaYoDzF7NvkqgtdxYFKPmkEiufH zdmvNpkdNsUilrvxsenvfinuPvuMneSE7lWYul75H6SJ0XLQRHKLMiBm3pnh0fNDzzTG o0KcHLyzcbrGBBeGMCI1l1bv9YU4GgnoBWqsRNpyicnPUG7bp7NVO8fxol7mj5RWbayl jkyg== X-Gm-Message-State: AOAM530TSVklJqr5Ba+dI3R/bPvPcFwpjd3hZ3aE4+WAyN9bwIWbg0U0 XUBOKGUw4+qkhxUc68qtm3Mql/BuVfAOWhGOaX90vJtBzxifyQ== X-Google-Smtp-Source: ABdhPJy9ppdu5OY3KQVV2DgWIqGnoN2igig6rhmpdX3GkcJjUVFLfcJpiEPfr/peRAAqumOGXAmv4fUyOMbbxBTWgFA= X-Received: by 2002:a05:6000:18a7:: with SMTP id b7mr24169995wri.308.1637470013109; Sat, 20 Nov 2021 20:46:53 -0800 (PST) MIME-Version: 1.0 From: Zach Riggle Date: Sat, 20 Nov 2021 22:46:42 -0600 Message-ID: Subject: Setting GLOB_DOTS for a single command To: Zsh Users Content-Type: multipart/alternative; boundary="000000000000763a6105d1453222" X-Seq: 27354 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: --000000000000763a6105d1453222 Content-Type: text/plain; charset="UTF-8" Hello all! I recently learned about GLOB_DOTS, which is pretty useful in some scenarios, e.g. echo *(md-1) To show all files modified within the last day. However, in some cases I want to see hidden files (e.g. ./.foo) as well. The globdots option is excellent for this! Is there an easy way to set this for a single expression? I know I can use a function / anonymous function combined with LOCAL_OPTIONS to get this, but I wondered if there's something more clever. show() { setopt | grep glob } echo ----- Before ----- show (){ setopt globdots echo ----- Inside ----- show setopt localoptions } echo ----- After ----- show I expect that there's something I can do for scripts that I fully control, to declare some function ('globdots') which is invoked with noglob, and can then internally set the flag, and then trigger expansion of each argument in "$@". globdots() { setopt globdots local arguments=( $@ ) # TODO: Force filename expansion on each item in ${@} or ${arguments[@]} "${arguments[@]}" setopt localoptions } touch .hidden_file # Does NOT show .hidden_file ls -1d *(md-1) # DOES show .hidden_file noglob globdots ls -1d *(md-1) However, I'm not sure what portion of Section 14 (Expansion) to read to figure out how that works. It initially looked like the (e) flag (per 14.3.2.22) would do this, but it doesn't appear to. I can just invoke "eval" on something that I KNOW will be a glob expression to get it to expand, but blindly calling eval will execute things that are NOT glob expressions, and I only want filename expansion. What I have found that DOES work (but overkill and a hack) is just to shell out to zsh again, while passing in all options that are currently set -- plus globdots. () { set -x yo() { local myopts=( $(setopt) globdots ) local myargs=() local arg for arg in "$@"; do myargs+=( "$(zsh -c "setopt $o &>/dev/null; command echo $arg" )" ) done "${myargs[@]}" } touch .hidden_file noglob yo echo *hidden*(mm-1) } This of course is wasteful, and I expect there's a better solution. Then there's also the issue of causing filename expansion to occur when unintended -- for example, if '*' is indeed just a string argument, and should not be subject to expansion. I think this corner case I can ignore, as any user will explicitly be asking for glob expansion. *Finally, I wanted to say that I genuinely appreciate the help and answers I've gotten from this community. You're all very welcoming, experienced, and get down to the point / answers quickly. If there's any way that I can help support Zsh development or the community around it, please let me know.* *Zach Riggle* --000000000000763a6105d1453222 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello all!

I recently learned abou= t GLOB_DOTS, which is pretty useful in some scenarios, e.g.

<= /div>
<= div>echo *(md-1)

To show all files modifie= d within the last day.=C2=A0 However, in some cases I want to see hidden fi= les (e.g. ./.foo) as well.=C2=A0 The globdots=C2=A0option is excellent for = this!

Is there an easy way to set this for a singl= e expression?

I know I can use a function / anonym= ous function combined with=C2=A0LOCAL_OPTIONS to get this, but I wondered i= f there's something more clever.

=C2=A0 =C2=A0= show() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 setopt | grep glob
=C2=A0 =C2= =A0 }

=C2=A0 =C2=A0 echo ----- Before -----
=C2=A0 =C2=A0 show
=C2=A0 =C2=A0 (){
=C2=A0 =C2=A0 =C2=A0 =C2=A0 setopt globdots
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo ----- Inside -----
=C2=A0 =C2=A0 =C2=A0= =C2=A0 show
=C2=A0 =C2=A0 =C2=A0 =C2=A0 setopt localoptions
=C2=A0 = =C2=A0 }

=C2=A0 =C2=A0 echo ----- After -----
=C2=A0 =C2=A0 show<= br>

I expect that there's something I can do f= or scripts that I fully control, to declare some function ('globdots= 9;) which is invoked with=C2=A0noglob, and can then internally set the flag= , and then trigger expansion of each argument in "$@".=C2=A0=C2= =A0

=C2=A0 =C2=A0 globdots() {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 setopt globdots
=C2=A0 =C2=A0 =C2=A0 =C2=A0 local argu= ments=3D( $@ ) # TODO: Force filename expansion on each item in ${@} or ${a= rguments[@]}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 "${arguments[@]}"
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 setopt localoptions
=C2=A0 =C2=A0 }

= =C2=A0 =C2=A0 touch .hidden_file

=C2=A0 =C2=A0 # Does NOT show .hidd= en_file
=C2=A0 =C2=A0 ls -1d *(md-1)

=C2=A0 =C2=A0 # DOES show .h= idden_file
=C2=A0 =C2=A0 noglob globdots ls -1d *(md-1)
=

However, I'm not sure what portio= n of Section 14 (Expansion) to read to figure out how that works.=C2=A0 It = initially looked like the (e) flag (per 14.3.2.22) would do this, but it do= esn't appear to.=C2=A0=C2=A0

I can just invoke= "eval" on something that I KNOW will be a glob expression to get= it to expand, but blindly calling eval will execute things that are NOT gl= ob expressions, and I only want filename expansion.

What I have found that DOES work (but overkill and a hack) is just to she= ll out to zsh again, while passing in all options that are currently set --= plus globdots.

=C2=A0 =C2=A0 () {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 set -x
=C2=A0 =C2=A0 =C2=A0 =C2=A0 yo() {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local myopts=3D( $(setopt) globdots )=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local myargs=3D()
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local arg
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 for arg in "$@"; do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 myargs+=3D( "$(zsh -c "setopt $o &= ;>/dev/null; command echo $arg" )" )
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 done
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &quo= t;${myargs[@]}"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 touch .hidden_file
=C2=A0 =C2=A0 =C2=A0 =C2=A0 noglob yo echo= *hidden*(mm-1)
=C2=A0 =C2=A0 }

This of course is wasteful, and I expec= t there's a better solution.

Then there's also the issue of causing filename expansion to = occur when unintended -- for example, if '*' is indeed just a strin= g argument, and should not be subject to expansion.=C2=A0 I think this corn= er case I can ignore, as any user will explicitly be asking for glob expans= ion.

Finally, I wanted to say that I genuinely appreciate t= he help and answers I've gotten from this community.=C2=A0 You're a= ll very welcoming, experienced, and get down to the point / answers quickly= .=C2=A0 If there's any way that I can help support Zsh development or t= he community around it, please let me know.

Zach Riggle
<= br>
--000000000000763a6105d1453222--