------------------------------------------------------------
revno: 1199
committer: David Paleino <[EMAIL PROTECTED]>
branch nick: current
timestamp: Sat 2008-11-01 12:25:38 +0100
message:
  Added support for `-F configfile' to _known_hosts(), ssh, scp and 
  sftp, thanks to Freddy Vulto (Closes: #504141)
modified:
  bash_completion
  contrib/ssh
  debian/changelog
=== modified file 'bash_completion'
--- a/bash_completion   2008-11-01 08:49:57 +0000
+++ b/bash_completion   2008-11-01 11:25:38 +0000
@@ -2519,27 +2519,43 @@
 # This function performs host completion based on ssh's known_hosts files,
 # defaulting to standard host completion if they don't exist.
 #
+# Arguments:  -a             Use aliases
+#             -c             Use `:' suffix
+#             -F configfile  Use `configfile' for configuration settings
 _known_hosts()
 {
-       local cur curd ocur user suffix aliases global_kh user_kh hosts i host
-       local -a kh khd config
+       local configfile
+       local cur curd ocur user suffix aliases global_kh user_kh hosts i host
+       local -a kh khd config
 
        COMPREPLY=()
        cur=`_get_cword`
        ocur=$cur
 
-       [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes'
-       [ "$1" = -c ] || [ "$2" = -c ] && suffix=':'
+       local OPTIND=1
+       while getopts "acF:" flag "$@"; do
+               case $flag in
+                       a) aliases='yes' ;;
+                       c) suffix=':' ;;
+                       F) configfile="$OPTARG" ;;
+               esac
+       done
+    
        [[ $cur == [EMAIL PROTECTED] ]] && [EMAIL PROTECTED]@ && [EMAIL 
PROTECTED]
        kh=()
 
        # ssh config files
-       [ -r /etc/ssh/ssh_config ] &&
-         config=( "[EMAIL PROTECTED]" "/etc/ssh/ssh_config" )
-       [ -r "${HOME}/.ssh/config" ] &&
-         config=( "[EMAIL PROTECTED]" "${HOME}/.ssh/config" )
-       [ -r "${HOME}/.ssh2/config" ] &&
-         config=( "[EMAIL PROTECTED]" "${HOME}/.ssh2/config" )
+       if [ -n "$configfile" ]; then
+               [ -r "$configfile" ] &&
+                 config=( "[EMAIL PROTECTED]" "$configfile" )
+       else
+               [ -r /etc/ssh/ssh_config ] &&
+                 config=( "[EMAIL PROTECTED]" "/etc/ssh/ssh_config" )
+               [ -r "${HOME}/.ssh/config" ] &&
+                 config=( "[EMAIL PROTECTED]" "${HOME}/.ssh/config" )
+               [ -r "${HOME}/.ssh2/config" ] &&
+                 config=( "[EMAIL PROTECTED]" "${HOME}/.ssh2/config" )
+       fi
 
        if [ [EMAIL PROTECTED] -gt 0 ]; then
            # expand path (if present) to global known hosts file
@@ -2551,29 +2567,33 @@
        # Global known_hosts files
        [ -r "$global_kh" ] &&
                kh=( "[EMAIL PROTECTED]" "$global_kh" )
