From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 3C77D21BE7 for ; Sat, 23 Mar 2024 00:04:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:From:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=M1qS8pCrCj3nt7wkSz4hxuFQrZODZdhuE9azvVBRRlQ=; b=nuPlN1M4ZyZ2NcH/vH8V2vOfFY f0u/mBrBiM/F4kS7MWGknzwQUW0UO/cB/78MRrtcoCTMqpmOux+iKFS+P7tc0ODIFBiEcX6EJ51K+ e1UPySC0db/o6QSSaR6kSxvIT3US30w75Utd+idRfXUaaDHAPKkoR9j/p5YZuXhbzjjI9ff577RLf j7wU0WTJTDaeIZBMMDFfGgQ0rETwLgQVafoajq8xWncJAZGPXu6Qhknqr9SKUaGUURVyNlKWnrbJd lcBv3a/522mRL+Jeo/f0Ei4MBzzNiJ1RWnGUQ6lwoi3r/ArRDiBh34oRoWCviiFpmKJC8pXtNvgbp ti8xr9YA==; Received: by zero.zsh.org with local id 1rnnvj-000BOQ-U9; Fri, 22 Mar 2024 23:04:08 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rnnv3-000B2y-49; Fri, 22 Mar 2024 23:03:26 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1rnnv1-00000000Krs-0Pco for zsh-workers@zsh.org; Sat, 23 Mar 2024 00:03:23 +0100 From: Oliver Kiddle To: Zsh workers Subject: PATCH: handle comments when parsing ssh config for completion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <80210.1711148601.1@hydra> Date: Sat, 23 Mar 2024 00:03:22 +0100 Message-ID: <80211-1711148602.054529@fkea.PPsy.Y_Mq> X-Seq: 52798 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Given that ssh config files just use hash characters to introduce comments, using ${(Z.C.)line} instead of ${(z)line) can be used to strip them out and prevent them breaking ssh host completion. This also drops entries containing a %. In a config file, `Hostname` currently accepts the tokens %% and %h and completing entries containing these is not especially helpful. There's also a couple of minor ssh option updates/fixes. Oliver diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh index dc3979a58..5e6e60573 100644 --- a/Completion/Unix/Command/_ssh +++ b/Completion/Unix/Command/_ssh @@ -101,6 +101,7 @@ _ssh () { '--apple-use-keychain[update keychain when adding/removing identities]' ) _arguments -C -s : $args \ + '-C[process certificates only]' \ '-c[identity is subject to confirmation via SSH_ASKPASS]' \ '-D[delete all identities]' \ '-d[remove identity]' \ @@ -214,7 +215,7 @@ _ssh () { "(${${(@)cmds:#-p}} -v ${${(@)cms:#-[qt]}})-N+[provide new passphrase]:new passphrase" \ "(${${(@)cmds:#-c}} -v $cms)-C+[provide new comment]:new comment" \ "(-D -I -h -n -V -A)-f+[$file file]:$file file:_files" \ - "$p1(${${(@)cmds:#-[FE]}} ${${(@)cmn:#-v}} ${${(@)cms:#-E}})-l[show fingerprint of key file]" \ + "(${${(@)cmds:#-[FE]}} ${${(@)cmn:#-v}} ${${(@)cms:#-E}})-l[show fingerprint of key file]" \ "$p1(${${(@)cmds:#-[iep]}} $cms)-m+[specify conversion format]:format [RFC4716]:(PEM PKCS8 RFC4716)" \ "$p1*-O+[specify a key/value option]: : _values 'option' $options" \ "(${${(@)cmds:#-[lGT]}} ${${(@)cmn:#-[bv]}} -f)*-v[verbose mode]" \ diff --git a/Completion/Unix/Type/_ssh_hosts b/Completion/Unix/Type/_ssh_hosts index a4a08ad91..b50e1c16a 100644 --- a/Completion/Unix/Type/_ssh_hosts +++ b/Completion/Unix/Type/_ssh_hosts @@ -24,7 +24,7 @@ if [[ -r $config ]]; then while (( idx <= $#lines )); do IFS=$'=\t ' read -r key line <<<"${lines[idx]}" if [[ "$key" == ((#i)match) ]]; then - match_args=(${(z)line}) + match_args=( ${(Z.C.)line} ) while [[ $#match_args -ge 2 ]]; do if [[ "${match_args[1]}" == (#i)(canonical|final|(|original)host) ]]; then key="Host" @@ -36,13 +36,10 @@ if [[ -r $config ]]; then fi case "$key" in ((#i)include) - lines[idx]=("${(@f)$(cd $HOME/.ssh; cat ${(z)~line})}") 2>/dev/null;; + lines[idx]=( "${(@f)$(cd $HOME/.ssh; cat ${(Z.C.)~line} 2>/dev/null)}" ) ;; ((#i)host(|name)) - for host in ${(z)line}; do - case $host in - (*[*?]*) ;; - (*) config_hosts+=("$host") ;; - esac + for host in ${(Z.C.)line}; do + [[ $host != *[*?%]* ]] && config_hosts+=( $host ) done ;& (*) (( ++idx ));; esac