From 585cfaef8b9292f67177388f24f1514fcdd44f09 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 3 Jun 2025 21:30:56 +0900 Subject: [PATCH] [bash,zsh] Do not end the hostname analysis on "]" in ~/.ssh/known_hosts An entry of the form `[example.com]:port,192.168.0.1 ...` in ~/.ssh/known_hosts are not properly processed. The current implementation gives up the matching on the first occurrence of `]`, the subsequent 192.168.0.1 would not be extracted. This patch continues the analysis and removes "]" together with "[". This patch also removes the ":port" part from the hostnames in ~/.ssh/known_hosts. One cannot use the form "hostname:port" in the arguments to the ssh command anyway. --- shell/completion.bash | 4 ++-- shell/completion.zsh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index afe19c25..7e46bacf 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -503,9 +503,9 @@ if ! declare -F __fzf_list_hosts > /dev/null; then ) \ <( __fzf_exec_awk -F ',' ' - match($0, /^[[a-zA-Z0-9.,:-]+/) { + match($0, /^[][a-zA-Z0-9.,:-]+/) { $0 = substr($0, 1, RLENGTH) - gsub(/\[/, "") + gsub(/[][]|:[^,]*/, "") for (i = 1; i <= NF; i++) print $i } diff --git a/shell/completion.zsh b/shell/completion.zsh index b17271c5..3663a610 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -281,9 +281,9 @@ if ! declare -f __fzf_list_hosts > /dev/null; then ) \ <( __fzf_exec_awk -F ',' ' - match($0, /^[[a-zA-Z0-9.,:-]+/) { + match($0, /^[][a-zA-Z0-9.,:-]+/) { $0 = substr($0, 1, RLENGTH) - gsub(/\[/, "") + gsub(/[][]|:[^,]*/, "") for (i = 1; i <= NF; i++) print $i }