mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-01 21:51:40 +02:00
29918: Completion: Add new _remote_files() helper and use it to reduce code duplication.
This commit is contained in:
parent
3e1146677f
commit
d374f2b180
7 changed files with 87 additions and 127 deletions
|
@ -1,5 +1,8 @@
|
|||
2011-12-09 Simon Ruderich <simon@ruderich.org>
|
||||
|
||||
* 29918: Completion: Add new _remote_files() helper and use it to
|
||||
reduce code duplication.
|
||||
|
||||
* 29917: Completion/Unix/Command/_ssh: Tabs to spaces.
|
||||
|
||||
2011-12-09 Mikael Magnusson <mikachu@gmail.com>
|
||||
|
@ -15703,5 +15706,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.5528 $
|
||||
* $Revision: 1.5529 $
|
||||
*****************************************************
|
||||
|
|
|
@ -5,5 +5,5 @@ _arg_compile _combination _regex_arguments _values
|
|||
_arguments _set_command _retrieve_cache _guard
|
||||
_cache_invalid _describe _sep_parts _pick_variant
|
||||
_call_function _multi_parts _store_cache _regex_words
|
||||
_complete_help_generic
|
||||
_complete_help_generic _remote_files
|
||||
'
|
||||
|
|
77
Completion/Base/Utility/_remote_files
Normal file
77
Completion/Base/Utility/_remote_files
Normal file
|
@ -0,0 +1,77 @@
|
|||
#autoload
|
||||
|
||||
# Complete files on remote systems using SSH (and other programs). Needs
|
||||
# key-based authentication with no passwords or a running ssh-agent to work.
|
||||
#
|
||||
# Usage:
|
||||
# _remote_files [--no-files] [--no-dirs] -- <cmd> [<cmd options>]
|
||||
#
|
||||
# Options:
|
||||
# - --no-files: don't complete remote files
|
||||
# - --no-dirs: don't complete remote directories
|
||||
#
|
||||
# Commands:
|
||||
# - ssh: Additional options for non-interactive use are automatically added
|
||||
# (see below).
|
||||
# - All other commands are used unaltered.
|
||||
#
|
||||
# Examples:
|
||||
# - _remote_files -- ssh
|
||||
# Use ssh to retrieve the remote paths. The "--" is not optional!
|
||||
# - _remote_files --no-files -- ssh -2 -p 42
|
||||
# Use ssh with the option -2 and -p 42 to retrieve the remote paths and
|
||||
# complete only directories.
|
||||
# - _remote_files -- rsh
|
||||
# Use rsh to retrieve the remote paths.
|
||||
|
||||
|
||||
# There should be coloring based on all the different ls -F classifiers.
|
||||
local expl rempat remfiles remdispf remdispd args cmd cmd_args suf ret=1
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:files" remote-access; then
|
||||
|
||||
# Parse options to _remote_files. Stops at the first "--".
|
||||
zparseopts -D -E -a args -no-files -no-dirs
|
||||
shift
|
||||
|
||||
# Command to run on the remote system.
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
# Handle arguments to ssh.
|
||||
if [[ $cmd == ssh ]]; then
|
||||
zparseopts -D -E -a cmd_args p: 1 2 4 6 F:
|
||||
cmd_args="-o BatchMode=yes $cmd_args -a -x"
|
||||
else
|
||||
cmd_args="$@"
|
||||
fi
|
||||
|
||||
if [[ -z $QIPREFIX ]]
|
||||
then rempat="${PREFIX%%[^./][^/]#}\*"
|
||||
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
|
||||
fi
|
||||
|
||||
remfiles=(${(M)${(f)"$(_call_program files $cmd $cmd_args ${IPREFIX%:} ls -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
|
||||
|
||||
compset -P '*/'
|
||||
compset -S '/*' || suf='remote file'
|
||||
|
||||
remdispf=(${remfiles:#*/})
|
||||
remdispd=(${(M)remfiles:#*/})
|
||||
|
||||
_tags files
|
||||
while _tags; do
|
||||
while _next_label files expl ${suf:-remote directory}; do
|
||||
[[ ${args[(I)--no-files]} -eq 0 ]] && \
|
||||
[[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
|
||||
${(q)remdispf%[*=@|]} && ret=0
|
||||
[[ ${args[(I)--no-dirs]} -eq 0 ]] && \
|
||||
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
|
||||
${(q)remdispd%/} && ret=0
|
||||
done
|
||||
(( ret )) || return 0
|
||||
done
|
||||
return ret
|
||||
else
|
||||
_message -e remote-files 'remote file'
|
||||
fi
|
|
@ -5444,39 +5444,6 @@ __git_tree_files () {
|
|||
|
||||
# Repository Argument Types
|
||||
|
||||
# _remote_files
|
||||
_remote_files_git () {
|
||||
# FIXME: these should be imported from _ssh
|
||||
# TODO: this should take -/ to only get directories
|
||||
# There should be coloring based on all the different ls -F classifiers.
|
||||
local expl rempat remfiles remdispf remdispd args suf ret=1
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:files" remote-access; then
|
||||
zparseopts -D -E -a args p: 1 2 4 6 F:
|
||||
if [[ -z $QIPREFIX ]]
|
||||
then rempat="${PREFIX%%[^./][^/]#}\*"
|
||||
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
|
||||
fi
|
||||
remfiles=(${(M)${(f)"$(_call_program files ssh $args -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
|
||||
compset -P '*/'
|
||||
compset -S '/*' || suf='remote file'
|
||||
|
||||
remdispd=(${(M)remfiles:#*/})
|
||||
|
||||
_tags files
|
||||
while _tags; do
|
||||
while _next_label files expl ${suf:-remote directory}; do
|
||||
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
|
||||
${(q)remdispd%/} && ret=0
|
||||
done
|
||||
(( ret )) || return 0
|
||||
done
|
||||
return ret
|
||||
else
|
||||
_message -e remote-files 'remote file'
|
||||
fi
|
||||
}
|
||||
|
||||
(( $+functions[__git_remote_repositories] )) ||
|
||||
__git_remote_repositories () {
|
||||
local service
|
||||
|
@ -5484,7 +5451,7 @@ __git_remote_repositories () {
|
|||
service= _ssh
|
||||
|
||||
if compset -P '*:'; then
|
||||
_remote_files_git
|
||||
_remote_files --no-files -- ssh
|
||||
else
|
||||
_ssh_hosts -S:
|
||||
fi
|
||||
|
|
|
@ -1,32 +1,5 @@
|
|||
#compdef rlogin rsh remsh=rsh rcp
|
||||
|
||||
_rcp_remote_files () {
|
||||
# There should be coloring based on all the different ls -F classifiers.
|
||||
local expl remfiles remdispf remdispd suf ret=1
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:" remote-access; then
|
||||
remfiles=(${(M)${(f)"$(rsh ${IPREFIX%:} ls -d1F ${(Q)PREFIX%%[^./][^/]#}\* 2>/dev/null)"}%%[^/]#(|/)})
|
||||
compset -P '*/'
|
||||
compset -S '/*' || suf='remote file'
|
||||
|
||||
remdispf=(${remfiles:#*/})
|
||||
remdispd=(${(M)remfiles:#*/})
|
||||
|
||||
_tags files
|
||||
while _tags; do
|
||||
while _next_label files expl ${suf:-remote directory}; do
|
||||
[[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
|
||||
${(q)remdispf%[*=@|]} && ret=0
|
||||
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
|
||||
${(q)remdispd%/} && ret=0
|
||||
done
|
||||
(( ret )) || return 0
|
||||
done
|
||||
else
|
||||
_message -e remote-files 'remote file'
|
||||
fi
|
||||
}
|
||||
|
||||
_rlogin () {
|
||||
case "$service" in
|
||||
rlogin)
|
||||
|
@ -65,7 +38,7 @@ _rlogin () {
|
|||
|
||||
if [[ -n "$state" ]]; then
|
||||
if compset -P '*:'; then
|
||||
_rcp_remote_files && ret=0
|
||||
_remote_files -- rsh && ret=0
|
||||
elif compset -P '*@'; then
|
||||
_wanted hosts expl host _rlogin_hosts -S: && ret=0
|
||||
else
|
||||
|
|
|
@ -59,33 +59,7 @@ elif compset -P 1 '*::' || compset -P 1 'rsync://*/'; then
|
|||
elif compset -P 'rsync://'; then
|
||||
_rsync_user_or_host / "$@"
|
||||
elif compset -P 1 '*:'; then
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:files" remote-access; then
|
||||
if [[ -z $QIPREFIX ]]
|
||||
then rempat="${PREFIX%%[^./][^/]#}\*"
|
||||
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
|
||||
fi
|
||||
remfiles=(${(M)${(f)"$(_call_program files ssh -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
|
||||
compset -P '*/'
|
||||
compset -S '/*' || suf='remote file'
|
||||
|
||||
remdispf=(${remfiles:#*/})
|
||||
remdispd=(${(M)remfiles:#*/})
|
||||
|
||||
_tags files
|
||||
while _tags; do
|
||||
while _next_label files expl ${suf:-remote directory}; do
|
||||
[[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
|
||||
${(q)remdispf%[*=@|]} && ret=0
|
||||
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
|
||||
${(q)remdispd%/} && ret=0
|
||||
done
|
||||
(( ret )) || return 0
|
||||
done
|
||||
else
|
||||
_message -e remote-files 'remote file'
|
||||
fi
|
||||
|
||||
_remote_files -- ssh
|
||||
else
|
||||
_rsync_user_or_host : "$@"
|
||||
fi
|
||||
|
|
|
@ -5,40 +5,6 @@
|
|||
# TODO: update ssh-keygen (not based on 5.9)
|
||||
# TODO: sshd, ssh-keyscan, ssh-keysign
|
||||
|
||||
|
||||
_remote_files () {
|
||||
# There should be coloring based on all the different ls -F classifiers.
|
||||
local expl rempat remfiles remdispf remdispd args suf ret=1
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:files" remote-access; then
|
||||
zparseopts -D -E -a args p: 1 2 4 6 F:
|
||||
if [[ -z $QIPREFIX ]]
|
||||
then rempat="${PREFIX%%[^./][^/]#}\*"
|
||||
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
|
||||
fi
|
||||
remfiles=(${(M)${(f)"$(_call_program files ssh -o BatchMode=yes $args -a -x ${IPREFIX%:} ls -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
|
||||
compset -P '*/'
|
||||
compset -S '/*' || suf='remote file'
|
||||
|
||||
remdispf=(${remfiles:#*/})
|
||||
remdispd=(${(M)remfiles:#*/})
|
||||
|
||||
_tags files
|
||||
while _tags; do
|
||||
while _next_label files expl ${suf:-remote directory}; do
|
||||
[[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
|
||||
${(q)remdispf%[*=@|]} && ret=0
|
||||
compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
|
||||
${(q)remdispd%/} && ret=0
|
||||
done
|
||||
(( ret )) || return 0
|
||||
done
|
||||
return ret
|
||||
else
|
||||
_message -e remote-files 'remote file'
|
||||
fi
|
||||
}
|
||||
|
||||
_ssh () {
|
||||
local curcontext="$curcontext" state line expl common tmp cmds suf ret=1
|
||||
typeset -A opt_args
|
||||
|
@ -386,7 +352,7 @@ _ssh () {
|
|||
;;
|
||||
file)
|
||||
if compset -P '*:'; then
|
||||
_remote_files ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
|
||||
_remote_files -- ssh ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
|
||||
elif compset -P '*@'; then
|
||||
suf=( -S '' )
|
||||
compset -S ':*' || suf=( -r: -S: )
|
||||
|
@ -400,7 +366,7 @@ _ssh () {
|
|||
;;
|
||||
rfile)
|
||||
if compset -P '*:'; then
|
||||
_remote_files && ret=0
|
||||
_remote_files -- ssh && ret=0
|
||||
elif compset -P '*@'; then
|
||||
_wanted hosts expl host _ssh_hosts -r: -S: && ret=0
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue