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

Re: PATCH: Fix _file_descriptors



--- On Sun, 26/2/12, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:

> I noticed file descriptor completion
> didn't work, with the verbose style set
> because when this is run,
>   fds=( /dev/fd/<0-9>(N:t) )
> the /dev/fd dir is open while the glob is performed, which
> results in
> a spurious entry in the result, which then cannot be
> dereferenced. The
> result is that the list array is not aligned to the fds
> array (and also
> an error message is output), and an fd that doesn't exist is
> completed.

I'm not sure what you mean by "cannot be dereferenced".

In any case, this whole function can be simplified by using the newish :A modifier. Also, I'm fairly certain that it is intentional that this function only completes file descriptors from 0 - 9.

With :A, assigning fds can just be:

fds=( /dev/fd/<0-9>(e,'[[ $REPLY:A != /proc/$$/fd ]]',) )

It's probably best to build up list then with a for loop after checking the style but again :A can be used instead of trying the three old mechanisms.

Another approach would be to use a subshell to open the directory:
  fds=( $(print /proc/$$/fd/<0-9>(N:t)) ) 
But I think there are some platforms that have /dev/fd but not /proc/$$/fd.

Oliver



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