1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

one step closer to complete

This commit is contained in:
Darren Schroeder 2021-05-24 16:24:34 -05:00
parent 7521ffaaf2
commit c8c1d16cbf
8 changed files with 103 additions and 72 deletions

View file

@ -7,7 +7,8 @@ def ls-incorrect-dirs [] {
} }
let incorrect_count = (ls-incorrect-dirs | length); let incorrect_count = (ls-incorrect-dirs | length);
if $incorrect_count > 0 { if $incorrect_count > 0 {
echo `The following directories are named incorrectly: {{(char newline)}}` # echo `The following directories are named incorrectly: {{(char newline)}}`
$"The following directories are named incorrectly: (char newline)"
ls-incorrect-dirs ls-incorrect-dirs
exit 1 exit 1
} { } {

View file

@ -1,7 +1,9 @@
let m_table = ( let m_table = (
echo [['name', 'tz', 'time']; ['andres' 'US/Eastern' ' '] ['fdncred' 'US/Central' ' '] ['gedge' 'US/Eastern' ' '] ['jturner' 'NZ' ' '] ['wycats' 'US/Pacific' ' ']] [['name', 'tz', 'time']; ['andres' 'US/Eastern' ' '] ['fdncred' 'US/Central' ' '] ['gedge' 'US/Eastern' ' '] ['jturner' 'NZ' ' '] ['wycats' 'US/Pacific' ' ']]
) )
let now = (date now) let now = (date now)
echo $m_table | update time { $m_table | update time {
echo $now | date to-timezone (get tz) | date format '%c' each { |name|
$now | date to-timezone ($name | get tz) | date format '%c'
}
} }

View file

@ -13,8 +13,8 @@ let nu_files = (ls **/*.nu)
let nu_table = (echo $nu_files | let nu_table = (echo $nu_files |
get name | get name |
wrap File | wrap File |
insert Category { insert Category { |it|
let cat = (get File | path dirname) let cat = (echo $it.File | path dirname)
if $cat == "" { if $cat == "" {
echo "not assigned yet" echo "not assigned yet"
} { } {
@ -23,8 +23,8 @@ let nu_table = (echo $nu_files |
} | where Category !~ ".git" | select Category File | sort-by Category) } | where Category !~ ".git" | select Category File | sort-by Category)
# Let's fix the file now # Let's fix the file now
let nu_table = (echo $nu_table | update File { let nu_table = (echo $nu_table | update File { |it|
let file_path = (get File) let file_path = (echo $it.File)
let file_name = (echo $file_path | path basename) let file_name = (echo $file_path | path basename)
let file_link = (build-string "[" $file_name "]" "(./" $file_path ")") let file_link = (build-string "[" $file_name "]" "(./" $file_path ")")
echo $file_link echo $file_link

View file

@ -1,22 +1,47 @@
# A small script to auto-update nushell in linux # A small script to auto-update nushell in linux
# WIP - Not finished yet # WIP - Not finished yet
def get-latest [] { def get-latest [] {
# fetch the information about the latest release
let metadata = (fetch https://api.github.com/repos/nushell/nushell/releases/latest) let metadata = (fetch https://api.github.com/repos/nushell/nushell/releases/latest)
let release_name = (echo $metadata | get name | split row ' ' | nth 0) let release_name = ($metadata | get name | split row ' ' | nth 0)
let body = (echo $metadata | get body) # get the body that shows information about this release
let asset_info = (echo $metadata | get assets | where name =~ 'linux.tar.gz') let body = ($metadata | get body)
let download_url = (echo $asset_info | get browser_download_url) # find the linux download
let file_name = (echo $asset_info | get name) let asset_info = ($metadata | get assets | where name =~ 'linux.tar.gz')
echo (build-string "Release name is " $release_name (char newline) (char newline)) # construct the url
echo (build-string $body (char newline) (char newline) "Downloading...") let download_url = ($asset_info | get browser_download_url)
let file_name = ($asset_info | get name)
# tell you what i'm doing
$"Release name is ($release_name)(char newline)(char newline)"
$"($body)(char newline)(char newline)Downloading..."
# fetch doesn't appear to follow redirects so get the actual download url
let redirected_url = (fetch $download_url --raw) let redirected_url = (fetch $download_url --raw)
let real_download_url = (echo $redirected_url | xpath '//@href' | get '//@href') # pull the download url out with xpath, thank you!
let real_download_url = ($redirected_url | xpath '//@href' | get '//@href')
# now do the real download of the archive
fetch $real_download_url | save $file_name fetch $real_download_url | save $file_name
# Remaining to do # tell you what i'm doing
# tar xf $file_name $"Extracting ($file_name) to /tmp(char newline)"
# parse the $file_name to get the folder like going # extract the tar file to the temp folder
# from: nu_0_27_0_linux.tar.gz tar -xf ($file_name) -C /tmp
# to: nu_0_27_0_linux # parse the $file_name to get the folder
# cp nu_0_27_0_linux/nushell-0.27.0/* ~/.cargo/bin # echo nu_0_31_0_linux.tar.gz | path parse | get stem | path parse | get stem
# echo nu_0_31_0_linux.tar.gz | split column '.' | get Column1
# now get the file name using the path commands. it was a little tricky because
# there are two extensions .tar and .gz
let root_file_name = ($file_name | path parse | get stem | path parse | get stem)
# update our progress
$"Copying files from /tmp/($root_file_name)/*/* to ~/.cargo/bin(char newline)"
# this is for testing so it doesn't overwrite my real nu. this should really
# be a paremeter
mkdir release
# construct the copy from and to paths
let cp_from_path = $"/tmp/($root_file_name)/*/*"
let cp_to_path = "./release"
# actually run the cp command
# we may want to make this overwrite and not prompt
cp ($cp_from_path) ($cp_to_path)
# exec ~/.cargo/bin/nu # exec ~/.cargo/bin/nu
$"Starting nushell(char nl)"
exec ./release/nu
} }

View file

@ -92,19 +92,19 @@ def bg_from_rgb [
green:int # green component 0-255 green:int # green component 0-255
blue:int # blue component 0-255 blue:int # blue component 0-255
] { ] {
echo [(ansi -e '48;2;') $red ';' $green ';' $blue 'm'] | str collect $"(ansi -e '48;2;')($red);($green);($blue)m"
} }
# Get a foreground color from an index value 0-255 # Get a foreground color from an index value 0-255
def fg_from_index [ def fg_from_index [
idx:int # index value 0-255 idx:int # index value 0-255
] { ] {
echo [(ansi -e '38;5;') $idx 'm'] | str collect $"(ansi -e '38;5;')($idx)m"
} }
# Get a background color from an index value 0-255 # Get a background color from an index value 0-255
def bg_from_index [ def bg_from_index [
idx:int # index value 0-255 idx:int # index value 0-255
] { ] {
echo [(ansi -e '48;5;') $idx 'm'] | str collect $"(ansi -e '48;5;')($idx)m"
} }

