mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
Add parsers for cpuinfo and dmidecode (#393)
* Add parsers for cpuinfo and dmidecode * newlines --------- Co-authored-by: Yethal <nosuchemail@email.com>
This commit is contained in:
parent
a8e6ea2923
commit
0e6168bf7c
2 changed files with 58 additions and 0 deletions
22
formats/from-cpuinfo.nu
Normal file
22
formats/from-cpuinfo.nu
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Convert from contents of /proc/cpuinfo to structured data
|
||||||
|
export def "from cpuinfo" [] {
|
||||||
|
lines
|
||||||
|
| split list ''
|
||||||
|
| each {
|
||||||
|
split column ':'
|
||||||
|
| str trim
|
||||||
|
| update column1 {
|
||||||
|
get column1
|
||||||
|
| str replace -a -s ' ' '_'
|
||||||
|
}
|
||||||
|
| transpose -r -d
|
||||||
|
| update flags {
|
||||||
|
get flags
|
||||||
|
| split row ' '
|
||||||
|
}
|
||||||
|
| update bugs {
|
||||||
|
get bugs
|
||||||
|
| split row ' '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
formats/from-dmidecode.nu
Normal file
36
formats/from-dmidecode.nu
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Convert from output of dmidecode to structured data
|
||||||
|
export def "from dmidecode" [] {
|
||||||
|
lines
|
||||||
|
| skip until {|x|
|
||||||
|
$x starts-with 'Handle'
|
||||||
|
}
|
||||||
|
| split list ''
|
||||||
|
| each {|entry|
|
||||||
|
let parsed_entry = (
|
||||||
|
$entry
|
||||||
|
| get 0
|
||||||
|
| parse 'Handle {handle}, DMI type {type}, {bytes} bytes'
|
||||||
|
| get 0
|
||||||
|
| insert description ($entry|get 1)
|
||||||
|
| insert values {
|
||||||
|
if ($entry|length) > 2 {
|
||||||
|
if ($entry|get 2|str trim) == 'Header and Data:' {
|
||||||
|
{'header_and_data': ($entry|skip 3|str trim)}
|
||||||
|
} else {
|
||||||
|
$entry
|
||||||
|
| skip 2
|
||||||
|
| split column ':'
|
||||||
|
| str trim
|
||||||
|
| str downcase column1
|
||||||
|
| str replace -a -s ' ' '_' column1
|
||||||
|
| transpose -r -d
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
$parsed_entry
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue