mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-28 12:45:13 +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
|
||||||
end
|
end
|
||||||
for file in $known_hosts
|
for file in $known_hosts
|
||||||
# Ignore hosts that are hashed, commented or have custom ports (like [localhost]:2200)
|
if test -r $file
|
||||||
test -r $file
|
# Ignore hosts that are hashed, commented or @-marked and strip the key.
|
||||||
and string replace -ra '(\S+) .*' '$1' <$file | string match -r '^[^#|[=]+$' | string split ","
|
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
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue