From: Oliver Kiddle <opk@zsh.org>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: handle comments when parsing ssh config for completion
Date: Sat, 23 Mar 2024 00:03:22 +0100 [thread overview]
Message-ID: <80211-1711148602.054529@fkea.PPsy.Y_Mq> (raw)
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
reply other threads:[~2024-03-22 23:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=80211-1711148602.054529@fkea.PPsy.Y_Mq \
--to=opk@zsh.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).