From f6c589c606a8936e33778a717d6200632f8cab21 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 4 Jun 2025 12:30:31 +0900 Subject: [PATCH] [bash,zsh] Skip comments in ~/.ssh/config For the line "Host host1 # this is a comment", the current implementation generates words in an inline comment as hostnames. This patch removes the comment before generating the hostname. --- shell/completion.bash | 1 + shell/completion.zsh | 1 + 2 files changed, 2 insertions(+) diff --git a/shell/completion.bash b/shell/completion.bash index 044a35f6..c3121ecc 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -499,6 +499,7 @@ if ! declare -F __fzf_list_hosts > /dev/null; then # 16-year-old mawk unfortunately. We need to use [ \t] instead. match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) { $0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?" + sub(/#.*/, "") for (i = 1; i <= NF; i++) if ($i !~ /[*?%]/) print $i diff --git a/shell/completion.zsh b/shell/completion.zsh index 0f20812a..b9f9baa0 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -277,6 +277,7 @@ if ! declare -f __fzf_list_hosts > /dev/null; then # 16-year-old mawk unfortunately. We need to use [ \t] instead. match(tolower($0), /^[ \t]*host(name)?[ \t]*[ \t=]/) { $0 = substr($0, RLENGTH + 1) # Remove "Host(name)?=?" + sub(/#.*/, "") for (i = 1; i <= NF; i++) if ($i !~ /[*?%]/) print $i