mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Port before_v0.60/math
, before_v0.60/parsing
and before_v0.60/git
(#844)
This PR is part of porting all old scripts #221 and includes a set of small modules: - `math` - `parsing` - `git`
This commit is contained in:
parent
429126f3d8
commit
15cb7179e2
7 changed files with 9 additions and 46 deletions
14
modules/git/README.md
Normal file
14
modules/git/README.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Git Scripts
|
||||
|
||||
### Definition
|
||||
|
||||
These scripts should be used to demonstrate how combine the power of nushell with git commands.
|
||||
|
||||
### Aliases
|
||||
If you find some of these scripts useful you can add them as aliases in your git config file.
|
||||
|
||||
For instance you can create a nushell script in your computer and define in your git config file an alias that call that script:
|
||||
```
|
||||
[alias]
|
||||
bcl = !nu \"D:\\Tools\\gitalias_bcl.nu\"
|
||||
```
|
15
modules/git/git_branch_age.nu
Normal file
15
modules/git/git_branch_age.nu
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Creates a table listing the branches of a git repository and the day of the last commit
|
||||
export def "git age" [] {
|
||||
git branch |
|
||||
lines |
|
||||
str substring 2.. |
|
||||
wrap name |
|
||||
insert last_commit {
|
||||
get name |
|
||||
each {
|
||||
git show $in --no-patch --format=%as | into datetime
|
||||
}
|
||||
} |
|
||||
sort-by last_commit
|
||||
}
|
||||
|
5
modules/parsing/README.md
Normal file
5
modules/parsing/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Parsing Scripts
|
||||
|
||||
### Definition
|
||||
|
||||
These scripts should be used to demonstrate how to parse any file format, including `json`, `csv`, etc. Also, perhaps parsing of `external` commands. For example, on Windows, perhaps we could wrap `ipconfig.exe` so that the output was more nushell friendly.
|
18
modules/parsing/sample_andres.json
Normal file
18
modules/parsing/sample_andres.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"name": "Brunello Cucinelli",
|
||||
"shoes": [
|
||||
{ "name": "tasselled black low-top lace-up", "price": 1000 },
|
||||
{ "name": "tasselled green low-top lace-up", "price": 1100 },
|
||||
{ "name": "plain beige suede moccasin", "price": 950 },
|
||||
{ "name": "plain olive suede moccasin", "price": 1050 }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Gucci",
|
||||
"shoes": [
|
||||
{ "name": "red leather laced sneakers", "price": 800 },
|
||||
{ "name": "black leather laced sneakers", "price": 900 }
|
||||
]
|
||||
}
|
||||
]
|
21
modules/parsing/sample_andres.nu
Normal file
21
modules/parsing/sample_andres.nu
Normal file
|
@ -0,0 +1,21 @@
|
|||
def look_for [word] {
|
||||
open sample_andres.json |
|
||||
flatten |
|
||||
flatten |
|
||||
insert comp {
|
||||
get shoes_name |
|
||||
split row " " |
|
||||
enumerate | each {
|
||||
[[idx, loc]; [$in.index, ($in.item | str index-of $word)]]
|
||||
} | flatten
|
||||
} |
|
||||
flatten |
|
||||
where comp.loc >= 0 |
|
||||
flatten |
|
||||
update idx { $in + 1 } |
|
||||
reject name price loc |
|
||||
rename nameWords targetWordIndex
|
||||
}
|
||||
|
||||
print (look_for "leather" | to json --indent 4)
|
||||
print (look_for "low-top" | to json --indent 4)
|
Loading…
Add table
Add a link
Reference in a new issue