From 32e65ed3010169396cff612efcbdf36883db2477 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 5 Sep 2017 16:31:12 +0200 Subject: [PATCH] __fish_print_hostnames: Improve ssh known_hosts extraction This now includes hosts with custom ports (and other hosts with the same key), and explicitly excludes negated hosts, those with a wildcard and those with an `@`-marker (e.g. `@revoked`) It's also possibly a bit quicker because the ordering is better, especially for files with many comments. --- share/functions/__fish_print_hostnames.fish | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index da840dbb4..c3f392a3b 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -95,9 +95,16 @@ function __fish_print_hostnames -d "Print a list of known hostnames" end end for file in $known_hosts - # Ignore hosts that are hashed, commented or have custom ports (like [localhost]:2200) - test -r $file - and string replace -ra '(\S+) .*' '$1' <$file | string match -r '^[^#|[=]+$' | string split "," + if test -r $file + # Ignore hosts that are hashed, commented or @-marked and strip the key. + string replace -r '[#@| ].*' '' <$file \ + # Split on ",". + # Ignore negated/wildcarded hosts. + | string split "," | string match -rv '[!\*\?]' \ + # Extract hosts with custom port. + | string replace -r '\[([^]]+)\]:.*' '$1' + # string replace -ra '(\S+) .*' '$1' <$file | string match -r '^[^#|[=]+$' | string split "," + end end return 0 end