Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _file_descriptors: initialize `list' array with local -a
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author