mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
Speed up __fish_print_hostnames for faster completions
Thanks to @ThomasAH, as per #4378. Tested on many platforms (OS X, FreeBSD, Linux, and Solaris). Works with IPv4 and IPv6 as well as host names and loopback addresses.
This commit is contained in:
parent
6513db35c1
commit
3b3bcc998e
1 changed files with 19 additions and 4 deletions
|
@ -94,10 +94,25 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
|
||||||
set known_hosts $known_hosts (string replace -rfi '.*KnownHostsFile\s*' '' <$file)
|
set known_hosts $known_hosts (string replace -rfi '.*KnownHostsFile\s*' '' <$file)
|
||||||
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 ","
|
awk '$1 !~ /[|#@]/ {
|
||||||
|
n=split($1, entries, ",")
|
||||||
|
for (i=1; i<=n; i++) {
|
||||||
|
# Ignore negated/wildcarded hosts.
|
||||||
|
if (!match(entry=entries[i], "[!*?]")) {
|
||||||
|
# Extract hosts with custom port.
|
||||||
|
if (substr(entry, 1, 1) == "[") {
|
||||||
|
if (pos=match(entry, "]:.*$")) {
|
||||||
|
entry=substr(entry, 2, pos-2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}' $file
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue