diff --git a/custom-completions/ssh/README.md b/custom-completions/ssh/README.md index 21b7fe0..7b388a4 100644 --- a/custom-completions/ssh/README.md +++ b/custom-completions/ssh/README.md @@ -21,6 +21,8 @@ Host my-ip HostName 192.168.50.237 Host mydomain HostName mydomain.example.com +Host no.hostname + ProxyCommand ssh -q -W %h:%p office Host my-domain-2 HostName mydomain-2.example.com Host my_domain_3 @@ -34,6 +36,7 @@ When you press the tab key, it will display: ❯ | ssh my-ip 192.168.50.237 mydomain mydomain.example.com +no.hostname my-domain-2 mydomain-2.example.com my_domain_3 mydomain_3.example.com diff --git a/custom-completions/ssh/ssh-completions.nu b/custom-completions/ssh/ssh-completions.nu index 137edf2..1e85e3f 100644 --- a/custom-completions/ssh/ssh-completions.nu +++ b/custom-completions/ssh/ssh-completions.nu @@ -38,15 +38,20 @@ def "nu-complete ssh-host" [] { $files | each { |file| let lines = $file | open | lines | str trim - let hosts = $lines - | parse --regex '^Host\s+(?.+)' - | get host - let hostnames = $lines - | parse --regex '^HostName\s+(?.+)' - | get hostname - $hosts | zip $hostnames | each { || - {'value': $in.0, 'description': $in.1} + mut result = [] + for $line in $lines { + let data = $line | parse --regex '^Host\s+(?.+)' + if ($data | is-not-empty) { + $result = ($result | append { 'value': ($data.host | first), 'description': "" }) + continue; + } + let data = $line | parse --regex '^HostName\s+(?.+)' + if ($data | is-not-empty) { + let last = $result | last | update 'description' ($data.hostname | first) + $result = ($result | drop | append $last) + } } + $result } | flatten } \ No newline at end of file