From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21124 invoked by alias); 29 Mar 2017 23:11:07 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40912 Received: (qmail 21845 invoked from network); 29 Mar 2017 23:11:07 -0000 X-Qmail-Scanner-Diagnostics: from king.bitgnome.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(167.88.119.192):SA:0(-0.0/5.0):. Processed in 2.103282 secs); 29 Mar 2017 23:11:07 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: nipsy@bitgnome.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at bitgnome.net designates 167.88.119.192 as permitted sender) Date: Wed, 29 Mar 2017 18:11:01 -0500 From: Mark Nipper To: d.s@daniel.shahaf.name, jmcantrell@gmail.com Cc: zsh-workers@zsh.org Subject: Re: patch for ssh completion Message-ID: <20170329231101.f2fqlxb3b5xgnmro@king.bitgnome.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170302121229.GC6315@fujitsu.shahaf.local2> User-Agent: NeoMutt/20170113 (1.7.2) X-Virus-Scanned: clamav-milter 0.99.2 at king.bitgnome.net X-Virus-Status: Clean On 5 Mar 2017, d.s@daniel.shahaf.name wrote: > Jeremy — have you seen my review (quoted below)? Would you be able to > revise the patch to address these points, at least the first two? > > Process-wise, patches that apply to latest master are preferred, but > _ssh hasn't been changed since 5.3.1 so that's okay. > > Cheers, > > Daniel I might have a cleaner patch for this which doesn't rely on external commands. It also handles the case of the relative path for a user's .ssh directory, although it doesn't attempt to deal with relative include directives in /etc/ssh. It will continue to read included files recursively, either from the user's .ssh directory or via absolute paths. I figured this was the most common use case, so didn't attempt to deal with /etc/ssh since it might not be in a standard location depending on how ssh was compiled. I also wasn't sure if certain shell options should be assumed for these completion functions. I am assuming MULTIOS in this particular example for the included file array to be read correctly. I tried to follow the existing line reading logic already present in _ssh_hosts for weeding out the include directives. --- Completion/Unix/Command/_ssh.orig 2016-11-25 14:24:09.000000000 -0600 +++ Completion/Unix/Command/_ssh 2017-03-29 17:20:56.508325833 -0500 @@ -1,5 +1,7 @@ #compdef ssh slogin=ssh scp ssh-add ssh-agent ssh-keygen sftp ssh-copy-id +local -a config_includes + # TODO: sshd, ssh-keyscan, ssh-keysign _ssh () { @@ -662,6 +664,27 @@ _combination -s '[:@]' my-accounts users-hosts users "$@" } +_ssh_includes () { + local key includes + if [[ -r $@ ]]; then + config_includes+=("$@") + else + return 1 + fi + + while IFS=$'=\t ' read -r key includes; do + if [[ "$key" == (#i)include ]]; then + if [[ ${includes[1]} == / ]]; then + _ssh_includes $includes + else + _ssh_includes $HOME/.ssh/$includes + fi + fi + done < "$@" + + return 0 +} + _ssh_hosts () { local -a config_hosts local config @@ -679,7 +702,7 @@ else config="$HOME/.ssh/config" fi - if [[ -r $config ]]; then + if _ssh_includes $config; then local key hosts host while IFS=$'=\t ' read -r key hosts; do if [[ "$key" == (#i)host ]]; then @@ -690,7 +713,7 @@ esac done fi - done < "$config" + done < ${config_includes} if (( ${#config_hosts} )); then _wanted hosts expl 'remote host name' \ compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" $config_hosts -- Mark Nipper nipsy@bitgnome.net (XMPP) - Spelling mistakes left as an exercise for the reader.