Skip to content

Commit 32fab51

Browse files
feat: handle "\s+Host=" and w/o preceding blank line
1 parent 582b53c commit 32fab51

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

zsh-ssh.zsh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ _ssh-host-list() {
3737

3838
ssh_config=$(_parse_config_file $SSH_CONFIG_FILE)
3939
ssh_config=$(echo $ssh_config | command grep -v -E "^\s*#[^_]")
40+
# Make sure each Host line is preceded by an empty line
41+
ssh_config=$(echo $ssh_config | command sed 's/[[:space:]]*Host\b/\nHost /g')
4042

4143
host_list=$(echo $ssh_config | command awk '
4244
function join(array, start, end, sep, result, i) {
@@ -52,10 +54,12 @@ _ssh-host-list() {
5254
}
5355
5456
function parse_line(line) {
55-
n = split(line, line_array, " ")
57+
# Manualy remove leading spaces for split with regex
58+
line = gensub(/^\s+/, "", "g", line)
59+
n = split(line, line_array, " +|=")
5660
5761
key = line_array[1]
58-
value = join(line_array, 2, n)
62+
value = join(line_array, 2, n, " ")
5963
6064
return key "#-#" value
6165
}

0 commit comments

Comments
 (0)