mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Merge branch 'main' of https://github.com/fdncred/nu_scripts into main
This commit is contained in:
commit
e2bee3fd16
3 changed files with 38 additions and 1 deletions
24
nothing.nu
Normal file
24
nothing.nu
Normal file
|
@ -0,0 +1,24 @@
|
|||
# This checks the -f switch to see if it was supplied
|
||||
# and tests the new $nothing variable
|
||||
def nada [
|
||||
--flat(-f)
|
||||
] {
|
||||
if $flat == $nothing {
|
||||
echo $true
|
||||
} {
|
||||
echo $false
|
||||
}
|
||||
}
|
||||
|
||||
# This shows an alternate way to check for nothing
|
||||
def nada2 [
|
||||
--flat(-f)
|
||||
] {
|
||||
let flat = $(= $flat | empty?)
|
||||
|
||||
if $flat {
|
||||
echo $true
|
||||
} {
|
||||
echo $false
|
||||
}
|
||||
}
|
6
stdlib_candidate/logging.nu
Normal file
6
stdlib_candidate/logging.nu
Normal file
|
@ -0,0 +1,6 @@
|
|||
# This is a first attempt and some type of logging
|
||||
def log [message:any] {
|
||||
let now = $(date now | date format '%Y%m%d_%H%M%S.%f')
|
||||
let mess = $(build-string $now '|DBG|' $message $(char newline))
|
||||
echo $mess | autoview
|
||||
}
|
|
@ -41,22 +41,29 @@ def print2 [
|
|||
}
|
||||
}
|
||||
|
||||
# Bring in the logging command
|
||||
source logging.nu
|
||||
|
||||
# A print command that concatenates arguments together with an optional separator.
|
||||
# This print command will also concatenate tables like [1 2 3] as well as most other primitives
|
||||
# since the str from command has been updated with wider support.
|
||||
def print3 [
|
||||
--separator(-s):any # Optional separator (not yet flagged as optional?)
|
||||
--flat(-f) # If tables are found, flatten them
|
||||
--flat(-f) # If tables are found, flatten them
|
||||
...rest # All of the parameters
|
||||
] {
|
||||
let sep_empty = $(= $separator | empty?)
|
||||
let num_of_rest = $(echo $rest | count)
|
||||
let flat = $(= $flat | empty?)
|
||||
echo $rest | each --numbered {
|
||||
if $sep_empty {
|
||||
log 'sep is empty'
|
||||
if $(echo $it.item | count) > 1 && $flat {
|
||||
log 'flatten please'
|
||||
let flatter = $(echo $it.item | flatten | str from | str collect)
|
||||
build-string $flatter
|
||||
} {
|
||||
log 'no flat'
|
||||
build-string $it.item
|
||||
}
|
||||
} {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue