aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Boris Aranovich <nomaed@users.noreply.github.com>2016-06-15 18:54:40 +0300
committerGravatar Fabian Homborg <FHomborg@gmail.com>2016-06-15 17:54:40 +0200
commitcbe97ac1a16930d561ff3899433ce07a7a5f261a (patch)
treee4f1d35dffe09b0dd53b0bd4a2f0aa91b402d3af
parent3cecc1f475d8f2d34f6e2519a8f7f9168296a494 (diff)
Refine reading ssh_config (#3146)
https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5 1. It is possible to add multiple whitespace characters between the keyword (i.e. Host) and the argument(s). 2. It is allowed to have a single = and whitespace between the keyword and the argument(s). 3. It is possible to add multiple host names under a single Host directive by spacing the names apart. 1. and 3. are actual conventions that we use in our team, and I couldn't get auto-complete working for fish without this modification. Modification explained: a. The space between Host(?:name)? and the \w.* was replaced by (?:\s+|\s*=\s*) to match any sequence of whitespace characters, or optional whitespaces with a single =, per spec. b. Result of first replacement is piped through another string replace to switch duplicate whitespace characters to a single space, and then piped to be split by that space. This allows specifying several aliases or host names in a single Host/Hostname definition, also per spec.
-rw-r--r--share/functions/__fish_print_hostnames.fish7
1 files changed, 4 insertions, 3 deletions
diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish
index 40499d1e..aca754c1 100644
--- a/share/functions/__fish_print_hostnames.fish
+++ b/share/functions/__fish_print_hostnames.fish
@@ -26,9 +26,10 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
if test -r $file
# Print hosts from system wide ssh configuration file
# Note the non-capturing group to avoid printing "name"
- string match -ri '\s*Host(?:name)? \w.*' < $file | string replace -ri '^\s*Host(?:name)?\s*(\S+)' '$1'
- set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' <$file \
- | string replace -ri '.*KnownHostsFile\s*' '')
+ string match -ri '\s*Host(?:name)?(?:\s+|\s*=\s*)\w.*' < $file | string replace -ri '^\s*Host(?:name)?\s*(\S+)' '$1' \
+ | string replace -r '\s+' ' ' | string split ' '
+ set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' < $file \
+ | string replace -ri '.*KnownHostsFile\s*' '')
end
end
for file in $known_hosts