[Bash-completion-commits] [SCM] bash-completion branch, master, updated. e308b07526eba5667f17ea04e4e57f38ca6edf9e

Ville Skyttä ville.skytta at iki.fi
Thu Dec 24 14:04:42 UTC 2009


The following commit has been merged in the master branch:
commit 92e7b735643ba57e8b904bad6c74e88774abaa88
Author: Leonard Crestez <cdleonard at gmail.com>
Date:   Thu Dec 24 15:45:19 2009 +0200

    Improve ssh -o suboption completion (Alioth: #312122).

diff --git a/CHANGES b/CHANGES
index 8bf375f..fa58644 100644
--- a/CHANGES
+++ b/CHANGES
@@ -58,6 +58,9 @@ bash-completion (2.x)
   [ Jeremie Lasalle Ratelle ]
   * Fix rsync remote path completion (Alioth: #312173).
 
+  [ Leonard Crestez ]
+  * Improve ssh -o suboption completion (Alioth: #312122).
+
  -- David Paleino <d.paleino at gmail.com>  Sun, 11 Oct 2009 11:11:57 +0200
 
 bash-completion (1.1)
diff --git a/contrib/ssh b/contrib/ssh
index 0946272..1016c16 100644
--- a/contrib/ssh
+++ b/contrib/ssh
@@ -3,8 +3,10 @@
 have ssh &&
 {
 
-_ssh_options() {
-    COMPREPLY=( $( compgen -W 'AddressFamily BatchMode BindAddress \
+_ssh_options()
+{
+    type compopt &>/dev/null && compopt -o nospace
+    COMPREPLY=( $( compgen -S = -W 'AddressFamily BatchMode BindAddress \
         ChallengeResponseAuthentication CheckHostIP Cipher Ciphers \
         ClearAllForwardings Compression CompressionLevel ConnectionAttempts \
         ConnectTimeout ControlMaster ControlPath DynamicForward EscapeChar \
@@ -23,6 +25,74 @@ _ssh_options() {
         VisualHostKey XAuthLocation' -- "$cur" ) )
 }
 
+# Complete a ssh suboption (like ForwardAgent=y<tab>)
+# Only one parameter: the string to complete including the equal sign.
+# Not all suboptions are completed.
+# Doesn't handle comma-separated lists.
+_ssh_suboption()
+{
+    # Split into subopt and subval
+    local subopt=${1%%=*} subval=${1#*=}
+
+    case "$subopt" in
+        BatchMode|ChallengeResponseAuthentication|CheckHostIP|\
+        ClearAllForwardings|Compression|ExitOnForwardFailure|ForwardAgent|\
+        ForwardX11|ForwardX11Trusted|GatewayPorts|GSSAPIAuthentication|\
+        GSSAPIKeyExchange|GSSAPIDelegateCredentials|GSSAPITrustDns|\
+        HashKnownHosts|HostbasedAuthentication|IdentitiesOnly|\
+        KbdInteractiveAuthentication|KbdInteractiveDevices|\
+        NoHostAuthenticationForLocalhost|PasswordAuthentication|\
+        PubkeyAuthentication|RhostsRSAAuthentication|RSAAuthentication|\
+        StrictHostKeyChecking|TCPKeepAlive|UsePrivilegedPort|\
+        VerifyHostKeyDNS|VisualHostKey)
+            COMPREPLY=( $( compgen -W 'yes no' -- "$subval") )
+            ;;
+        AddressFamily)
+            COMPREPLY=( $( compgen -W 'any inet inet6' -- "$subval" ) )
+            ;;
+        Cipher)
+            COMPREPLY=( $( compgen -W 'blowfish des 3des' -- "$subval" ) )
+            ;;
+        Protocol)
+            COMPREPLY=( $( compgen -W '1 2 1,2 2,1' -- "$subval" ) )
+            ;;
+        Tunnel)
+            COMPREPLY=( $( compgen -W 'yes no point-to-point ethernet' \
+                    -- "$subval" ) )
+            ;;
+        PreferredAuthentications)
+            COMPREPLY=( $( compgen -W 'gssapi-with-mic host-based \
+                    publickey keyboard-interactive password' \
+                    -- "$subval" ) )
+            ;;
+        MACs)
+            COMPREPLY=( $( compgen -W 'hmac-md5 hmac-sha1 umac-64 at openssh.com \
+                hmac-ripemd160 hmac-sha1-96 hmac-md5-96' -- "subval" ) )
+            ;;
+        Ciphers)
+            COMPREPLY=( $( compgen -W '3des-cbc aes128-cbc aes192-cbc \
+                    aes256-cbc aes128-ctr aes192-ctr aes256-ctr arcfour128 \
+                    arcfour256 arcfour blowfish-cbc cast128-cbc' \
+                    -- "$subval" ) )
+            ;;
+    esac
+    return 0
+}
+
+# Try to complete -o SubOptions=
+#
+# Returns 0 if the completion was handled or non-zero otherwise.
+_ssh_suboption_check()
+{
+    # Get prev and cur words without splitting on =
+    local cureq=`_get_cword :=` preveq=`_get_pword :=`
+    if [[ $cureq == *=* && $preveq == -o ]]; then
+        _ssh_suboption $cureq
+        return $?
+    fi
+    return 1
+}
+
 _ssh()
 {
     local cur prev configfile
@@ -32,6 +102,8 @@ _ssh()
     cur=`_get_cword :`
     prev=${COMP_WORDS[COMP_CWORD-1]}
 
+    _ssh_suboption_check && return 0
+
     case "$prev" in
         -F|-i|-S)
             _filedir
@@ -112,6 +184,8 @@ _sftp()
     cur=`_get_cword`
     prev=${COMP_WORDS[COMP_CWORD-1]}
 
+    _ssh_suboption_check && return 0
+
     case "$prev" in
         -b|-F|-P)
             _filedir

-- 
bash-completion



More information about the Bash-completion-commits mailing list