From c8c1d16cbf23e191e52a234752cee597186357ec Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Mon, 24 May 2021 16:24:34 -0500 Subject: [PATCH] one step closer to complete --- lint_directories.nu | 3 +- maintainer_time.nu | 8 +-- make_readme_table.nu | 8 +-- stdlib_candidate/get-latest-release-linux.nu | 53 ++++++++++++++------ stdlib_candidate/nu_style.nu | 6 +-- stdlib_candidate/print.nu | 50 +++++++++--------- table_grouping.nu | 23 +++++---- temp.nu | 24 ++++----- 8 files changed, 103 insertions(+), 72 deletions(-) diff --git a/lint_directories.nu b/lint_directories.nu index 0e4b7f6..d2efac6 100755 --- a/lint_directories.nu +++ b/lint_directories.nu @@ -7,7 +7,8 @@ def ls-incorrect-dirs [] { } let incorrect_count = (ls-incorrect-dirs | length); 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 exit 1 } { diff --git a/maintainer_time.nu b/maintainer_time.nu index 8997087..7afd7c7 100644 --- a/maintainer_time.nu +++ b/maintainer_time.nu @@ -1,7 +1,9 @@ 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) -echo $m_table | update time { - echo $now | date to-timezone (get tz) | date format '%c' +$m_table | update time { + each { |name| + $now | date to-timezone ($name | get tz) | date format '%c' + } } \ No newline at end of file diff --git a/make_readme_table.nu b/make_readme_table.nu index d6ee98e..d457131 100644 --- a/make_readme_table.nu +++ b/make_readme_table.nu @@ -13,8 +13,8 @@ let nu_files = (ls **/*.nu) let nu_table = (echo $nu_files | get name | wrap File | - insert Category { - let cat = (get File | path dirname) + insert Category { |it| + let cat = (echo $it.File | path dirname) if $cat == "" { echo "not assigned yet" } { @@ -23,8 +23,8 @@ let nu_table = (echo $nu_files | } | where Category !~ ".git" | select Category File | sort-by Category) # Let's fix the file now -let nu_table = (echo $nu_table | update File { - let file_path = (get File) +let nu_table = (echo $nu_table | update File { |it| + let file_path = (echo $it.File) let file_name = (echo $file_path | path basename) let file_link = (build-string "[" $file_name "]" "(./" $file_path ")") echo $file_link diff --git a/stdlib_candidate/get-latest-release-linux.nu b/stdlib_candidate/get-latest-release-linux.nu index c737010..4c8f9c3 100644 --- a/stdlib_candidate/get-latest-release-linux.nu +++ b/stdlib_candidate/get-latest-release-linux.nu @@ -1,22 +1,47 @@ # A small script to auto-update nushell in linux # WIP - Not finished yet def get-latest [] { + # fetch the information about the latest release let metadata = (fetch https://api.github.com/repos/nushell/nushell/releases/latest) - let release_name = (echo $metadata | get name | split row ' ' | nth 0) - let body = (echo $metadata | get body) - let asset_info = (echo $metadata | get assets | where name =~ 'linux.tar.gz') - let download_url = (echo $asset_info | get browser_download_url) - let file_name = (echo $asset_info | get name) - echo (build-string "Release name is " $release_name (char newline) (char newline)) - echo (build-string $body (char newline) (char newline) "Downloading...") + let release_name = ($metadata | get name | split row ' ' | nth 0) + # get the body that shows information about this release + let body = ($metadata | get body) + # find the linux download + let asset_info = ($metadata | get assets | where name =~ 'linux.tar.gz') + # construct the url + 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 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 - # Remaining to do - # tar xf $file_name - # parse the $file_name to get the folder like going - # from: nu_0_27_0_linux.tar.gz - # to: nu_0_27_0_linux - # cp nu_0_27_0_linux/nushell-0.27.0/* ~/.cargo/bin + # tell you what i'm doing + $"Extracting ($file_name) to /tmp(char newline)" + # extract the tar file to the temp folder + tar -xf ($file_name) -C /tmp + # parse the $file_name to get the folder + # 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 + $"Starting nushell(char nl)" + exec ./release/nu } \ No newline at end of file diff --git a/stdlib_candidate/nu_style.nu b/stdlib_candidate/nu_style.nu index af6706b..cfaf4b8 100644 --- a/stdlib_candidate/nu_style.nu +++ b/stdlib_candidate/nu_style.nu @@ -92,19 +92,19 @@ def bg_from_rgb [ green:int # green 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 def fg_from_index [ 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 def bg_from_index [ idx:int # index value 0-255 ] { - echo [(ansi -e '48;5;') $idx 'm'] | str collect + $"(ansi -e '48;5;')($idx)m" } \ No newline at end of file diff --git a/stdlib_candidate/print.nu b/stdlib_candidate/print.nu index e571728..bb22fec 100644 --- a/stdlib_candidate/print.nu +++ b/stdlib_candidate/print.nu @@ -5,18 +5,18 @@ def print [ ...rest # All of the parameters ] { let is_empty = ($separator | empty?) - let num_of_rest = (echo $rest | length) - echo $rest | each --numbered { + let num_of_rest = ($rest | length) + $rest | each --numbered { |param| if $is_empty { - build-string $it.item + $param.item } { - if $num_of_rest > ($it.index + 1) { - build-string $it.item $separator + if $num_of_rest > ($param.index + 1) { + $"($param.item)($separator)" } { - build-string $it.item + $param.item } } - } | str collect + } | into string | str collect } # > print 1 2 3 "four" -s '--' @@ -33,11 +33,11 @@ def print2 [ ...rest # All of the parameters ] { let is_empty = ($separator | empty?) - let num_of_rest = (echo $rest | length) + let num_of_rest = ($rest | length) 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 ] { let sep_empty = ($separator | empty?) - let num_of_rest = (echo $rest | length) + let num_of_rest = ($rest | length) let flat = ($flat | empty?) - echo $rest | each --numbered { + $rest | each --numbered { |param| if $sep_empty { #log 'sep is empty' - if (echo $it.item | length) > 1 && $flat { + if (echo $param.item | length) > 1 && $flat { #log 'flatten please' - let flatter = (echo $it.item | flatten | str from | str collect) - build-string $flatter + let flatter = ($param.item | flatten | into string | str collect) + $flatter } { #log 'no flat' - build-string $it.item + $param.item } } { - if $num_of_rest > ($it.index + 1) { - if (echo $it.item | length) > 1 && $flat { - let flatter = (echo $it.item | flatten | str from | str collect $separator) - build-string $flatter $separator + if $num_of_rest > ($param.index + 1) { + if ($param.item | length) > 1 && $flat { + let flatter = ($param.item | flatten | into string | str collect $separator) + $"($flatter)($separator)" } { - build-string $it.item $separator + $"($param.item)($separator)" } } { - if (echo $it.item | length) > 1 && $flat { - let flatter = (echo $it.item | flatten | str from | str collect $separator) - build-string $flatter + if ($param.item | length) > 1 && $flat { + let flatter = ($param.item | flatten | into string | str collect $separator) + $flatter } { - build-string $it.item + $param.item } } } diff --git a/table_grouping.nu b/table_grouping.nu index d0d3f29..2ab7ac9 100644 --- a/table_grouping.nu +++ b/table_grouping.nu @@ -10,24 +10,27 @@ let table = (echo [ ]) # 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 -build-string '## Nushell' (char nl) (char nl) -echo $table | group-by user_login | pivot user prs | each { - let user_name = $it.user - let pr_count = (echo $it.prs | length) +$"## Nushell(char nl)(char nl)" +$table | group-by user_login | pivot user prs | each { |row| + let user_name = $row.user + let pr_count = (echo $row.prs | length) # only print the comma if there's another item - let user_prs = (echo $it.prs | each -n { - if $pr_count == ($it.index + 1) { - build-string '[' $it.item.title '](' $it.item.url ')' + let user_prs = ($row.prs | each -n { |pr| + if $pr_count == ($pr.index + 1) { + 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) - build-string '- ' $user_name ' created ' $user_prs (char nl) + $"- ($user_name) created ($user_prs) (char nl)" + } | str collect # ╭───┬──────────────────────────────────────────────────────────┬─────────────────┬───────────────────────────────────────────────────────╮ diff --git a/temp.nu b/temp.nu index 30cb43a..d02d04b 100644 --- a/temp.nu +++ b/temp.nu @@ -5,7 +5,7 @@ def "temp f-to-c" [ # (100°F − 32) × 5/9 = 37.778°C let celcius = (($fahren - 32) * 5 / 9) - build-string $fahren ' °F is ' $celcius ' °C' + $"($fahren) °F is ($celcius) °C" } # Convert Fahrenheit to Kelvin @@ -15,7 +15,7 @@ def "temp f-to-k" [ # (100°F − 32) × 5/9 + 273.15 = 310.928K let kelvin = (($fahren - 32) * 5 / 9 + 273.15) - build-string $fahren ' °F is ' $kelvin ' °K' + $"($fahren) °F is ($kelvin) °K" } # Convert Celcius to Fahrenheit @@ -25,7 +25,7 @@ def "temp c-to-f" [ # (100°C × 9/5) + 32 = 212°F let fahren = (($celcius * 9 / 5) + 32) - build-string $celcius ' °C is ' $fahren ' °F' + $"($celcius) °C is ($fahren) °F" } # Convert Celcius to Kelvin @@ -35,7 +35,7 @@ def "temp c-to-k" [ # 100°C + 273.15 = 373.15K let kelvin = ($celcius + 273.15) - build-string $celcius ' °C is ' $kelvin ' °K' + $"($celcius) °C is ($kelvin) °K" } # Convert Kelvin to Fahrenheit @@ -45,7 +45,7 @@ def "temp k-to-f" [ # (100K − 273.15) × 9/5 + 32 = -279.7°F let fahren = (($kelvin - 273.15) * 9 / 5 + 32) - build-string $kelvin ' °K is ' $fahren ' °F' + $"($kelvin) °K is ($fahren) °F" } # Convert Kelvin to Celcius @@ -55,18 +55,18 @@ def "temp k-to-c" [ # 100K − 273.15 = -173.1°C let celcius = ($kelvin - 273.15) - build-string $kelvin ' °K is ' $celcius ' °C' + $"($kelvin) °K is ($celcius) °C" } temp f-to-c 100 -echo (char nl) +char nl temp f-to-k 100 -echo (char nl) +char nl temp c-to-f 100 -echo (char nl) +char nl temp c-to-k 100 -echo (char nl) +char nl temp k-to-f 100 -echo (char nl) +char nl temp k-to-c 100 -echo (char nl) +char nl