mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
__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.
This commit is contained in:
parent
57753c7303
commit
32e65ed301
1 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue