Fixed ssh/scp/sftp -F completions
- -F<TAB> (without a space) now also completes. - Fixed error when completion -F with file containing spaces - Call _filedir instead of _filedirs in sftp NOTE: Because the ssh & sftp completions don't have `-o filenames' in effect, _filedir won't escape spaces in filenames. This can be seen in the tests as "expected failures (XFAIL)". See also: http://lists.alioth.debian.org/pipermail/bash-completion-devel/2009-July/001766.html To run the tests: cd test && ./runCompletion ssh.exp scp.exp sftp.exp
This commit is contained in:
parent
740c6239b1
commit
532f0a0e3f
57
contrib/ssh
57
contrib/ssh
@ -29,8 +29,7 @@ _ssh_options() {
|
|||||||
|
|
||||||
_ssh()
|
_ssh()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev configfile
|
||||||
local optconfigfile
|
|
||||||
local -a config
|
local -a config
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
@ -75,26 +74,32 @@ _ssh()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -F* ]]; then
|
||||||
|
cur=${cur#-F}
|
||||||
|
_filedir
|
||||||
|
# Prefix completions with '-F'
|
||||||
|
COMPREPLY=( "${COMPREPLY[@]/#/-F}" )
|
||||||
|
cur=-F$cur # Restore cur
|
||||||
|
elif [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-1 -2 -4 -6 -A -a -C -f -g -K -k -M \
|
COMPREPLY=( $( compgen -W '-1 -2 -4 -6 -A -a -C -f -g -K -k -M \
|
||||||
-N -n -q -s -T -t -V -v -X -v -Y -y -b -b -c -D -e -F \
|
-N -n -q -s -T -t -V -v -X -v -Y -y -b -b -c -D -e -F \
|
||||||
-i -L -l -m -O -o -p -R -S -w' -- $cur ) )
|
-i -L -l -m -O -o -p -R -S -w' -- $cur ) )
|
||||||
else
|
else
|
||||||
# Search COMP_WORDS for '-F configfile' argument
|
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
|
||||||
set -- "${COMP_WORDS[@]}"
|
set -- "${COMP_WORDS[@]}"
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
if [ "${1:0:2}" = -F ]; then
|
if [ "${1:0:2}" = -F ]; then
|
||||||
if [ ${#1} -gt 2 ]; then
|
if [ ${#1} -gt 2 ]; then
|
||||||
optconfigfile="$(dequote "$1")"
|
configfile="$(dequote "${1:2}")"
|
||||||
else
|
else
|
||||||
shift
|
shift
|
||||||
[ "$1" ] && optconfigfile="$(dequote "-F$1")"
|
[ "$1" ] && configfile="$(dequote "$1")"
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
_known_hosts_real -a $optconfigfile "$cur"
|
_known_hosts_real -a -F "$configfile" "$cur"
|
||||||
if [ $COMP_CWORD -ne 1 ]; then
|
if [ $COMP_CWORD -ne 1 ]; then
|
||||||
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
|
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
|
||||||
fi
|
fi
|
||||||
@ -108,8 +113,7 @@ shopt -u hostcomplete && complete -F _ssh ssh slogin autossh
|
|||||||
#
|
#
|
||||||
_sftp()
|
_sftp()
|
||||||
{
|
{
|
||||||
local cur prev
|
local cur prev configfile
|
||||||
local optconfigfile
|
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=`_get_cword`
|
cur=`_get_cword`
|
||||||
@ -117,7 +121,7 @@ _sftp()
|
|||||||
|
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
-@(b|F|P))
|
-@(b|F|P))
|
||||||
_filedirs
|
_filedir
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-o)
|
-o)
|
||||||
@ -126,7 +130,13 @@ _sftp()
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -F* ]]; then
|
||||||
|
cur=${cur#-F}
|
||||||
|
_filedir
|
||||||
|
# Prefix completions with '-F'
|
||||||
|
COMPREPLY=( "${COMPREPLY[@]/#/-F}" )
|
||||||
|
cur=-F$cur # Restore cur
|
||||||
|
elif [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-1 -C -v -B -b -F -o -P -R -S -s' \
|
COMPREPLY=( $( compgen -W '-1 -C -v -B -b -F -o -P -R -S -s' \
|
||||||
-- $cur ) )
|
-- $cur ) )
|
||||||
else
|
else
|
||||||
@ -135,16 +145,16 @@ _sftp()
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
if [ "${1:0:2}" = -F ]; then
|
if [ "${1:0:2}" = -F ]; then
|
||||||
if [ ${#1} -gt 2 ]; then
|
if [ ${#1} -gt 2 ]; then
|
||||||
optconfigfile="$(dequote "$1")"
|
configfile="$(dequote "${1:2}")"
|
||||||
else
|
else
|
||||||
shift
|
shift
|
||||||
[ "$1" ] && optconfigfile="$(dequote "-F$1")"
|
[ "$1" ] && configfile="$(dequote "$1")"
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
_known_hosts_real -a $optconfigfile "$cur"
|
_known_hosts_real -a -F "$configfile" "$cur"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -156,8 +166,7 @@ shopt -u hostcomplete && complete -F _sftp sftp
|
|||||||
#
|
#
|
||||||
_scp()
|
_scp()
|
||||||
{
|
{
|
||||||
local cur userhost path
|
local configfile cur userhost path prefix
|
||||||
local optconfigfile
|
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=`_get_cword ":"`
|
cur=`_get_cword ":"`
|
||||||
@ -185,30 +194,34 @@ _scp()
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Search COMP_WORDS for '-F configfile' argument
|
if [[ "$cur" = -F* ]]; then
|
||||||
|
cur=${cur#-F}
|
||||||
|
prefix=-F
|
||||||
|
else
|
||||||
|
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
|
||||||
set -- "${COMP_WORDS[@]}"
|
set -- "${COMP_WORDS[@]}"
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
if [ "${1:0:2}" = -F ]; then
|
if [ "${1:0:2}" = -F ]; then
|
||||||
if [ ${#1} -gt 2 ]; then
|
if [ ${#1} -gt 2 ]; then
|
||||||
optconfigfile="$(dequote "$1")"
|
configfile="$(dequote "${1:2}")"
|
||||||
else
|
else
|
||||||
shift
|
shift
|
||||||
[ "$1" ] && optconfigfile="$(dequote "-F$1")"
|
[ "$1" ] && configfile="$(dequote "$1")"
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ "$cur" == */* ]] || _known_hosts_real -c -a $optconfigfile "$cur"
|
[[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur"
|
||||||
|
fi
|
||||||
# This approach is used instead of _filedir to get a space appended
|
# This approach is used instead of _filedir to get a space appended
|
||||||
# after local file/dir completions, and $nospace retained for others.
|
# after local file/dir completions, and $nospace retained for others.
|
||||||
local IFS=$'\t\n'
|
local IFS=$'\t\n'
|
||||||
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
|
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
|
||||||
2>/dev/null | sed \
|
2>/dev/null | sed \
|
||||||
-e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\&/g" \
|
-e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\&/g" \
|
||||||
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
|
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' -e "s/^/$prefix/") )
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user