mirror of
https://github.com/Cian-H/dotfiles.git
synced 2026-03-03 03:58:02 +00:00
Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows) and improves grepability with neovim/telescope
This commit is contained in:
5
dot_config/nushell/nu_scripts/modules/formats/README.md
Normal file
5
dot_config/nushell/nu_scripts/modules/formats/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Formatting scripts
|
||||
|
||||
### Definition
|
||||
|
||||
The scripts in this folder are used to help formatting nicely inputs/outputs of nushell.
|
||||
@@ -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 ' ' '_'
|
||||
}
|
||||
| transpose -r -d
|
||||
| update flags {
|
||||
get flags
|
||||
| split row ' '
|
||||
}
|
||||
| update bugs {
|
||||
get bugs
|
||||
| split row ' '
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 ' ' '_' column1
|
||||
| transpose -r -d
|
||||
}
|
||||
} else {
|
||||
{}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$parsed_entry
|
||||
}
|
||||
}
|
||||
11
dot_config/nushell/nu_scripts/modules/formats/from-env.nu
Normal file
11
dot_config/nushell/nu_scripts/modules/formats/from-env.nu
Normal file
@@ -0,0 +1,11 @@
|
||||
# Converts a .env file into a record
|
||||
# may be used like this: open .env | load-env
|
||||
# works with quoted and unquoted .env files
|
||||
def "from env" []: string -> record {
|
||||
lines
|
||||
| split column '#' # remove comments
|
||||
| get column1
|
||||
| parse "{key}={value}"
|
||||
| str trim value -c '"' # unquote values
|
||||
| transpose -r -d
|
||||
}
|
||||
@@ -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
dot_config/nushell/nu_scripts/modules/formats/to-ini.nu
Normal file
13
dot_config/nushell/nu_scripts/modules/formats/to-ini.nu
Normal file
@@ -0,0 +1,13 @@
|
||||
# converts records into .ini files
|
||||
export def "to ini" [] {
|
||||
transpose key value
|
||||
| update value {|row|
|
||||
$row.value
|
||||
| transpose key value
|
||||
| format pattern "{key}={value}"
|
||||
| prepend $"[($row.key)]"
|
||||
| str join (char nl)
|
||||
}
|
||||
| get value
|
||||
| str join (char nl)
|
||||
}
|
||||
@@ -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 -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
|
||||
}
|
||||
Reference in New Issue
Block a user