View file

@ -5,18 +5,18 @@ def print [
...rest # All of the parameters ...rest # All of the parameters
] { ] {
let is_empty = ($separator | empty?) let is_empty = ($separator | empty?)
let num_of_rest = (echo $rest | length) let num_of_rest = ($rest | length)
echo $rest | each --numbered { $rest | each --numbered { |param|
if $is_empty { if $is_empty {
build-string $it.item $param.item
} { } {
if $num_of_rest > ($it.index + 1) { if $num_of_rest > ($param.index + 1) {
build-string $it.item $separator $"($param.item)($separator)"
} { } {
build-string $it.item $param.item
} }
} }
} | str collect } | into string | str collect
} }
# > print 1 2 3 "four" -s '--' # > print 1 2 3 "four" -s '--'
@ -33,11 +33,11 @@ def print2 [
...rest # All of the parameters ...rest # All of the parameters
] { ] {
let is_empty = ($separator | empty?) let is_empty = ($separator | empty?)
let num_of_rest = (echo $rest | length) let num_of_rest = ($rest | length)
if $is_empty { if $is_empty {
echo $rest | str from | str collect $rest | into string | str collect
} { } {
echo $rest | str from | str collect $separator $rest | into string | str collect $separator
} }
} }
@ -53,33 +53,33 @@ def print3 [
...rest # All of the parameters ...rest # All of the parameters
] { ] {
let sep_empty = ($separator | empty?) let sep_empty = ($separator | empty?)
let num_of_rest = (echo $rest | length) let num_of_rest = ($rest | length)
let flat = ($flat | empty?) let flat = ($flat | empty?)
echo $rest | each --numbered { $rest | each --numbered { |param|
if $sep_empty { if $sep_empty {
#log 'sep is empty' #log 'sep is empty'
if (echo $it.item | length) > 1 && $flat { if (echo $param.item | length) > 1 && $flat {
#log 'flatten please' #log 'flatten please'
let flatter = (echo $it.item | flatten | str from | str collect) let flatter = ($param.item | flatten | into string | str collect)
build-string $flatter $flatter
} { } {
#log 'no flat' #log 'no flat'
build-string $it.item $param.item
} }
} { } {
if $num_of_rest > ($it.index + 1) { if $num_of_rest > ($param.index + 1) {
if (echo $it.item | length) > 1 && $flat { if ($param.item | length) > 1 && $flat {
let flatter = (echo $it.item | flatten | str from | str collect $separator) let flatter = ($param.item | flatten | into string | str collect $separator)
build-string $flatter $separator $"($flatter)($separator)"
} { } {
build-string $it.item $separator $"($param.item)($separator)"
} }
} { } {
if (echo $it.item | length) > 1 && $flat { if ($param.item | length) > 1 && $flat {
let flatter = (echo $it.item | flatten | str from | str collect $separator) let flatter = ($param.item | flatten | into string | str collect $separator)
build-string $flatter $flatter
} { } {
build-string $it.item $param.item
} }
} }
} }

View file

@ -10,24 +10,27 @@ let table = (echo [
]) ])
# Show what the table looks like # Show what the table looks like
echo $table $"This is an example table (char nl)"
$table
$"This is markdown created from the example table (char nl)"
# Now show what the table in Markdown looks like # Now show what the table in Markdown looks like
build-string '## Nushell' (char nl) (char nl) $"## Nushell(char nl)(char nl)"
echo $table | group-by user_login | pivot user prs | each { $table | group-by user_login | pivot user prs | each { |row|
let user_name = $it.user let user_name = $row.user
let pr_count = (echo $it.prs | length) let pr_count = (echo $row.prs | length)
# only print the comma if there's another item # only print the comma if there's another item
let user_prs = (echo $it.prs | each -n { let user_prs = ($row.prs | each -n { |pr|
if $pr_count == ($it.index + 1) { if $pr_count == ($pr.index + 1) {
build-string '[' $it.item.title '](' $it.item.url ')' build-string '[' $pr.item.title '](' $pr.item.url ')'
} { } {
build-string '[' $it.item.title '](' $it.item.url '), and ' build-string '[' $pr.item.title '](' $pr.item.url '), and '
} }
} | str collect) } | str collect)
build-string '- ' $user_name ' created ' $user_prs (char nl) $"- ($user_name) created ($user_prs) (char nl)"
} | str collect } | str collect
# ╭───┬──────────────────────────────────────────────────────────┬─────────────────┬───────────────────────────────────────────────────────╮ # ╭───┬──────────────────────────────────────────────────────────┬─────────────────┬───────────────────────────────────────────────────────╮

24
temp.nu
View file

@ -5,7 +5,7 @@ def "temp f-to-c" [
# (100°F 32) × 5/9 = 37.778°C # (100°F 32) × 5/9 = 37.778°C
let celcius = (($fahren - 32) * 5 / 9) let celcius = (($fahren - 32) * 5 / 9)
build-string $fahren ' °F is ' $celcius ' °C' $"($fahren) °F is ($celcius) °C"
} }
# Convert Fahrenheit to Kelvin # Convert Fahrenheit to Kelvin
@ -15,7 +15,7 @@ def "temp f-to-k" [
# (100°F 32) × 5/9 + 273.15 = 310.928K # (100°F 32) × 5/9 + 273.15 = 310.928K
let kelvin = (($fahren - 32) * 5 / 9 + 273.15) let kelvin = (($fahren - 32) * 5 / 9 + 273.15)
build-string $fahren ' °F is ' $kelvin ' °K' $"($fahren) °F is ($kelvin) °K"
} }
# Convert Celcius to Fahrenheit # Convert Celcius to Fahrenheit
@ -25,7 +25,7 @@ def "temp c-to-f" [
# (100°C × 9/5) + 32 = 212°F # (100°C × 9/5) + 32 = 212°F
let fahren = (($celcius * 9 / 5) + 32) let fahren = (($celcius * 9 / 5) + 32)
build-string $celcius ' °C is ' $fahren ' °F' $"($celcius) °C is ($fahren) °F"
} }
# Convert Celcius to Kelvin # Convert Celcius to Kelvin
@ -35,7 +35,7 @@ def "temp c-to-k" [
# 100°C + 273.15 = 373.15K # 100°C + 273.15 = 373.15K
let kelvin = ($celcius + 273.15) let kelvin = ($celcius + 273.15)
build-string $celcius ' °C is ' $kelvin ' °K' $"($celcius) °C is ($kelvin) °K"
} }
# Convert Kelvin to Fahrenheit # Convert Kelvin to Fahrenheit
@ -45,7 +45,7 @@ def "temp k-to-f" [
# (100K 273.15) × 9/5 + 32 = -279.7°F # (100K 273.15) × 9/5 + 32 = -279.7°F
let fahren = (($kelvin - 273.15) * 9 / 5 + 32) let fahren = (($kelvin - 273.15) * 9 / 5 + 32)
build-string $kelvin ' °K is ' $fahren ' °F' $"($kelvin) °K is ($fahren) °F"
} }
# Convert Kelvin to Celcius # Convert Kelvin to Celcius
@ -55,18 +55,18 @@ def "temp k-to-c" [
# 100K 273.15 = -173.1°C # 100K 273.15 = -173.1°C
let celcius = ($kelvin - 273.15) let celcius = ($kelvin - 273.15)
build-string $kelvin ' °K is ' $celcius ' °C' $"($kelvin) °K is ($celcius) °C"
} }
temp f-to-c 100 temp f-to-c 100
echo (char nl) char nl
temp f-to-k 100 temp f-to-k 100
echo (char nl) char nl
temp c-to-f 100 temp c-to-f 100
echo (char nl) char nl
temp c-to-k 100 temp c-to-k 100
echo (char nl) char nl
temp k-to-f 100 temp k-to-f 100
echo (char nl) char nl
temp k-to-c 100 temp k-to-c 100
echo (char nl) char nl