1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 15:17:47 +00:00

Update remoting.nu (#239)

Running built-in command using `ssh script` fails with a non-obvious error message. This fixes that
This commit is contained in:
Yethal 2022-05-30 23:22:32 +02:00 committed by GitHub
parent abd600d41e
commit 456c0fe5b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -61,11 +61,24 @@ export def "ssh script" [
script: string@"nu-complete scripts" # name of the script script: string@"nu-complete scripts" # name of the script
...args # arguments you wish to pass to the script in key=value format ...args # arguments you wish to pass to the script in key=value format
] { ] {
let host = (hosts|where name == $hostname|get 0) let span = (metadata $script).span
let full-command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r') if $script in ($nu.scope.commands|where is_custom|get command) {
^ssh (get-url $host) ($full-command)|from json
}
let host = (hosts|where name == $hostname|get 0)
let full-command = (build-string (view-source $script) '; ' $script ' ' ($args|str collect ' ') '|to json -r')
^ssh (get-url $host) ($full-command)|from json
} else {
error make {
msg: $"($script) is not a custom command, use regular ssh command instead"
label: {
text: "Not a custom command",
start: $span.start,
end: $span.end
}
}
}
}
# Turns on specified hosts using Wake on Lan # Turns on specified hosts using Wake on Lan
export def wake [ export def wake [
...names: string@"nu-complete wol" # list of host names to wake ...names: string@"nu-complete wol" # list of host names to wake