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:
parent
10fc3797e0
commit
e732b79ce2
1 changed files with 7 additions and 4 deletions
|
@ -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 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 }
|
||||
# We don't further process "Include" lines in these secondary files.
|
||||
let hosts = $hosts ++ $second_result.hosts
|
||||
$second_result.hosts
|
||||
})
|
||||
|
||||
let hosts = $first_result.hosts ++ $included_hosts
|
||||
$hosts | each { {value: $in.name, description: $in.addr } }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue