zsh-users
 help / color / mirror / code / Atom feed
* Empty directories
@ 2014-10-01 10:48 Yuri D'Elia
  2014-10-01 10:50 ` Yuri D'Elia
  0 siblings, 1 reply; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 10:48 UTC (permalink / raw)
  To: zsh-users

$ mkdir empty
$ cd empty<TAB>

will just stop at 'empty/'.

Is there a way to make directories/local-directories accept empty
directories as valid?



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

* Re: Empty directories
  2014-10-01 10:48 Empty directories Yuri D'Elia
@ 2014-10-01 10:50 ` Yuri D'Elia
  2014-10-01 11:00   ` Peter Stephenson
  0 siblings, 1 reply; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 10:50 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 12:48 PM, Yuri D'Elia wrote:
> $ mkdir empty
> $ cd empty<TAB>
> 
> will just stop at 'empty/'.
> 
> Is there a way to make directories/local-directories accept empty
> directories as valid?

I should perhaps state that the obvious reasoning behind this is the
"rmdir" completion.



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

* Re: Empty directories
  2014-10-01 10:50 ` Yuri D'Elia
@ 2014-10-01 11:00   ` Peter Stephenson
  2014-10-01 12:47     ` Yuri D'Elia
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2014-10-01 11:00 UTC (permalink / raw)
  Cc: zsh-users

On Wed, 01 Oct 2014 12:50:54 +0200
Yuri D'Elia <wavexx@thregr.org> wrote:
> On 10/01/2014 12:48 PM, Yuri D'Elia wrote:
> > $ mkdir empty
> > $ cd empty<TAB>
> > 
> > will just stop at 'empty/'.
> > 
> > Is there a way to make directories/local-directories accept empty
> > directories as valid?
> 
> I should perhaps state that the obvious reasoning behind this is the
> "rmdir" completion.

I'm still not understanding.  Like cd completion, "rmdir empty<TAB>"
will also stop at "empty/" (with a / that disappears if you hit return
immediately). But what else could you want?

pws


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

* Re: Empty directories
  2014-10-01 11:00   ` Peter Stephenson
@ 2014-10-01 12:47     ` Yuri D'Elia
  2014-10-01 13:25       ` Peter Stephenson
  2014-10-01 13:35       ` Vincent Lefevre
  0 siblings, 2 replies; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 12:47 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 01:00 PM, Peter Stephenson wrote:
> On Wed, 01 Oct 2014 12:50:54 +0200
> Yuri D'Elia <wavexx@thregr.org> wrote:
>> On 10/01/2014 12:48 PM, Yuri D'Elia wrote:
>>> $ mkdir empty
>>> $ cd empty<TAB>
>>>
>>> will just stop at 'empty/'.
>>>
>>> Is there a way to make directories/local-directories accept empty
>>> directories as valid?
>>
>> I should perhaps state that the obvious reasoning behind this is the
>> "rmdir" completion.
> 
> I'm still not understanding.  Like cd completion, "rmdir empty<TAB>"
> will also stop at "empty/" (with a / that disappears if you hit return
> immediately). But what else could you want?

In normal file completion, prefix<tab> will accept the entire path (if
unique) and insert a space after it.

$ touch pref1_file pref2_file
$ rm pref1<tab>

With an empty directory though the path is not accepted even though
there is nothing more to complete.

It's a minor difference, I know, but I wanted to know why it's there.



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

* Re: Empty directories
  2014-10-01 12:47     ` Yuri D'Elia
@ 2014-10-01 13:25       ` Peter Stephenson
  2014-10-01 14:47         ` Yuri D'Elia
  2014-10-01 13:35       ` Vincent Lefevre
  1 sibling, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2014-10-01 13:25 UTC (permalink / raw)
  To: zsh-users

On Wed, 01 Oct 2014 14:47:48 +0200
Yuri D'Elia <wavexx@thregr.org> wrote:
> In normal file completion, prefix<tab> will accept the entire path (if
> unique) and insert a space after it.
> 
> $ touch pref1_file pref2_file
> $ rm pref1<tab>
> 
> With an empty directory though the path is not accepted even though
> there is nothing more to complete.
> 
> It's a minor difference, I know, but I wanted to know why it's there.

Oh.

When you hit tab the first time, it's just looking for something at the
current path level.  If it's a directory it just adds it.  It has no
idea whether or not it's an empty directory, that's the next level
down.

Then after it's added a / for that directory, you start completing
in that directory and it will now look for whether there's anything
there or not.

