zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _file_descriptors: initialize `list' array with local -a
Date: Thu, 18 Jun 2015 23:33:42 +0200	[thread overview]
Message-ID: <2672.1434663222@thecus.kiddle.eu> (raw)
In-Reply-To: <29394.1434553069@thecus.kiddle.eu>

I wrote:
> The updated function looks good. One slight issue is that description
> separators don't align now that two digit fds are included:

I was going to commit this with that small tweak but noticed that it
also needed to handle sorting manually so that e.g. 10 is placed after
3. Given a few further tweaks and the addition of pfiles use for
Solaris it seems necessary to post a patch.

Oliver

diff --git a/Completion/Zsh/Type/_file_descriptors b/Completion/Zsh/Type/_file_descriptors
index 0b2cd00..52fe4bf 100644
--- a/Completion/Zsh/Type/_file_descriptors
+++ b/Completion/Zsh/Type/_file_descriptors
@@ -1,16 +1,23 @@
 #autoload
 
-local i fds expl link sep
+local i fds expl disp link sep
 local -a list
 
 fds=( /dev/fd/<3->(N:t) )
+fds=( ${(n)fds} )
 
-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
+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]:*} )
+    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+=( "$i $sep ${link[1]}" )
+        list+=( "${(r.$#fds[-1].)i} $sep ${link[1]}" )
       else
         fds[(i)$i]=()
       fi
@@ -18,7 +25,7 @@ if zstyle -T ":completion:${curcontext}:" verbose && [[ -h /proc/$$/fd/$fds[1] ]
   elif (( $+commands[readlink] )); then
     for i in "${fds[@]}"; do
       if link=$(readlink /proc/$$/fd/$i); then
-        list+=( "$i $sep $link" )
+        list+=( "${(r.$#fds[-1].)i} $sep $link" )
       else
         fds[(i)$i]=()
       fi
@@ -26,19 +33,23 @@ if zstyle -T ":completion:${curcontext}:" verbose && [[ -h /proc/$$/fd/$fds[1] ]
   else
     for i in "${fds[@]}"; do
       if link=$(ls -l /proc/$$/fd/$i); then
-        list+=( "$i $sep ${link#* -> }" )
+        list+=( "${(r.$#fds[-1].)i} $sep ${link#* -> }" )
       else
         fds[(i)$i]=()
       fi
     done
   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
+  if (( list[(I)* $sep ?*] )); then
+    list=(
+      "${(r.$#fds[-1].):-0} $sep standard input"
+      "${(r.$#fds[-1].):-1} $sep standard output"
+      "${(r.$#fds[-1].):-2} $sep standard error" $list
+    )
+    disp=( -d list )
   fi
+  fds=( 0 1 2 $fds )
 fi
 
-_wanted file-descriptors expl 'file descriptor' compadd -a "$@" - fds
+_description -V file-descriptors expl 'file descriptor'
+compadd $disp "${@/-J/-V}" "$expl[@]" -a fds


  reply	other threads:[~2015-06-18 21:40 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 [this message]
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=2672.1434663222@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --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).