s
This commit is contained in:
3
examples/ifconfig_tun_find.nu
Normal file
3
examples/ifconfig_tun_find.nu
Normal file
@@ -0,0 +1,3 @@
|
||||
ifconfig | lines -s | each { |row| (find "tun") } | each { |row| (find "prefixlen") }
|
||||
| split column --collapse-empty --regex "[% ]" "interface" "mac" "dev" "pl"
|
||||
| select "dev" "mac"
|
32
examples/menu.nu
Normal file
32
examples/menu.nu
Normal file
@@ -0,0 +1,32 @@
|
||||
let new_menu = {
|
||||
name: new_menu
|
||||
only_buffer_difference: true
|
||||
marker: "# "
|
||||
type: {
|
||||
layout: list
|
||||
page_size: 10
|
||||
}
|
||||
style: {
|
||||
text: green
|
||||
selected_text: green_reverse
|
||||
description_text: yellow
|
||||
}
|
||||
source: { |buffer, position|
|
||||
$nu.scope.vars
|
||||
| where name =~ $buffer
|
||||
| sort-by name
|
||||
| each { |it| {value: $it.name description: $it.type} }
|
||||
}
|
||||
}
|
||||
|
||||
$env.config.menus = ($env.config.menus | append $new_menu)
|
||||
|
||||
# let $nu.scope.vars = [{
|
||||
# value: # The value that will be inserted in the buffer
|
||||
# description: # Optional. Description that will be display with the selected value
|
||||
# span: { # Optional. Span indicating what section of the string will be replaced by the value
|
||||
# start:
|
||||
# end:
|
||||
# }
|
||||
# extra: [string] # Optional. A list of strings that will be displayed with the selected value. Only works with a description menu
|
||||
# }]
|
17
examples/paths.nu
Normal file
17
examples/paths.nu
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
let envpath = $env.PATH
|
||||
| where ($it | str contains -n '.apple.security')
|
||||
| where ($it | str contains -n 'Cryptexes')
|
||||
| where ($it | str contains -n 'dotnet')
|
||||
| where ($it | str contains -n -i 'gpg')
|
||||
| append ($env.HOME | path join .cargo/bin)
|
||||
| append ($env.HOME | path join hero/bin)
|
||||
| uniq
|
||||
| sort
|
||||
|
||||
load-env {PATH:$envpath}
|
||||
|
||||
# -i means case insensitive
|
||||
# -n means not
|
||||
|
26
examples/restcall_xml.nu
Normal file
26
examples/restcall_xml.nu
Normal file
@@ -0,0 +1,26 @@
|
||||
let l = http get https://blog.rust-lang.org/feed.xml
|
||||
let data = $l.content | into value | where tag == 'author'
|
||||
|
||||
echo $data | to json
|
||||
|
||||
# now we get one list of the content
|
||||
$data | get content | each { get content | each { get content } } | flatten | flatten | to json | save /tmp/test.json
|
||||
|
||||
let input = "182.178.55.3:4333"
|
||||
$input | parse --regex '(?P<addr>\d{1,3}(\.\d{1,3}){3})(:(?P<port>\d+))?' | default port 2222 | select addr port
|
||||
|
||||
let input = "182.178.55.3"
|
||||
$input | parse --regex '(?P<addr>\d{1,3}(\.\d{1,3}){3})(:(?P<port>\d+))?' | default port 2222 | select addr port
|
||||
|
||||
|
||||
let input = "182.178.55.3:4333"
|
||||
$input | parse --regex '(?P<addr>\d{1,3}(\.\d{1,3}){3})(:(?P<port>\d+))?' |
|
||||
each { |row| if $row.port == $"" { $row | upsert port 2222 } else { $row } } | select addr port
|
||||
|
||||
let ipaddr_ = $input | parse --regex '(?P<addr>\d{1,3}(\.\d{1,3}){3})(:(?P<port>\d+))?' | select addr port
|
||||
let ipaddr = $ipaddr_.port ???
|
||||
|
||||
$input | parse '{addr}:{port}'
|
||||
|
||||
let data = open data.json | from json
|
||||
let x = "sss"
|
23
examples/schiit.nu
Normal file
23
examples/schiit.nu
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env nu
|
||||
let baseurl = 'https://www.schiit.co.uk/'
|
||||
let pages = ['headphone-amps' 'dacs']
|
||||
|
||||
# Simple script to check stock of https://schiit.co.uk store
|
||||
def schiit [] {
|
||||
$pages | par-each { |page|
|
||||
http get ($baseurl + $page)
|
||||
|query web -q '.price, .stock, .product-item h5'
|
||||
|str trim
|
||||
|group 3
|
||||
|each {
|
||||
|x| {
|
||||
name: $x.0,
|
||||
avail: $x.1,
|
||||
price: $x.2
|
||||
}
|
||||
}
|
||||
}
|
||||
|sort-by avail
|
||||
}
|
||||
|
||||
schiit
|
7
examples/string_format.nu
Normal file
7
examples/string_format.nu
Normal file
@@ -0,0 +1,7 @@
|
||||
# string interpolation
|
||||
|
||||
let name = "this is a string"
|
||||
$"s ($name)"
|
||||
|
||||
https://www.nushell.sh/book/working_with_strings.html#string-comparison
|
||||
|
20
examples/text_write.nu
Normal file
20
examples/text_write.nu
Normal file
@@ -0,0 +1,20 @@
|
||||
"
|
||||
Band,Album,Year
|
||||
|
||||
Fugazi,In On The Kill Taker,1993
|
||||
Fugazi,The Argument,2001{$x}
|
||||
|
||||
Fugazi,7 Songs,1988
|
||||
Fugazi,Repeater,1990
|
||||
Fugazi,Steady Diet of Nothing,1991
|
||||
|
||||
" | save -f /tmp/test.txt
|
||||
|
||||
|
||||
#-s is skip empty lines
|
||||
let data = open /tmp/test.txt | lines -s | split column "," Band Album Year | skip 1 | sort-by Year
|
||||
|
||||
$data | each { |row| $row.Band + ":" + $row.Album + ":" + $row.Year }
|
||||
$data |to csv
|
||||
|
||||
|
Reference in New Issue
Block a user