Skip to content

Commit e732b79

Browse files
authoredMar 8, 2025
Fix ssh-completions when there's no includes (#1065)
The ssh-completion didn't work when I first tried to source it. Turned out that `reduce` failed when `$includes` was an empty list: ```nushell $includes | par-each {|p| $p | open --raw | process } | reduce {|it| merge deep $it --strategy=append } ``` The change proposed in this PR fixes the problem so the completion also works if there are no includes in the ssh config files. I'm a total nushell beginner though, so I'm not sure if it's the best or the most idiomatic way to solve the problem :)
1 parent 10fc379 commit e732b79

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎custom-completions/ssh/ssh-completions.nu

+7-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def "nu-complete ssh-host" [] {
8989
$r.includes = $r.includes | each {|f| $folder | path join $f }
9090
$r
9191
} | reduce {|it| merge deep $it --strategy=append }
92-
let hosts = $first_result.hosts
92+
9393
let $includes: list<string> = $first_result.includes | each {|f|
9494
if '*' in $f {
9595
glob $f
@@ -99,8 +99,11 @@ def "nu-complete ssh-host" [] {
9999
} | flatten
100100

101101
# Process include files
102-
let second_result = $includes | par-each {|p| $p | open --raw | process } | reduce {|it| merge deep $it --strategy=append }
103-
# We don't further process "Include" lines in these secondary files.
104-
let hosts = $hosts ++ $second_result.hosts
102+
let included_hosts = (if ($includes | is-empty) { [] } else {
103+
let second_result = $includes | par-each {|p| $p | open --raw | process } | reduce {|it| merge deep $it --strategy=append }
104+
$second_result.hosts
105+
})
106+
107+
let hosts = $first_result.hosts ++ $included_hosts
105108
$hosts | each { {value: $in.name, description: $in.addr } }
106109
}

0 commit comments

Comments
 (0)
Please sign in to comment.