From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Danek Duvall <duvall@comfychair.org>, zsh-workers@zsh.org
Subject: Re: [PATCH] _file_descriptors: initialize `list' array with local -a
Date: Tue, 23 Jun 2015 03:19:41 +0200 [thread overview]
Message-ID: <6056.1435022381@thecus.kiddle.eu> (raw)
In-Reply-To: <20150619130143.GC17684@lorien.comfychair.org>
On 19 Jun, Danek Duvall wrote:
> Newer versions of Solaris (11 and up?) have /proc/<pid>/path/<->, which
> have the same effect as the symlinks in /proc/<pid>/fd on Linux.
Thanks. That interface is probably more reliable. It is there in Solaris
10 and also for even older versions that are running in a branded zone.
So this is yet another patch to the function. It should also work for
FreeBSD using procstat.
Oliver
diff --git a/Completion/Zsh/Type/_file_descriptors b/Completion/Zsh/Type/_file_descriptors
index 52fe4bf..3e9f496 100644
--- a/Completion/Zsh/Type/_file_descriptors
+++ b/Completion/Zsh/Type/_file_descriptors
@@ -1,44 +1,48 @@
#autoload
local i fds expl disp link sep
-local -a list
+local -a list proc
fds=( /dev/fd/<3->(N:t) )
fds=( ${(n)fds} )
if zstyle -T ":completion:${curcontext}:file-descriptors" verbose; then
zstyle -s ":completion:${curcontext}:file-descriptors" list-separator sep || sep=--
- if [[ $OSTYPE = solaris* ]]; then
- fds=( ${${(f)"$(pfiles $$|nawk 'NR==1{next} /^ *[0-9]*:/ {printf "\n%s", $1} / *\// {print $1}')"}:#[012]:*} )
+
+ if [[ $OSTYPE = freebsd* ]]; then
+ fds=( ${(f)"$(procstat -f $$|awk -v OFS=: '$3>2 && $3~/[0-9]/ {print $3,$10}')"} )
zformat -a list " $sep " $fds
fds=( ${fds%%:*} )
- elif [[ ! -h /proc/$$/fd/$fds[1] ]]; then
- :
- elif zmodload -F zsh/stat b:zstat; then
- for i in "${fds[@]}"; do
- if zstat +link -A link /proc/$$/fd/$i; then
- list+=( "${(r.$#fds[-1].)i} $sep ${link[1]}" )
- else
- fds[(i)$i]=()
- fi
- done
- elif (( $+commands[readlink] )); then
- for i in "${fds[@]}"; do
- if link=$(readlink /proc/$$/fd/$i); then
- list+=( "${(r.$#fds[-1].)i} $sep $link" )
- else
- fds[(i)$i]=()
- fi
- done
- else
- for i in "${fds[@]}"; do
- if link=$(ls -l /proc/$$/fd/$i); then
- list+=( "${(r.$#fds[-1].)i} $sep ${link#* -> }" )
- else
- fds[(i)$i]=()
- fi
- done
- fi 2>/dev/null
+ elif
+ proc=( /proc/$$/(fd|path)/<->(@N[-1]:h) )
+ [[ -n $proc ]]
+ then
+ if zmodload -F zsh/stat b:zstat; then
+ for i in "${fds[@]}"; do
+ if zstat +link -A link $proc/$i; then
+ list+=( "${(r.$#fds[-1].)i} $sep ${(D)link[1]}" )
+ else
+ fds[(i)$i]=()
+ fi
+ done
+ elif (( $+commands[readlink] )); then
+ for i in "${fds[@]}"; do
+ if link=$(readlink $proc/$i); then
+ list+=( "${(r.$#fds[-1].)i} $sep ${(D)link}" )
+ else
+ fds[(i)$i]=()
+ fi
+ done
+ else
+ for i in "${fds[@]}"; do
+ if link=$(ls -l $proc/$i); then
+ list+=( "${(r.$#fds[-1].)i} $sep ${(D)link#* -> }" )
+ else
+ fds[(i)$i]=()
+ fi
+ done
+ fi 2>/dev/null
+ fi
if (( list[(I)* $sep ?*] )); then
list=(
@@ -48,8 +52,8 @@ if zstyle -T ":completion:${curcontext}:file-descriptors" verbose; then
)
disp=( -d list )
fi
- fds=( 0 1 2 $fds )
fi
+fds=( 0 1 2 $fds )
_description -V file-descriptors expl 'file descriptor'
compadd $disp "${@/-J/-V}" "$expl[@]" -a fds
prev parent reply other threads:[~2015-06-23 1:26 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
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 [this message]
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=6056.1435022381@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=duvall@comfychair.org \
--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).