From f7c10fc6658c39154ff62e00532f796dc97b8f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Sat, 14 Dec 2024 17:10:10 +0700 Subject: [PATCH] Follow Include to extract more SSH hosts --- custom-completions/ssh/ssh-completions.nu | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/custom-completions/ssh/ssh-completions.nu b/custom-completions/ssh/ssh-completions.nu index 1e85e3f4b..85c1e3437 100644 --- a/custom-completions/ssh/ssh-completions.nu +++ b/custom-completions/ssh/ssh-completions.nu @@ -34,14 +34,21 @@ def "nu-complete ssh-host" [] { let files = [ '/etc/ssh/ssh_config', '~/.ssh/config' - ] | filter { |file| $file | path exists } + ] | filter {|file| $file | path exists } - $files | each { |file| + let included_files = $files | each {|file| + let folder = $file | path expand | path dirname + let rel_subfiles = $file | open | lines | str trim | where { |s| $s | str starts-with 'Include' } | each { |s| $s | parse --regex '^Include\s+(?.+)' | get subfile | str replace -a '"' '' } | flatten + $rel_subfiles | each { |f| $folder | path join $f } + } | flatten | filter { |p| $p | path exists } + + + [ ...$files, ...$included_files ] | each {|file| let lines = $file | open | lines | str trim mut result = [] for $line in $lines { - let data = $line | parse --regex '^Host\s+(?.+)' + let data = $line | parse --regex '^Host\s+(?[-\.\w]+)' if ($data | is-not-empty) { $result = ($result | append { 'value': ($data.host | first), 'description': "" }) continue; @@ -54,4 +61,4 @@ def "nu-complete ssh-host" [] { } $result } | flatten -} \ No newline at end of file +}