-       [ -r /etc/ssh/ssh_known_hosts ] &&
-               kh=( "[EMAIL PROTECTED]" /etc/ssh/ssh_known_hosts )
-       [ -r /etc/ssh/ssh_known_hosts2 ] &&
-               kh=( "[EMAIL PROTECTED]" /etc/ssh/ssh_known_hosts2 )
-       [ -r /etc/known_hosts ] &&
-               kh=( "[EMAIL PROTECTED]" /etc/known_hosts )
-       [ -r /etc/known_hosts2 ] &&
-               kh=( "[EMAIL PROTECTED]" /etc/known_hosts2 )
-       [ -d /etc/ssh2/knownhosts ] &&
-               khd=( "[EMAIL PROTECTED]" /etc/ssh2/knownhosts/*pub )
+       if [ -z "$configfile" ]; then
+               [ -r /etc/ssh/ssh_known_hosts ] &&
+                 kh=( "[EMAIL PROTECTED]" /etc/ssh/ssh_known_hosts )
+               [ -r /etc/ssh/ssh_known_hosts2 ] &&
+                 kh=( "[EMAIL PROTECTED]" /etc/ssh/ssh_known_hosts2 )
+               [ -r /etc/known_hosts ] &&
+                 kh=( "[EMAIL PROTECTED]" /etc/known_hosts )
+               [ -r /etc/known_hosts2 ] &&
+                 kh=( "[EMAIL PROTECTED]" /etc/known_hosts2 )
+               [ -d /etc/ssh2/knownhosts ] &&
+                 khd=( "[EMAIL PROTECTED]" /etc/ssh2/knownhosts/*pub )
+       fi
 
        # User known_hosts files
        [ -r "$user_kh" ] &&
                kh=( "[EMAIL PROTECTED]" "$user_kh" )
-       [ -r ~/.ssh/known_hosts ] &&
-               kh=( "[EMAIL PROTECTED]" ~/.ssh/known_hosts )
-       [ -r ~/.ssh/known_hosts2 ] &&
-               kh=( "[EMAIL PROTECTED]" ~/.ssh/known_hosts2 )
-       [ -d ~/.ssh2/hostkeys ] &&
-               khd=( "[EMAIL PROTECTED]" ~/.ssh2/hostkeys/*pub )
+       if [ -z "$configfile" ]; then
+               [ -r ~/.ssh/known_hosts ] &&
+                 kh=( "[EMAIL PROTECTED]" ~/.ssh/known_hosts )
+               [ -r ~/.ssh/known_hosts2 ] &&
+                 kh=( "[EMAIL PROTECTED]" ~/.ssh/known_hosts2 )
+               [ -d ~/.ssh2/hostkeys ] &&
+                 khd=( "[EMAIL PROTECTED]" ~/.ssh2/hostkeys/*pub )
+       fi
 
        # If we have known_hosts files to use
-       if [ [EMAIL PROTECTED] -gt 0 -o [EMAIL PROTECTED] -gt 0 ]; then
+       if [ [EMAIL PROTECTED] -gt 0 -o [EMAIL PROTECTED] -gt 0 -o -n 
"$configfile" ]; then
            # Escape slashes and dots in paths for awk
            cur=${cur//\//\\\/}
            cur=${cur//\./\\\.}
@@ -2629,7 +2649,7 @@
            for (( i=0; i < [EMAIL PROTECTED]; i++ )); do
                COMPREPLY[i]=$user${COMPREPLY[i]}$suffix
            done
-       else
+       elif [ -z "$configfile" ]; then
            # Just do normal hostname completion
            COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
        fi

=== modified file 'contrib/ssh'
--- a/contrib/ssh       2008-10-24 17:19:37 +0000
+++ b/contrib/ssh       2008-11-01 11:25:38 +0000
@@ -4,6 +4,7 @@
 _ssh()
 {
        local cur prev
+       local optconfigfile
        local -a config
 
        COMPREPLY=()
@@ -11,6 +12,9 @@
        prev=${COMP_WORDS[COMP_CWORD-1]}
 
        case "$prev" in
+       -F)
+               _filedir
+               ;;
        -*c)
            COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
                           arcfour cast128-cbc' -- $cur ) )
@@ -22,9 +26,24 @@
            COMPREPLY=( $( compgen -u -- $cur ) )
            ;;
        *)
-           _known_hosts -a
+               # Search COMP_WORDS for '-F configfile' argument
+               set -- "[EMAIL PROTECTED]"
+               while [ $# -gt 0 ]; do
+                       if [ "${1:0:2}" = -F ]; then
+                               if [ ${#1} -gt 2 ]; then
+                                       optconfigfile="$1"
+                               else
+                                       shift
+                                       optconfigfile="-F$1"
+                               fi
+                               break
+                       fi
+                       shift
+               done
+               
+           _known_hosts -a $optconfigfile
 
-           [ $COMP_CWORD -eq 1 ] || \
+           [ $COMP_CWORD -eq 1 -o -n "$optconfigfile" ] || \
                COMPREPLY=( "[EMAIL PROTECTED]" $( compgen -c -- $cur ) )
        esac
 
@@ -37,6 +56,7 @@
 _scp()
 {
        local cur userhost path
+       local optconfigfile
 
        COMPREPLY=()
        cur=`_get_cword ":"`
@@ -63,8 +83,23 @@
                                   -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
                return 0
        fi
+       
+       # Search COMP_WORDS for '-F configfile' argument
+       set -- "[EMAIL PROTECTED]"
+       while [ $# -gt 0 ]; do
+               if [ "${1:0:2}" = -F ]; then
+                       if [ ${#1} -gt 2 ]; then
+                               optconfigfile="$1"
+                       else
+                               shift
+                               optconfigfile="-F$1"
+                       fi
+                       break
+               fi
+               shift
+       done
 
-       [[ "$cur" == */* ]] || _known_hosts -c -a
+       [[ "$cur" == */* ]] || _known_hosts -c -a $optconfigfile
                local IFS=$'\t\n'
                COMPREPLY=( "[EMAIL PROTECTED]" $( command ls -aF1d $cur* \
                            2>/dev/null | sed \

=== modified file 'debian/changelog'
--- a/debian/changelog  2008-10-24 20:12:09 +0000
+++ b/debian/changelog  2008-11-01 11:25:38 +0000
@@ -32,9 +32,11 @@
   * Fixed errors with POSIX enabled (Closes: #502804)
   * Fixed dpkg-source wrong exit() with return() (Closes: #)
   * Added --schedule-only to aptitude's completion (Closes: #502664)
+  * Added support for `-F configfile' to _known_hosts(), ssh, scp and 
+    sftp, thanks to Freddy Vulto (Closes: #504141)
   * debian/links fixed (Closes: #494292)
 
- -- David Paleino <[EMAIL PROTECTED]>  Fri, 24 Oct 2008 22:11:01 +0200
+ -- David Paleino <[EMAIL PROTECTED]>  Sat, 01 Nov 2008 12:24:34 +0100
 
 bash-completion (20080705) unstable; urgency=low
 

_______________________________________________
Bash-completion-commits mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/bash-completion-commits

Reply via email to