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

refactor: (#418)

* refactor:  move in one commit

Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.

* refactor: 📝 add modules readme (wip)

* refactor:  small move

* refactor: 📝 changed nestring, updated modules readme

* refactor: 📝 to document or not to document

* fix: 🐛 themes

replaced the template to use `main` and regenerated them
from lemnos themes.

* Revert "fix: 🐛 themes"

This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886.

* refactor:  introduce sourced

- Created a source `root` in which sourcable demos are stored.
  Some might get converted to modules later on.
- Moved some files to bin too.

* fix: 🐛 fehbg.nu

* fix: 🐛 modules/after.nu

* moved some other stuff around

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Mel Massadian 2023-04-26 00:56:25 +02:00 committed by GitHub
parent 382696cd21
commit c47ccd42b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 185 additions and 12 deletions

View file

@ -0,0 +1,5 @@
# Formatting scripts
### Definition
The scripts in this folder are used to help formatting nicely inputs/outputs of nushell.

View 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 ' '
}
}
}

View 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
}
}

View file

@ -0,0 +1,45 @@
#diacritics map for Polish but the function is universal provided diacritics_map contains mappings for specific language
# Usage: (remove-diacritics 'Zażółć gęślą jaźń') == Zazolc gesla jazn
export def main [
arg: string
] {
let diacritics_map = {
# Polish
"Ą": "A",
"ą": "a",
"Ć": "C",
"ć": "c",
"Ę": "E",
"ę": "e",
"Ł": "L",
"ł": "l",
"Ń": "N",
"ń": "n",
"Ó": "O",
"ó": "o",
"Ś": "S",
"ś": "s",
"Ż": "Z",
"ż": "z",
"Ź": "Z",
"ź": "z",
# German
"ä": "ae",
"Ä": "Ae",
"ö": "oe",
"Ö": "Oe",
"ü": "ue",
"Ü": "Ue",
"ß": "ss"
}
$arg
|split chars
|each {|char|
$diacritics_map
|get -i -s $char
|default $char
}
|str join ''
}

13
modules/formats/to-ini.nu Normal file
View file

@ -0,0 +1,13 @@
# converts records into .ini files
export def "to ini" [] {
transpose key value
| update value {|row|
get value
| transpose key value
| format '{key}={value}'
| prepend $"[($row.key)]"
| str join (char nl)
}
| get value
| str join (char nl)
}

View file

@ -0,0 +1,68 @@
export def number-format [
num # Number to format
--thousands_delim (-t) = ' ' # Thousands delimiter: number-format 1000 -t ': 1'000
--whole_part_length (-w) = 0 # Length of padding whole-part digits: number-format 123 -w 6: 123
--decimal_digits (-d) = 0 # Number of digits after decimal delimiter: number-format 1000.1234 -d 2: 1000.12
--denom (-D) = "" # Denom `--denom "Wt": number-format 1000 --denom 'Wt': 1000Wt
] {
let parts = (
$num
| into string
| split row "."
)
let whole_part = (
$parts.0
| split chars
| reverse
| reduce -n -f [] {
|it, acc| if ((($it.index + 1) mod 3) == 0) {
$acc.item
| append $it.item
| append $thousands_delim
} else {
$acc.item
| append $it.item
}
}
| reverse
)
let whole_part2 = (
if ($whole_part | first) == $thousands_delim {
($whole_part | skip 1)
} else {
$whole_part
}
| str join ''
)
let whole_part3 = (
if $whole_part_length == 0 {
$whole_part2
} else {
$whole_part2
| fill -w $whole_part_length -c ' ' -a r
}
)
let dec_part = (
if ($parts | length) == 1 {
"0"
} else {
$parts.1
}
)
let dec_part2 = (
if $decimal_digits == 0 {
""
} else {
$".($dec_part)" | fill -w ($decimal_digits + 1) -c '0' -a l
}
)
let out = $"(ansi green)($whole_part3)($dec_part2)(ansi reset)(ansi green_bold)($denom)(ansi reset)"
$out
}