Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Any way to allow clobbering empty files when noclobber is set?



Bart Schaefer wrote on Thu, 04 Jun 2020 02:43 +00:00:
> On Wed, Jun 3, 2020 at 6:49 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > I certainly have several cases in my $HISTFILE where I repeated
> > a command with «>» changed to «>!»,¹ in the pattern Martin described.
> 
> Are you sure you haven't set the HIST_ALLOW_CLOBBER option?
> 

I am.  I really do have consecutive pairs of lines where the second line
is equal to the first one with s/>/>!/.

> > ... thinking out loud, how about an
> > option that does the following:
> >
> >     Given «foo > bar», if «foo» was run and exited non-zero and
> >     NO_CLOBBER in effect [which implies that «bar» didn't exist before
> >     foo was run], check whether «bar» is zero-size and, if so, unlink it.

[ Let's call this UNLINK_EMPTY_AFTER_FAILURE for the sake of discussion. ]

> 
> How does that user experience differ from HIST_ALLOW_CLOBBER?  In
> either of those cases, you have to retrieve the command from history
> and execute it again ...

Well, for one, because that proposal only takes effect when foo exited
non-zero, created bar, and bar is zero-sized?  HIST_ALLOW_CLOBBER
applies even when some of these conditions don't hold.

> and silently unlinking a file is not very friendly.  The /etc/nologin
> example in your next message comes to mind.

Doesn't this argument also apply to anyone who might set CLOBBER_EMPTY
and then lose the timestamps on empty files, as in your next message?
That's why these options are opt-in.

Seriously, though, it's perfectly possible that CLOBBER_EMPTY is the
better solution here.  I was only brainstorming.

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author