Add _xfunc for loading and calling functions on demand, use it in apt-get, cvsps, rsync, and sshfs.
parent
daa4aba4c8
commit
5baebf81d3
|
@ -1834,6 +1834,23 @@ _completion_loader()
|
|||
} &&
|
||||
complete -D -F _completion_loader
|
||||
|
||||
# Function for loading and calling functions from dynamically loaded
|
||||
# completion files that may not have been sourced yet.
|
||||
# @param $1 completion file to load function from in case it is missing
|
||||
# @param $2... function and its arguments
|
||||
_xfunc()
|
||||
{
|
||||
set -- "$@"
|
||||
local srcfile=$1
|
||||
shift
|
||||
declare -F $1 &>/dev/null || {
|
||||
local compdir=./completions
|
||||
[[ $BASH_SOURCE == */* ]] && compdir="${BASH_SOURCE%/*}/completions"
|
||||
. "$compdir/$srcfile"
|
||||
}
|
||||
"$@"
|
||||
}
|
||||
|
||||
# source compat completion directory definitions
|
||||
if [[ -d $BASH_COMPLETION_COMPAT_DIR && -r $BASH_COMPLETION_COMPAT_DIR && \
|
||||
-x $BASH_COMPLETION_COMPAT_DIR ]]; then
|
||||
|
|
|
@ -20,7 +20,7 @@ _apt_get()
|
|||
COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
|
||||
else
|
||||
# assume RPM based
|
||||
_rpm_installed_packages
|
||||
_xfunc rpm _rpm_installed_packages
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
|
|
|
@ -42,7 +42,7 @@ _cvsps()
|
|||
return 0
|
||||
;;
|
||||
--root)
|
||||
declare -F _cvs_roots &>/dev/null && _cvs_roots
|
||||
_xfunc cvs _cvs_roots
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
@ -50,7 +50,7 @@ _cvsps()
|
|||
if [[ "$cur" == -* ]] ; then
|
||||
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -h )' -- "$cur" ) )
|
||||
else
|
||||
declare -F _cvs_roots &>/dev/null && _cvs_roots
|
||||
_xfunc cvs _cvs_roots
|
||||
fi
|
||||
} &&
|
||||
complete -F _cvsps cvsps
|
||||
|
|
|
@ -66,22 +66,19 @@ _rsync()
|
|||
[[ $COMPREPLY == *= ]] || compopt +o nospace
|
||||
;;
|
||||
*:*)
|
||||
if declare -F _scp_remote_files &>/dev/null; then
|
||||
# find which remote shell is used
|
||||
local i shell=ssh
|
||||
for (( i=1; i < cword; i++ )); do
|
||||
if [[ "${words[i]}" == -@(e|-rsh) ]]; then
|
||||
shell=${words[i+1]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ "$shell" = ssh ] && _scp_remote_files
|
||||
fi
|
||||
# find which remote shell is used
|
||||
local i shell=ssh
|
||||
for (( i=1; i < cword; i++ )); do
|
||||
if [[ "${words[i]}" == -@(e|-rsh) ]]; then
|
||||
shell=${words[i+1]}
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ "$shell" = ssh ] && _xfunc ssh _scp_remote_files
|
||||
;;
|
||||
*)
|
||||
_known_hosts_real -c -a "$cur"
|
||||
declare -F _scp_local_files &>/dev/null && \
|
||||
_scp_local_files || _filedir
|
||||
_xfunc ssh _scp_local_files
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ _sshfs()
|
|||
|
||||
_expand || return 0
|
||||
|
||||
if [[ "$cur" == *:* ]] && declare -F _scp_remote_files &>/dev/null ; then
|
||||
_scp_remote_files -d
|
||||
if [[ "$cur" == *:* ]]; then
|
||||
_xfunc ssh _scp_remote_files -d
|
||||
# unlike scp and rsync, sshfs works with 1 backslash instead of 3
|
||||
COMPREPLY=( "${COMPREPLY[@]//\\\\\\/\\}" )
|
||||
return 0
|
||||
|
@ -18,7 +18,7 @@ _sshfs()
|
|||
|
||||
[[ "$cur" == @(*/|[.~])* ]] || _known_hosts_real -c -a "$cur"
|
||||
|
||||
declare -F _scp_local_files &>/dev/null && _scp_local_files -d
|
||||
_xfunc ssh _scp_local_files -d
|
||||
|
||||
return 0
|
||||
} &&
|
||||
|
|
Loading…
Reference in New Issue