From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _file_descriptors: initialize `list' array with local -a
Date: Tue, 16 Jun 2015 11:58:46 -0400 [thread overview]
Message-ID: <558047B6.4090908@gmx.com> (raw)
In-Reply-To: <22433.1434440572@thecus.kiddle.eu>
On 06/16/2015 03:42 AM, Oliver Kiddle wrote:
> Eric Cook wrote:
>> + fi 2>/dev/null
>
> That redirection causes the description of fd 2 to change to /dev/null
> instead of being the tty. I'm not sure in what situation it is needed
> but it might be better to put it directly on the readlink/sed or
> whichever command actually needs it.
zstat was the command in question, but placing the redirection there still
changes the description to /dev/null
Question: is there a reason why the upper limit is fd9?
I ask because i have a _zsocket function which is what made me notice all of this,
I normally use an fd above 10 with zsocket.
I also noticed since zstat isn't tested for success and link[1] might be defined still,
the description from the previous loop is used for fd3. Which is closed by the time
compsys is done running. Is there a reason to try to present it?
With the patch below: fd0,1,2 are hardcoded, the upper limit of fd9 is removed and test for the failure of zstat,
readlink and ls.
diff --git a/Completion/Zsh/Type/_file_descriptors b/Completion/Zsh/Type/_file_descriptors
index 3e251b7..0b2cd00 100644
--- a/Completion/Zsh/Type/_file_descriptors
+++ b/Completion/Zsh/Type/_file_descriptors
@@ -1,28 +1,41 @@
#autoload
-local i fds expl list link sep
+local i fds expl link sep
+local -a list
-fds=( /dev/fd/<0-9>(N:t) )
+fds=( /dev/fd/<3->(N:t) )
if zstyle -T ":completion:${curcontext}:" verbose && [[ -h /proc/$$/fd/$fds[1] ]]; then
zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
-
if zmodload -F zsh/stat b:zstat; then
for i in "${fds[@]}"; do
- zstat +link -A link /proc/$$/fd/$i
- list+=( "$i $sep ${link[1]}" )
+ if zstat +link -A link /proc/$$/fd/$i; then
+ list+=( "$i $sep ${link[1]}" )
+ else
+ fds[(i)$i]=()
+ fi
done
elif (( $+commands[readlink] )); then
for i in "${fds[@]}"; do
- list+=( "$i $sep $(readlink /proc/$$/fd/$i)" )
+ if link=$(readlink /proc/$$/fd/$i); then
+ list+=( "$i $sep $link" )
+ else
+ fds[(i)$i]=()
+ fi
done
else
for i in "${fds[@]}"; do
- list+=( "$i $sep $(ls -l /proc/$$/fd/$i|sed 's/.*-> //' )" )
+ if link=$(ls -l /proc/$$/fd/$i); then
+ list+=( "$i $sep ${link#* -> }" )
+ else
+ fds[(i)$i]=()
+ fi
done
- fi
+ fi 2>/dev/null
if (( $list[(I)* $sep ?*] )); then
+ list=( "0 $sep standard input" "1 $sep standard output" "2 $sep standard error" $list )
+ fds=( 0 1 2 $fds )
_wanted file-descriptors expl 'file descriptor' compadd "$@" -d list -a - fds
return
fi
next prev parent reply other threads:[~2015-06-16 15:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-16 5:31 Eric Cook
2015-06-16 7:42 ` Oliver Kiddle
2015-06-16 15:58 ` Eric Cook [this message]
2015-06-17 14:57 ` Oliver Kiddle
2015-06-18 21:33 ` Oliver Kiddle
2015-06-19 13:01 ` Danek Duvall
2015-06-23 1:19 ` Oliver Kiddle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=558047B6.4090908@gmx.com \
--to=llua@gmx.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).