From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5539 invoked by alias); 26 Feb 2012 18:37:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30271 Received: (qmail 9382 invoked from network); 26 Feb 2012 18:37:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.215.43 as permitted sender) Received-SPF: pass (google.com: domain of mikachu@gmail.com designates 10.152.147.202 as permitted sender) client-ip=10.152.147.202; Authentication-Results: mr.google.com; spf=pass (google.com: domain of mikachu@gmail.com designates 10.152.147.202 as permitted sender) smtp.mail=mikachu@gmail.com; dkim=pass header.i=mikachu@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer; bh=eZmaGjPkiqq0jwpmmLVzHsRI+S8HdVGd+5wyIctFKfk=; b=pLuDizsdjgPNCj5sM7zkiIpeBtiDFJyup6evFSLcc/Cfld9gkCYSvHywimtr+JnSYl PQLftBkJvEro2kK7Y/2tYu+sUghjH//K7G0vltZyONetc6KhSZ2gSKjx0oZCY5ksAO9s YkF32AQRDu9D2TT/vx1nNqD59oOIimJy0XNmM= From: Mikael Magnusson To: zsh-workers@zsh.org Subject: PATCH: Fix _file_descriptors Date: Sun, 26 Feb 2012 19:37:13 +0100 Message-Id: <1330281433-23949-1-git-send-email-mikachu@gmail.com> X-Mailer: git-send-email 1.7.5.4 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. If the verbose style is not set, the spurious fd is not filtered. --- Completion/Zsh/Type/_file_descriptors | 34 ++++++++++++++++++-------------- 1 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Completion/Zsh/Type/_file_descriptors b/Completion/Zsh/Type/_file_descriptors index 3e251b7..38e2bf5 100644 --- a/Completion/Zsh/Type/_file_descriptors +++ b/Completion/Zsh/Type/_file_descriptors @@ -1,31 +1,35 @@ #autoload -local i fds expl list link sep +local i expl link sep cmd +local -a fds list -fds=( /dev/fd/<0-9>(N:t) ) - -if zstyle -T ":completion:${curcontext}:" verbose && [[ -h /proc/$$/fd/$fds[1] ]]; then +if zstyle -T ":completion:${curcontext}:" verbose && [ -h /proc/$$/fd/<->([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]}" ) - done + cmd='zstat +link -A link $REPLY; link=$link[1]' elif (( $+commands[readlink] )); then - for i in "${fds[@]}"; do - list+=( "$i $sep $(readlink /proc/$$/fd/$i)" ) - done + cmd='link=$(readlink $REPLY)' else - for i in "${fds[@]}"; do - list+=( "$i $sep $(ls -l /proc/$$/fd/$i|sed 's/.*-> //' )" ) - done + cmd='link=$(ls -l $REPLY|sed "s/.*-> //" )' fi - if (( $list[(I)* $sep ?*] )); then + # Filter out the fd for the dir opened during the glob (/proc/$$/fd) + : /proc/$$/fd/<->(e,$cmd' + if [[ $link == /proc/$$/fd ]]; then + false + else + fds+=( $REPLY:t ) + list+=( "$REPLY:t $sep $link" ) + fi + ',) + + if (( $list[(I)<-> $sep ?*] )); then _wanted file-descriptors expl 'file descriptor' compadd "$@" -d list -a - fds return fi +else + fds=( /dev/fd/<->(N:t) ) fi _wanted file-descriptors expl 'file descriptor' compadd -a "$@" - fds -- 1.7.5.4