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

Fix: SSH config may not contain hostname (#893)

I am sorry. I assumed that an SSH host in the config file must contain a
hostname, but this assumption is not true.

If a user reads an SSH host that doesn't contain a hostname, it will
fail to parse.
This commit is contained in:
denny 2024-07-11 23:26:04 +08:00 committed by GitHub
parent 0d70dbddd5
commit 1533149826
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View file

@ -38,15 +38,20 @@ def "nu-complete ssh-host" [] {
$files | each { |file|
let lines = $file | open | lines | str trim
let hosts = $lines
| parse --regex '^Host\s+(?<host>.+)'
| get host
let hostnames = $lines
| parse --regex '^HostName\s+(?<hostname>.+)'
| get hostname
$hosts | zip $hostnames | each { ||
{'value': $in.0, 'description': $in.1}
mut result = []
for $line in $lines {
let data = $line | parse --regex '^Host\s+(?<host>.+)'
if ($data | is-not-empty) {
$result = ($result | append { 'value': ($data.host | first), 'description': "" })
continue;
}
let data = $line | parse --regex '^HostName\s+(?<hostname>.+)'
if ($data | is-not-empty) {
let last = $result | last | update 'description' ($data.hostname | first)
$result = ($result | drop | append $last)
}
}
$result
} | flatten
}