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:
2024-11-07 13:52:17 +00:00
parent 83b02bd753
commit 896af887ca
2351 changed files with 0 additions and 0 deletions
@@ -0,0 +1,5 @@
# Nu_101 Scripts
### Definition
These scripts should be used to demonstrate to the beginner how nushell scripting works. Perhaps how it's different from Windows `batch` files and `bash` shell scripts. Also, to show off how nushell pipes commands in and out of one another.
@@ -0,0 +1,46 @@
### These examples are here to show the user
### How the parser works by showing examples that will not parse
### The beginning nushell script writer / user may get confused
### as to why their script is not working
###
### If you uncomment any of the defs below these are
### the error messages you will see
#
#
#
### Examples p1 - p3 below elucidate the following idea:
### That a brace has to be on the same line as the def
###
###
### Error: nu::parser::missing_positional
### The error message is: "Missing required positional argument"
### missing block
###
### help: Usage: def <def_name> <params> <block>
###
#
### https://github.com/nushell/nushell/issues/2972
#
### All of these examples will not parse.
### def p1 [arg]
### { echo $arg }
### def p2 [arg]
### {
### echo $arg }
### def p3 [arg]
### {
### echo $arg
### }
### This breaks because you need a space between
### between foo and the left bracket
### def foo[] {
### "bar"
### }
### This works
### def foo [] {
### "bar"
### }
@@ -0,0 +1,5 @@
def my-ls [x] {
ls $x | where size > 10kb
}
my-ls .
@@ -0,0 +1,98 @@
# Some examples of how you can use nushell commands to treat lists like other data structures and perform equivalent data structure operations on them.
## Queue (first in, first out [FIFO])
let queue = [1 2 3]
let elem = 4
### Enqueue (push)
$queue | append $elem
### Dequeue (shift)
{ out: ($queue | first),
new_queue: ($queue | skip 1) }
## Stack (last in, first out [LIFO])
### Push
$queue | append $elem
### Pop
{ out: ($queue | last),
new_stack: ($queue | drop) }
## Set
# Ordered sets are similar to below, just taking more care of order when altering the sets since lists are already ordered.
let set = [1 2 3]
let elem = 4
let set_b = [2 3 4 5]
### Checking set membership
$elem in $set # false
2 in $set # true
### Inserting a new element
if $elem not-in $set { $set | append $elem }
# or
$set | append $elem | uniq
# Result: [1 2 3 4]
### Union
$set ++ $set_b | uniq
# Result: [1 2 3 4 5]
### Intersection
$set | filter { |elem| $elem in $set_b }
# Result: [2 3]
### Difference
# $set - $set_b
$set | filter { |elem| $elem not-in $set_b }
# or
# Result: [1]
### Symmetric Difference
$set ++ $set_b | uniq --unique
# Result: [1 4 5]
### Multiset (bag)
# Pretty much the same as a list but you can get the counts of the multiset elements with
[1 2 2 3] | uniq --count
# Result:
# ╭───┬───────┬───────╮
# │ # │ value │ count │
# ├───┼───────┼───────┤
# │ 0 │ 1 │ 1 │
# │ 1 │ 2 │ 2 │
# │ 2 │ 3 │ 1 │
# ╰───┴───────┴───────╯
# The unique values along with how many times they are in the multiset/bag.
@@ -0,0 +1,74 @@
### So in this case you have to pass in a parameter
### Any parameter you type will work
### If you don't type a parameter you get an error
###
### The syntax for this is
### noflag hola
###
def noflag [x] {
echo $x
}
### The syntax for this is
### flag -f
### flag --flag
### If you type anything else it does not work
### For example
### flag -flag
### flag -f=hola
### flag -f hola
### flag -f = hola
def flag [
--flag(-f)
] {
echo $flag
}
# Write out the flags you entered
def flag_details [myint: int, mystring: string] {
echo "myint is " $myint | str join
echo "mystring is " $mystring | str join
}
# Get the data passed into the flags
def get_flag [
--test_int(-i): int # The test intlocation
--test_string(-s): string # The test string
] {
let is_int_empty = ($test_int == null)
let is_string_empty = ($test_string == null)
let no_int_no_string = ($is_int_empty == true and $is_string_empty == true)
let no_int_with_string = ($is_int_empty == true and $is_string_empty == false)
let with_int_no_string = ($is_int_empty == false and $is_string_empty == true)
let with_int_with_string = ($is_int_empty == false and $is_string_empty == false)
echo 'no int and no string ' $no_int_no_string | str join
echo 'no int with string ' $no_int_with_string | str join
echo 'with int and no string ' $with_int_no_string | str join
echo 'with int and with string ' $with_int_with_string | str join
if $no_int_no_string {
(flag_details 1 "blue")
} else if $no_int_with_string {
(flag_details 1 $test_string)
} else if $with_int_no_string {
(flag_details $test_int "blue")
} else if $with_int_with_string {
(flag_details $test_int $test_string)
}
}
# To run this call
# > get_flag
# it will default to int 1 and string blue
# > get_flag -i 2
# This changes to int 2 and string blue
# > get_flag -i 3 -s green
# This changes to int 3 and string green
@@ -0,0 +1,11 @@
# This is an experiment to see if one can have
# $it in and inner loop and an outer loop at
# the same time, each having different values
seq 30 39 | each { |outer|
let row = $"($outer) "
let data = (seq 40 49 | each { |inner|
$"($inner) "
} | str join)
$"($row)($data)"
} | str join (char newline)
@@ -0,0 +1,24 @@
# This checks the -f switch to see if it was supplied
# and tests the new $nothing variable
def nada [
flat?
] {
if $flat == null {
true
} else {
false
}
}
# This shows an alternate way to check for nothing
def nada2 [
flat?
] {
let flat = ($flat | is-empty)
if $flat {
true
} else {
false
}
}