Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: completion for file descriptors



Here is the completion for file descriptors which was discussed during
the day along with a few small changes to _print to use it and to handle
-p only when the is a coprocess. Can anyone see any problems or
alternatives to my fallback method of finding links of using ls -l piped
into sed? The stat module works well but I didn't want to use it if it
wasn't loaded because it isn't there by default. On IRIX, I seem to get
all 10 file descriptors listed regardless and I can't see a way round
it, not that it matters much. If put _file_descriptors in Core because
it will be used by _redirect and because other things like _options is
there - it can always be moved.

Oliver

Index: Completion/Builtins/_print
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_print,v
retrieving revision 1.1
diff -r1.1 _print
3c3
< local state expl line eflag
---
> local state expl line eflag pflag
7a8,11
> # -p flag only relevant if we have a coprocess
> (:>&p) 2>/dev/null &&
>   pflag='(-s -u -z)-p[print arguments to input of coprocess]'
> 
21,22c25
<   '(-s -p -z)-u+[specify file-descriptor to print arguments to]:file-descritor' \
<   '(-s -u -z)-p[print arguments to input of coprocess]' \
---
>   '(-s -p -z)-u+[specify file-descriptor to print arguments to]:file-descriptor:_file_descriptors' \
26c29
<   $eflag '*:default:_default'
---
>   $pflag $eflag '*:default:_default'
Index: Completion/Core/_file_descriptors
===================================================================
RCS file: _file_descriptors
diff -N _file_descriptors
0a1,23
> #autoload
> 
> local i fds expl list link
> 
> for i in {0..9}; [[ -e /dev/fd/$i ]] && fds=( ${fds[@]} $i )
> 
> if zstyle -T ":completion:${curcontext}" verbose && [[ -e /proc/$$/fd ]]; then
>   if zmodload -e zsh/stat; then
>     for i in "${fds[@]}"; do
>       stat +link -A link /proc/$$/fd/$i
>       list=( ${list[@]} "$i -- ${link[1]}" )
>     done
>   elif (( $+commands[readlink] )); then
>     for i in "${fds[@]}"; list=( ${list[@]} "$i -- $(readlink /proc/$$/fd/$i)" )
>   else
>     for i in "${fds[@]}"; do
>       list=( ${list[@]} "$i -- $(ls -l /proc/$$/fd/$i|sed 's/.*-> //' )" )
>     done
>   fi
>   _wanted file-descriptors expl 'file descriptors' compadd "$@" -d list - "$fds[@]"  
> else
>   _wanted file-descriptors expl 'file descriptors' compadd "$@" - "$fds[@]"
> fi



Messages sorted by: Reverse Date, Date, Thread, Author