Skip to content

Commit

Permalink
Fix ssh-completions when there's no includes (#1065)
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
danmichaelo authored Mar 8, 2025
1 parent 10fc379 commit e732b79
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions custom-completions/ssh/ssh-completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 } }
}

0 comments on commit e732b79

Please sign in to comment.