To do better, you need a special case in file completion to handle
directory *only* completion.  But it's tricky since in principle there
may be a mixture of directories that are empty and directories that
aren't which would need to be grouped differently.  There are already
way too many cases no one really understands in _path_files, so this
might need an intermediate level for use by cd, rmdir, etc.  This is a
lot of work for something this minor.

pws


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

* Re: Empty directories
  2014-10-01 12:47     ` Yuri D'Elia
  2014-10-01 13:25       ` Peter Stephenson
@ 2014-10-01 13:35       ` Vincent Lefevre
  1 sibling, 0 replies; 13+ messages in thread
From: Vincent Lefevre @ 2014-10-01 13:35 UTC (permalink / raw)
  To: zsh-users

On 2014-10-01 14:47:48 +0200, Yuri D'Elia wrote:
> On 10/01/2014 01:00 PM, Peter Stephenson wrote:
> > On Wed, 01 Oct 2014 12:50:54 +0200
> > Yuri D'Elia <wavexx@thregr.org> wrote:
> >> On 10/01/2014 12:48 PM, Yuri D'Elia wrote:
> >>> $ mkdir empty
> >>> $ cd empty<TAB>
> >>>
> >>> will just stop at 'empty/'.
> >>>
> >>> Is there a way to make directories/local-directories accept empty
> >>> directories as valid?
> >>
> >> I should perhaps state that the obvious reasoning behind this is the
> >> "rmdir" completion.
> > 
> > I'm still not understanding.  Like cd completion, "rmdir empty<TAB>"
> > will also stop at "empty/" (with a / that disappears if you hit return
> > immediately). But what else could you want?
> 
> In normal file completion, prefix<tab> will accept the entire path (if
> unique) and insert a space after it.
> 
> $ touch pref1_file pref2_file
> $ rm pref1<tab>
> 
> With an empty directory though the path is not accepted even though
> there is nothing more to complete.

Why do you think that it is not accepted? And what does "not accepted"
mean?

Perhaps you mean that the ending slash should not be there in case of
"leaf" directories, i.e. when there is nothing else to complete (no
other directories, or not enough permission to enter them)? The main
advantage I could see here is that you immediately get the information
that you have reached a leaf directory. Otherwise this is a bit
useless.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


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

* Re: Empty directories
  2014-10-01 13:25       ` Peter Stephenson
@ 2014-10-01 14:47         ` Yuri D'Elia
  2014-10-01 15:47           ` Bart Schaefer
  2014-10-01 17:01           ` Ray Andrews
  0 siblings, 2 replies; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 14:47 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 03:25 PM, Peter Stephenson wrote:
> aren't which would need to be grouped differently.  There are already
> way too many cases no one really understands in _path_files, so this

This made me smile ;)

I tried to look into _path_files, and there's actually a special rule to
handle empty directories, though I got lost in the expansion loop.



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

* Re: Empty directories
  2014-10-01 14:47         ` Yuri D'Elia
@ 2014-10-01 15:47           ` Bart Schaefer
  2014-10-01 18:14             ` Yuri D'Elia
  2014-10-01 17:01           ` Ray Andrews
  1 sibling, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2014-10-01 15:47 UTC (permalink / raw)
  To: zsh-users

On Oct 1,  4:47pm, Yuri D'Elia wrote:
}
} I tried to look into _path_files, and there's actually a special rule to
} handle empty directories, though I got lost in the expansion loop.

I'm not entirely sure (see "no one really understands") but I think that
rule is for handling partial path completion, that is, given "a/b/c" it
eliminates empty directories matching a* or a*/b* -- because it knows it
has to get as far as a*/b*/c*, so empty dirs along the way are useless.


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

* Re: Empty directories
  2014-10-01 14:47         ` Yuri D'Elia
  2014-10-01 15:47           ` Bart Schaefer
@ 2014-10-01 17:01           ` Ray Andrews
  2014-10-02  4:24             ` Bart Schaefer
  1 sibling, 1 reply; 13+ messages in thread
From: Ray Andrews @ 2014-10-01 17:01 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 07:47 AM, Yuri D'Elia wrote:
> On 10/01/2014 03:25 PM, Peter Stephenson wrote:
>> aren't which would need to be grouped differently.  There are already
>> way too many cases no one really understands in _path_files, so this
> This made me smile ;)
>
> I tried to look into _path_files, and there's actually a special rule to
> handle empty directories, though I got lost in the expansion loop.
Yeah! Laugh now ;-)
I hope we're doing better than bash:

http://blog.erratasec.com/2014/09/the-shockingly-bad-code-of-bash.html


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

* Re: Empty directories
  2014-10-01 15:47           ` Bart Schaefer
