From cf4c7ebf6c754028957fe0061d0ed247a47ecb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 29 Jun 2015 00:02:12 +0300 Subject: [PATCH] ssh: Query ciphers and macs from ssh before hardcoded fallback --- completions/ssh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/completions/ssh b/completions/ssh index 69d1e3c1..7cd1c862 100644 --- a/completions/ssh +++ b/completions/ssh @@ -6,17 +6,26 @@ _ssh_queries() "cipher cipher-auth mac kex key protocol-version" -- "$cur" ) ) } +_ssh_query() +{ + ${1:-ssh} -Q $2 2>/dev/null +} + _ssh_ciphers() { - COMPREPLY+=( $( compgen -W '3des-cbc aes128-cbc aes192-cbc aes256-cbc + local ciphers="$( _ssh_query $1 cipher )" + [[ $ciphers ]] || ciphers="3des-cbc aes128-cbc aes192-cbc aes256-cbc aes128-ctr aes192-ctr aes256-ctr arcfour128 arcfour256 arcfour - blowfish-cbc cast128-cbc' -- "$cur" ) ) + blowfish-cbc cast128-cbc" + COMPREPLY+=( $( compgen -W "$ciphers" -- "$cur" ) ) } _ssh_macs() { - COMPREPLY+=( $( compgen -W 'hmac-md5 hmac-sha1 umac-64@openssh.com - hmac-ripemd160 hmac-sha1-96 hmac-md5-96' -- "$cur" ) ) + local macs="$( _ssh_query $1 mac )" + [[ $macs ]] || macs="hmac-md5 hmac-sha1 umac-64@openssh.com hmac-ripemd160 + hmac-sha1-96 hmac-md5-96" + COMPREPLY+=( $( compgen -W "$macs" -- "$cur" ) ) } _ssh_options() @@ -45,7 +54,8 @@ _ssh_options() } # Complete a ssh suboption (like ForwardAgent=y) -# Only one parameter: the string to complete including the equal sign. +# Two parameters: the string to complete including the equal sign, and +# the ssh executable to invoke (optional). # Not all suboptions are completed. # Doesn't handle comma-separated lists. _ssh_suboption() @@ -95,10 +105,10 @@ _ssh_suboption() keyboard-interactive password' -- "$cur" ) ) ;; MACs) - _ssh_macs + _ssh_macs "$2" ;; Ciphers) - _ssh_ciphers + _ssh_ciphers "$2" ;; esac return 0 @@ -112,7 +122,7 @@ _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 + _ssh_suboption $cureq "$1" return $? fi return 1 @@ -126,7 +136,7 @@ _ssh() local configfile local -a config - _ssh_suboption_check && return 0 + _ssh_suboption_check "$1" && return 0 case $prev in -F|-i|-S) @@ -134,11 +144,11 @@ _ssh() return 0 ;; -c) - _ssh_ciphers + _ssh_ciphers "$1" return 0 ;; -m) - _ssh_macs + _ssh_macs "$1" return 0 ;; -l)