From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10935 invoked by alias); 16 Jun 2015 15:58:55 -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: 35490 Received: (qmail 6544 invoked from network); 16 Jun 2015 15:58:53 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 Message-ID: <558047B6.4090908@gmx.com> Date: Tue, 16 Jun 2015 11:58:46 -0400 From: Eric Cook User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: Re: [PATCH] _file_descriptors: initialize `list' array with local -a References: <1434432668-18303-1-git-send-email-llua@gmx.com> <22433.1434440572@thecus.kiddle.eu> In-Reply-To: <22433.1434440572@thecus.kiddle.eu> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:+RoOjMtj5mM/+Ja5aJBe6PqSwRrEbIYycW4rsO4ij6bDY88xest JUZfLLwOLg6ta2afVDq6+FCBrf7UiNuEotsHRkuhHjc3ZjvgSBhSpdTxDtNHlKGX0lA492G 49tzlunjMyJw6oGdpZooi6Epev++ZmU2OyH/CMHO784IF1mbcaGhQQATuB4NQFuijOxAUU9 6DMbEyQEEgBCQGSb8X5MA== X-UI-Out-Filterresults: notjunk:1;V01:K0:4ws5joYGNpY=:a9jR5HMnevGUalJhY8RvYD y94/yfBuNzfQ7tklSvuyIHfxdTzbaLjiuXHKzikYr5SNGk5/0xpeSZhHZsFT/kfxDGgNw+iOU HW+yfKjbHRz7SNayLO+/kJeGE1hCrit7GKnfUk4YlTcH7yaYDCcFBKJ/4R1kz/0oK8EkSmY20 g7O9JZ9XEAuQBxSAU04h3W6bj1jp7YTaWdr5OvRLUY0v8lZ7lBITs/SA81W5Lgvl5DbEJMaI6 8JD66LvX9VBON9kF16j98HkcloeBFChqlYOiHdNI475+Qdv5N4kX+SE6cRyfg8YuJjzQTqv9y aPPcBLThjIq7vDpefiy5Ln5xZmUbSp/HxCosLM/bFDkJ5ztiK+Af/SWMgUaDqGwLeo0MbCiS+ M8+eW8IDPYA1mt9iurHpsBUdKRMmNgXhNnOteBIR7tByL8V5vZUnXIqQvmz4UtpcYgzk+x7uZ k3ZjRgHKt1tdEOC3xumPVC+8KYkDTxN5831fB4U5hsSLUpqPBGVL8FSjSih83Hq50v4siC5ge YWvbPgOxVTro8CBFfnp76mb5x3PBipj+igvO6EJUdiHYDyCPsSGSsxkemepZIfPs+MPpTGoQQ duT7yR2YiPaxlch4us3AK2oS07YurM6qNQdObzJL2+nmj9elzHphPV0TTy8k8y3hsxh7ZpWL5 M+0ou7faJGSySoKnXwz4BJIw1l157IvlNzPv/8+C1GD+KwvTTtmZEVfo1PF5FH1m7m90= 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