@ 2014-10-01 18:14             ` Yuri D'Elia
  2014-10-01 19:58               ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 18:14 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 05:47 PM, Bart Schaefer wrote:
> On Oct 1,  4:47pm, Yuri D'Elia wrote:
> }
> } I tried to look into _path_files, and there's actually a special rule to
> } handle empty directories, though I got lost in the expansion loop.
> 
> I'm not entirely sure (see "no one really understands") but I think that
> rule is for handling partial path completion, that is, given "a/b/c" it
> eliminates empty directories matching a* or a*/b* -- because it knows it
> has to get as far as a*/b*/c*, so empty dirs along the way are useless.

Ok, so maybe we can cut it short and avoid to append a slash on empty
directories directly on the first run?

This would stop path completion immediately.



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

* Re: Empty directories
  2014-10-01 18:14             ` Yuri D'Elia
@ 2014-10-01 19:58               ` Bart Schaefer
  2014-10-01 20:11                 ` Yuri D'Elia
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2014-10-01 19:58 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

On Oct 1, 2014 11:15 AM, "Yuri D'Elia" <wavexx@thregr.org> wrote:
>
> Ok, so maybe we can cut it short and avoid to append a slash on empty
> directories directly on the first run?

The trouble is there is no way to tell that a directory is empty except by
looking "inside" it.  If the directory is network-mounted or contains
thousands of files (or, worse, both) that could be an enormous performance
hit to save you typing one character.

We might be able to do something with the newly-added short-circuit glob
qualifier, but that doesn't help with the network mount issue, and it still
means manufacturing a path tail, testing it, and then throwing it away
again.

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

* Re: Empty directories
  2014-10-01 19:58               ` Bart Schaefer
@ 2014-10-01 20:11                 ` Yuri D'Elia
  0 siblings, 0 replies; 13+ messages in thread
From: Yuri D'Elia @ 2014-10-01 20:11 UTC (permalink / raw)
  To: zsh-users

On 10/01/2014 09:58 PM, Bart Schaefer wrote:
> On Oct 1, 2014 11:15 AM, "Yuri D'Elia" <wavexx@thregr.org> wrote:
>> Ok, so maybe we can cut it short and avoid to append a slash on empty
>> directories directly on the first run?
> 
> The trouble is there is no way to tell that a directory is empty except by
> looking "inside" it.  If the directory is network-mounted or contains
> thousands of files (or, worse, both) that could be an enormous performance
> hit to save you typing one character.
> 
> We might be able to do something with the newly-added short-circuit glob
> qualifier, but that doesn't help with the network mount issue, and it still
> means manufacturing a path tail, testing it, and then throwing it away
> again.

Very good point, yes.

Something "unexpected" on a same vein happens with glob_complete and
repeated slashes. Assuming "compinit" has been called, try with the
following for maximum enjoyment:

$ anything .//<TAB>




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

* Re: Empty directories
  2014-10-01 17:01           ` Ray Andrews
@ 2014-10-02  4:24             ` Bart Schaefer
  0 siblings, 0 replies; 13+ messages in thread
From: Bart Schaefer @ 2014-10-02  4:24 UTC (permalink / raw)
  To: zsh-users

On Oct 1, 10:01am, Ray Andrews wrote:
}
} I hope we're doing better than bash:
} 
} http://blog.erratasec.com/2014/09/the-shockingly-bad-code-of-bash.html

We're not doing a whole lot better on the number of global variables,
I'm afraid, but we've at least modernized all the function signatures.


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

end of thread, other threads:[~2014-10-02  4:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-01 10:48 Empty directories Yuri D'Elia
2014-10-01 10:50 ` Yuri D'Elia
2014-10-01 11:00   ` Peter Stephenson
2014-10-01 12:47     ` Yuri D'Elia
2014-10-01 13:25       ` Peter Stephenson
2014-10-01 14:47         ` Yuri D'Elia
2014-10-01 15:47           ` Bart Schaefer
2014-10-01 18:14             ` Yuri D'Elia
2014-10-01 19:58               ` Bart Schaefer
2014-10-01 20:11                 ` Yuri D'Elia
2014-10-01 17:01           ` Ray Andrews
2014-10-02  4:24             ` Bart Schaefer
2014-10-01 13:35       ` Vincent Lefevre

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