zsh-users
 help / color / mirror / code / Atom feed
* Safety guards for typos
@ 2022-01-24  0:17 Phil Pennock
  2022-01-24  1:46 ` Mikael Magnusson
  2022-01-24  5:57 ` Daniel Shahaf
  0 siblings, 2 replies; 6+ messages in thread
From: Phil Pennock @ 2022-01-24  0:17 UTC (permalink / raw)
  To: zsh-users

So I just had a rather bad time when I didn't type a dot.

Instead of:

    mv *(.) old-2022-01-23/

I typed:

    mv *() old-2021-01-24/

This created a function `mv` and a function for each entry in the
current directory.  I should not have had a directory named `cd`, that
was a bad call.  My Downloads area is full of cruft.

Is there anything that I can turn on, in parsing, so that *() is
interpreted as a syntax error instead of doing the globbing first and
then defining many functions?

-Phil


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

* Re: Safety guards for typos
  2022-01-24  0:17 Safety guards for typos Phil Pennock
@ 2022-01-24  1:46 ` Mikael Magnusson
  2022-01-24  2:01   ` Phil Pennock
  2022-01-24  2:11   ` Phil Pennock
  2022-01-24  5:57 ` Daniel Shahaf
  1 sibling, 2 replies; 6+ messages in thread
From: Mikael Magnusson @ 2022-01-24  1:46 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-users

On 1/24/22, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> So I just had a rather bad time when I didn't type a dot.
>
> Instead of:
>
>     mv *(.) old-2022-01-23/
>
> I typed:
>
>     mv *() old-2021-01-24/
>
> This created a function `mv` and a function for each entry in the
> current directory.  I should not have had a directory named `cd`, that
> was a bad call.  My Downloads area is full of cruft.
>
> Is there anything that I can turn on, in parsing, so that *() is
> interpreted as a syntax error instead of doing the globbing first and
> then defining many functions?

setopt NO_MULTI_FUNC_DEF would probably do the trick in this case,
though it will also prevent explicitly saying mv cp ln() { whatever }.

-- 
Mikael Magnusson


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

* Re: Safety guards for typos
  2022-01-24  1:46 ` Mikael Magnusson
@ 2022-01-24  2:01   ` Phil Pennock
  2022-01-24  2:11   ` Phil Pennock
  1 sibling, 0 replies; 6+ messages in thread
From: Phil Pennock @ 2022-01-24  2:01 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

On 2022-01-24 at 02:46 +0100, Mikael Magnusson wrote:
> setopt NO_MULTI_FUNC_DEF would probably do the trick in this case,
> though it will also prevent explicitly saying mv cp ln() { whatever }.

Hrm, I did remember that such an option was available, but was hoping
for something to prevent the glob qualifier from failing through.

I do use multi func definitions, but I think only in one place, so I
could unset it in that file and reset it afterwards.

-Phil


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

* Re: Safety guards for typos
  2022-01-24  1:46 ` Mikael Magnusson
  2022-01-24  2:01   ` Phil Pennock
@ 2022-01-24  2:11   ` Phil Pennock
  2022-01-24  2:51     ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: Phil Pennock @ 2022-01-24  2:11 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

On 2022-01-24 at 02:46 +0100, Mikael Magnusson wrote:
> setopt NO_MULTI_FUNC_DEF would probably do the trick in this case,
> though it will also prevent explicitly saying mv cp ln() { whatever }.

I tried it and the protection doesn't appear to fire.  Is it possible
that the examination of multiple words before the function definition
happens prior to globbing expansion?

% echo $ZSH_VERSION
5.8
% echo ${options[multifuncdef]}
off
% *() { echo wibble }
% whence -vfa zshenv zshrc
zshenv () {
	echo wibble
}
zshrc () {
	echo wibble
}
%

-Phil


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

* Re: Safety guards for typos
  2022-01-24  2:11   ` Phil Pennock
@ 2022-01-24  2:51     ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2022-01-24  2:51 UTC (permalink / raw)
  To: Phil Pennock; +Cc: Mikael Magnusson, Zsh Users

On Sun, Jan 23, 2022 at 6:11 PM Phil Pennock
<zsh-workers+phil.pennock@spodhuis.org> wrote:
>
> I tried it and the protection doesn't appear to fire.  Is it possible
> that the examination of multiple words before the function definition
> happens prior to globbing expansion?

Yes, that's it.  It happens when "()" is tokenized.

> % *() { echo wibble }

How often would you find a glob as the first word in a command line, though?


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

* Re: Safety guards for typos
  2022-01-24  0:17 Safety guards for typos Phil Pennock
  2022-01-24  1:46 ` Mikael Magnusson
@ 2022-01-24  5:57 ` Daniel Shahaf
  1 sibling, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2022-01-24  5:57 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-users

Phil Pennock wrote on Sun, Jan 23, 2022 at 19:17:36 -0500:
> Instead of:
> 
>     mv *(.) old-2022-01-23/
> 
> I typed:
> 
>     mv *() old-2021-01-24/

A syntax highlighting plugin <disclaimer>which I co-maintain</disclaimer>
would highlight the two cases differently:

[[[
% tests/generate.zsh 'mv *(.) foo/' main users-27486a
⋮
BUFFER=$'mv *(.) foo/'

expected_region_highlight=(
  '1 2 command' # mv
  '4 7 default' # *(.)
  '4 4 globbing' # *
  '9 12 default' # foo/
)
% tests/generate.zsh 'mv *() bar/' main users-27486b
⋮
BUFFER=$'mv *() bar/'

expected_region_highlight=(
  '1 2 command' # mv
  '4 4 default' # *
  '4 4 globbing' # *
  '5 6 reserved-word' # ()
  '8 11 unknown-token' # bar/
)
% 
]]]

So, in the second case you'd see the «()» in yellow and the directory
name in red (or, if AUTO_CD is set, green).

https://github.com/zsh-users/zsh-syntax-highlighting/

Cheers,

Daniel


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

end of thread, other threads:[~2022-01-24  5:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24  0:17 Safety guards for typos Phil Pennock
2022-01-24  1:46 ` Mikael Magnusson
2022-01-24  2:01   ` Phil Pennock
2022-01-24  2:11   ` Phil Pennock
2022-01-24  2:51     ` Bart Schaefer
2022-01-24  5:57 ` Daniel Shahaf

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