1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

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 :)
This commit is contained in:
Dan Michael O. Heggø 2025-03-08 23:38:17 +01:00 committed by GitHub
parent 10fc3797e0
commit e732b79ce2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,7 +89,7 @@ def "nu-complete ssh-host" [] {
$r.includes = $r.includes | each {|f| $folder | path join $f }
$r
} | reduce {|it| merge deep $it --strategy=append }
let hosts = $first_result.hosts
let $includes: list<string> = $first_result.includes | each {|f|
if '*' in $f {
glob $f
@ -99,8 +99,11 @@ def "nu-complete ssh-host" [] {
} | flatten
# Process include files
let second_result = $includes | par-each {|p| $p | open --raw | process } | reduce {|it| merge deep $it --strategy=append }
# We don't further process "Include" lines in these secondary files.
let hosts = $hosts ++ $second_result.hosts
let included_hosts = (if ($includes | is-empty) { [] } else {
let second_result = $includes | par-each {|p| $p | open --raw | process } | reduce {|it| merge deep $it --strategy=append }
$second_result.hosts
})
let hosts = $first_result.hosts ++ $included_hosts
$hosts | each { {value: $in.name, description: $in.addr } }
}