diff --git a/coloring/24bit-1.nu b/coloring/24bit-1.nu index b2b1e8c..e3888ac 100644 --- a/coloring/24bit-1.nu +++ b/coloring/24bit-1.nu @@ -1,15 +1,16 @@ -let term_cols = $(= $(term size -w) - 1) +let term_cols = ((term size -w) - 1) +# let's itertate through each of the columns of our terminal echo 0..$term_cols | -each { - let r = $(= 255 - ($it * 255 / $term_cols) | math round) - let g = $(= $it * 510 / $term_cols | math round) - let b = $(= $it * 255 / $term_cols | math round) +each { |col| + let r = (255 - ($col * 255 / $term_cols) | math round) + let g = ($col * 510 / $term_cols | math round) + let b = ($col * 255 / $term_cols | math round) if $g > 255 { - let g = $(= 510 - $g) - echo $(build-colorstr $r $g $b) | autoview + let g = (510 - $g) + build-colorstr $r $g $b $col | autoview } { - echo $(build-colorstr $r $g $b) | autoview + build-colorstr $r $g $b $col | autoview } } @@ -17,23 +18,23 @@ def build-colorstr [ r:int # Red g:int # Green b:int # Blue + c:int # Column ] { - # log $(build-string "R=" $r " G=" $g " B=" $b) - let bg = $(build-string $(ansi rgb_bg) $r ';' $g ';' $b 'm') - let fg = $(build-string $(ansi rgb_fg) $(= 255 - $r) ';' $(= 255 - $g) ';' $(= 255 - $b) 'm') - let idx = $(= $it mod 2) - let slash_str = $(if $idx == 0 { - build-string "/" $(ansi reset) + # Heavy use of string interpolation below + let bg = $"(ansi rgb_bg)($r);($g);($b)m" + let fg = $"(ansi rgb_fg)(255 - $r);(255 - $g);(255 - $b)m" + let idx = ($c mod 2) + let slash_str = (if $idx == 0 { + $"/(ansi reset)" } { - build-string "\" $(ansi reset) + $"\(ansi reset)" }) - build-string $bg $fg $slash_str - # log $(build-string $bg $fg $slash_str | debug) + $"($bg)($fg)($slash_str)" } # This is a first attempt and some type of logging def log [message:any] { - let now = $(date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $(build-string $now '|DBG|' $message $(char newline)) + let now = (date now | date format '%Y%m%d_%H%M%S.%f') + let mess = $"($now)|DBG|($message)(char nl)" echo $mess | autoview } \ No newline at end of file diff --git a/coloring/color_table.nu b/coloring/color_table.nu index 8d541b5..0fae41c 100644 --- a/coloring/color_table.nu +++ b/coloring/color_table.nu @@ -1,24 +1,24 @@ def make_header [hi] { if $hi == $true { - let ansi100m = $(echo '100m' | str lpad -l 11 -c ' ') - let ansi101m = $(echo '101m' | str lpad -l 9 -c ' ') - let ansi102m = $(echo '102m' | str lpad -l 9 -c ' ') - let ansi103m = $(echo '103m' | str lpad -l 9 -c ' ') - let ansi104m = $(echo '104m' | str lpad -l 9 -c ' ') - let ansi105m = $(echo '105m' | str lpad -l 9 -c ' ') - let ansi106m = $(echo '106m' | str lpad -l 9 -c ' ') - let ansi107m = $(echo '107m' | str lpad -l 9 -c ' ') - echo [$(char newline) $ansi100m $ansi101m $ansi102m $ansi103m $ansi104m $ansi105m $ansi106m $ansi107m $(char newline)] | str collect + let ansi100m = ('100m' | str lpad -l 11 -c ' ') + let ansi101m = ('101m' | str lpad -l 9 -c ' ') + let ansi102m = ('102m' | str lpad -l 9 -c ' ') + let ansi103m = ('103m' | str lpad -l 9 -c ' ') + let ansi104m = ('104m' | str lpad -l 9 -c ' ') + let ansi105m = ('105m' | str lpad -l 9 -c ' ') + let ansi106m = ('106m' | str lpad -l 9 -c ' ') + let ansi107m = ('107m' | str lpad -l 9 -c ' ') + $"(char newline)($ansi100m)($ansi101m)($ansi102m)($ansi103m)($ansi104m)($ansi105m)($ansi106m)($ansi107m)(char newline)" } { - let ansi40m = $(echo '40m' | str lpad -l 10 -c ' ') - let ansi41m = $(echo '41m' | str lpad -l 8 -c ' ') - let ansi42m = $(echo '42m' | str lpad -l 8 -c ' ') - let ansi43m = $(echo '43m' | str lpad -l 8 -c ' ') - let ansi44m = $(echo '44m' | str lpad -l 8 -c ' ') - let ansi45m = $(echo '45m' | str lpad -l 8 -c ' ') - let ansi46m = $(echo '46m' | str lpad -l 8 -c ' ') - let ansi47m = $(echo '47m' | str lpad -l 8 -c ' ') - echo [$(char newline) $ansi40m $ansi41m $ansi42m $ansi43m $ansi44m $ansi45m $ansi46m $ansi47m $(char newline)] | str collect + let ansi40m = ('40m' | str lpad -l 10 -c ' ') + let ansi41m = ('41m' | str lpad -l 8 -c ' ') + let ansi42m = ('42m' | str lpad -l 8 -c ' ') + let ansi43m = ('43m' | str lpad -l 8 -c ' ') + let ansi44m = ('44m' | str lpad -l 8 -c ' ') + let ansi45m = ('45m' | str lpad -l 8 -c ' ') + let ansi46m = ('46m' | str lpad -l 8 -c ' ') + let ansi47m = ('47m' | str lpad -l 8 -c ' ') + $"(char newline)($ansi40m)($ansi41m)($ansi42m)($ansi43m)($ansi44m)($ansi45m)($ansi46m)($ansi47m)(char newline)" } } @@ -27,58 +27,54 @@ def make_header [hi] { # mk_header is more convoluted but less repetitive def mk_header [color_range:range] { - let min_rng = $(echo $color_range | math min) + let min_rng = (echo $color_range | math min) let hi_start_pad = 11 let hi_regular_pad = 9 let lo_start_pad = 10 let lo_regular_pad = 8 - echo $color_range | each { - let ansi_color = $(echo [$(build-string $it 'm')]) - if $it == $min_rng { + echo $color_range | each { |color| + let ansi_color = $"($color)m" + if $color == $min_rng { if $min_rng == 100 { - let header = $(echo $ansi_color | str lpad -l $hi_start_pad -c ' ') - echo $header + ($ansi_color | str lpad -l $hi_start_pad -c ' ') } { - let header = $(echo $ansi_color | str lpad -l $lo_start_pad -c ' ') - echo $header + ($ansi_color | str lpad -l $lo_start_pad -c ' ') } } { if $min_rng >= 100 { - let header = $(echo $ansi_color | str lpad -l $hi_regular_pad -c ' ') - echo $header + ($ansi_color | str lpad -l $hi_regular_pad -c ' ') } { - let header = $(echo $ansi_color | str lpad -l $lo_regular_pad -c ' ') - echo $header + ($ansi_color | str lpad -l $lo_regular_pad -c ' ') } } } | str collect - echo $(char newline) + echo (char newline) } def color_row_range [num:int bg_rg:range] { - let reset = $(ansi reset) - let row_header = $(build-string $num "m " $(ansi reset)) - let row_data = $(echo $bg_rg | each { - let row_name = $(echo [$(build-string $num ';' $it) "m"] | str collect) - let ansi_color = $(ansi -e $row_name) - echo [$ansi_color ' ' $row_name ' ' $reset] | str collect - } | append $(char newline) | str collect) - echo [$row_header $row_data] | str collect + let reset = (ansi reset) + let row_header = $"($num)m ($reset)" + let row_data = (echo $bg_rg | each { |back| + let row_name = $"($num);($back)m" + let ansi_color = (ansi -e $row_name) + $"($ansi_color) ($row_name) ($reset)" + } | append (char newline) | str collect) + $"($row_header)($row_data)" } def create_color_tables [fg_range:range bg_range:range] { - echo $fg_range | each { - color_row_range $it $bg_range + echo $fg_range | each { |fg| + color_row_range $fg $bg_range } | str collect } def color_table [] { - #make_header $false + # make_header $false mk_header 40..47 create_color_tables 30..37 40..47 # put a line between tables - echo $(char newline) + char newline #make_header $true mk_header 100..107 diff --git a/coloring/color_tables.nu b/coloring/color_tables.nu index cb7779c..fa9f452 100644 --- a/coloring/color_tables.nu +++ b/coloring/color_tables.nu @@ -10,16 +10,13 @@ # done # echo "" -echo 0..8 | each { - let x = $it - let row = $(echo 30..37 | each { - let i = $it - let row = $(echo 40..47 | each { - let a = $it - let color = $(build-string $x ';' $i ';' $a 'm') - echo [$(ansi -e $color) $color $(ansi reset) ' '] +echo 0..8 | each { |style| + let row = (echo 30..37 | each { |fg| + let row = (echo 40..47 | each { |bg| + let color = $"($style);($fg);($bg)m" + $"(ansi -e $color)($color)(ansi reset) " } | str collect) - echo [$row $(char newline)] | str collect + $"($row)(char newline)" } | str collect) - echo [$row $(char newline)] | str collect + $"($row)(char newline)" } | str collect \ No newline at end of file diff --git a/coloring/gradient.nu b/coloring/gradient.nu index af80c64..5ba5a08 100644 --- a/coloring/gradient.nu +++ b/coloring/gradient.nu @@ -1,40 +1,41 @@ # this script will print a blue gradient on the screen +# We can get the terminal width and height now with term size +# but we like to use the script as a benchmark, so let's keep +# it a constant size for now let height = 40 # really need to get the terminal height here let width = 160 # really need to get the terminal width here - +let stamp = 'Nu' seq 0 $height | each { - let row_data = $(seq 0 $width | each { - let fgcolor = $(iter_inc 2 2 $(echo $it | str to-int)) + let row_data = (seq 0 $width | each { |col| + let fgcolor = (iter_inc 2 2 $col) if $fgcolor > 200 && $fgcolor < 210 { - echo [$(ansi -e '48;2;0;0;') $(build-string $fgcolor m) 'Nu' $(ansi -e '0m')] | str collect + $"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')" } { - echo [$(ansi -e '48;2;0;0;') $(build-string $fgcolor m) ' ' $(ansi -e '0m')] | str collect + $"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')" } } | str collect) - echo [$row_data $(char newline)] | str collect | autoview + $"($row_data)(char newline)" | autoview } | str collect def iter_inc [incr mult iter] { - # echo $(build-string $incr + $mult * $iter) | math eval | math round - = $incr + $mult * $iter + $incr + $mult * $iter } -# ╭────┬────────────────────┬──────────────────────────────────────────────────────────────────────────────────────╮ -# │ # │ key │ value │ -# ├────┼────────────────────┼──────────────────────────────────────────────────────────────────────────────────────┤ -# │ 0 │ version │ 0.25.2 │ -# │ 1 │ branch │ main │ -# │ 2 │ short_commit │ d06f457b │ -# │ 3 │ commit_hash │ d06f457b2a7dee3acc71ecd0dc8b6a34afbfc5d8 │ -# │ 4 │ commit_date │ 2021-01-11 22:59:53 │ -# │ 5 │ build_os │ windows-x86_64 │ -# │ 6 │ rust_version │ rustc 1.49.0 (e1884a8e3 2020-12-29) │ -# │ 7 │ rust_channel │ stable (default) │ -# │ 8 │ cargo_version │ cargo 1.49.0 (d00d64df9 2020-12-05) │ -# │ 9 │ pkg_version │ 0.25.2 │ -# │ 10 │ build_time │ 2021-01-12 07:29:22 │ -# │ 11 │ build_rust_channel │ release │ -# │ 12 │ features │ clipboard-cli, ctrlc, default, directories, dirs, git, ichwh, ptree, rich-benchmark, │ -# │ │ │ rustyline, term, trash, uuid, which, zip │ -# ╰────┴────────────────────┴──────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file +# ╭────┬────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮ +# │ # │ key │ value │ +# ├────┼────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ +# │ 0 │ version │ 0.31.1 │ +# │ 1 │ branch │ main │ +# │ 2 │ short_commit │ 751de20f │ +# │ 3 │ commit_hash │ 751de20f938ed200ae6128a30d06a5dd24a4fd33 │ +# │ 4 │ commit_date │ 2021-05-21 02:04:27 │ +# │ 5 │ build_os │ windows-x86_64 │ +# │ 6 │ rust_version │ rustc 1.52.1 (9bc8c42bb 2021-05-09) │ +# │ 7 │ rust_channel │ stable (default) │ +# │ 8 │ cargo_version │ cargo 1.52.0 (69767412a 2021-04-21) │ +# │ 9 │ pkg_version │ 0.31.1 │ +# │ 10 │ build_time │ 2021-05-21 07:20:25 │ +# │ 11 │ build_rust_channel │ release │ +# │ 12 │ features │ clipboard-cli, ctrlc, default, directories, dirs, ptree, rustyline, term, trash, uuid, which, zip │ +# ╰────┴────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────╯ \ No newline at end of file diff --git a/coloring/nu_index_bg.nu b/coloring/nu_index_bg.nu index e2fc7ed..be99e70 100644 --- a/coloring/nu_index_bg.nu +++ b/coloring/nu_index_bg.nu @@ -1,19 +1,15 @@ def show_index_colors [] { let prefix = "48;5;" - let relet_color = "0m" - echo 1..256 | each { - let cr = $(echo $(build-string $it % 16) | math eval) - let color = $(echo [$(ansi -e $prefix) $(build-string $it) 'm'] | str collect) - let padded_number = $(echo $(build-string $it | str lpad -l 3 -c '0')) + echo 1..256 | each { |idx| + let cr = ($"($idx) % 16" | math eval) + let color = $"(ansi -e $prefix)($idx)m" + let padded_number = ($"($idx)" | str lpad -l 3 -c '0') if $cr == 0 { - echo [$color $padded_number ' ' $(ansi -e $relet_color) $(char newline)] + $"($color)($padded_number) (ansi -e 0m)(char newline)" } { - echo [$color $padded_number ' ' $(ansi -e $relet_color)] + $"($color)($padded_number) (ansi -e 0m)" } } | str collect } show_index_colors - -#one-liner -#echo 0..255 | each {echo [$(ansi -e '38;5;') $(build-string $it) 'm' $(build-string $it) ' ']} | str collect \ No newline at end of file diff --git a/coloring/nu_index_fg.nu b/coloring/nu_index_fg.nu index 13e02ef..b69f915 100644 --- a/coloring/nu_index_fg.nu +++ b/coloring/nu_index_fg.nu @@ -1,11 +1,11 @@ def show_index_colors [] { let prefix = "38;5;" - echo 1..256 | each { - let cr = $(echo $(build-string $it % 16) | math eval) + echo 1..256 | each { |fg| + let cr = ($"($fg) % 16" | math eval) if $cr == 0 { - echo [$(ansi -e $prefix) $(build-string $it) 'm' $(build-string $it | str lpad -l 3 -c '0') ' ' $(char newline)] + $"(ansi -e $prefix)($fg)m($fg | into string | str lpad -l 3 -c '0') (char newline)" } { - echo [$(ansi -e $prefix) $(build-string $it) 'm' $(build-string $it | str lpad -l 3 -c '0') ' '] + $"(ansi -e $prefix)($fg)m($fg | into string | str lpad -l 3 -c '0') " } } | str collect } @@ -13,4 +13,4 @@ def show_index_colors [] { show_index_colors #one-liner -#echo 0..255 | each {echo [$(ansi -e '38;5;') $(build-string $it) 'm' $(build-string $it) ' ']} | str collect \ No newline at end of file +#echo 0..255 | each { |fg| echo [(ansi -e '38;5;') ($fg | into string) 'm' ($fg | into string) ' ']} | str collect \ No newline at end of file diff --git a/coloring/nu_index_fg2.nu b/coloring/nu_index_fg2.nu index da43137..d287266 100644 --- a/coloring/nu_index_fg2.nu +++ b/coloring/nu_index_fg2.nu @@ -3,14 +3,15 @@ # different color def show_index_colors [] { let prefix = "38;5;" - echo 1..256 | each { - let cr = $(echo $(build-string $it % 16) | math eval) - let color = $(echo [$(ansi -e $prefix) $(build-string $it) 'm'] | str collect) - let padded_number = $(echo $(build-string $it | str lpad -l 3 -c '0')) + echo 1..256 | each { |idx| + let cr = ($"($idx) % 16" | math eval) + let color = ($"(ansi -e $prefix)($idx)m") + let padded_number = ($"($idx)" | str lpad -l 3 -c '0') + if $cr == 0 { - echo [$color $padded_number ' ' $(char newline)] + $"($color)($padded_number) (char newline)" } { - echo [$color $padded_number ' '] + $"($color)($padded_number) " } } | str collect } @@ -21,4 +22,4 @@ show_index_colors # it all on one line which wraps in # your terminal -#echo 1..256 | each {echo [$(ansi -e '38;5;') $(build-string $it) 'm' $(build-string $it) ' ']} | str collect \ No newline at end of file +#echo 1..256 | each { |idx| echo [(ansi -e '38;5;') (build-string $idx) 'm' (build-string $idx) ' ']} | str collect \ No newline at end of file diff --git a/coloring/python_index_table.nu b/coloring/python_index_table.nu index ff1c27e..ec127a6 100644 --- a/coloring/python_index_table.nu +++ b/coloring/python_index_table.nu @@ -6,34 +6,24 @@ # sys.stdout.write(u"\u001b[38;5;" + code + "m " + code.ljust(4)) # print u"\u001b[0m" - -# Convert anything that's piped into it a string -def 'to str' [] { - each { build-string $it } | str collect -} - # Foreground Colors -echo 0..16 | each { - let i = $it - let row = $(echo 0..16 | each { - let j = $it - let code = $(= $i * 16 + $j) +echo 0..16 | each { |col| + let row = (echo 0..16 | each { |row| + let code = ($col * 16 + $row) if $code < 256 { - echo [$(ansi -e '38;5;') $(echo $code | to str) 'm' $(echo $code | to str | str lpad -l 4 -c ' ')] | str collect + $"(ansi -e '38;5;')($code | into string)m($code | into string | str lpad -l 4 -c ' ')(ansi reset)" } {} # Do nothing in the else } | str collect) - echo [$row $(char newline)] | str collect + $"($row)(char newline)" } | str collect # Background Colors -echo 0..16 | each { - let i = $it - let row = $(echo 0..16 | each { - let j = $it - let code = $(= $i * 16 + $j) +echo 0..16 | each { |col| + let row = (echo 0..16 | each { |row| + let code = ($col * 16 + $row) if $code < 256 { - echo [$(ansi -e '48;5;') $(echo $code | to str) 'm' $(echo $code | to str | str lpad -l 4 -c ' ') $(ansi reset)] | str collect + $"(ansi -e '48;5;')($code | into string)m($code | into string | str lpad -l 4 -c ' ')(ansi reset)" } {} # do nothing in the else } | str collect) - echo [$row $(char newline)] | str collect + $"($row)(char newline)" } | str collect diff --git a/coloring/ref_table.nu b/coloring/ref_table.nu index 045db5e..7e97aca 100644 --- a/coloring/ref_table.nu +++ b/coloring/ref_table.nu @@ -2,32 +2,29 @@ # of background colors using ansi index coloring # This prints the column headers -let nl = $(char newline) -let plus = $(echo [$nl ' + '] | str collect) -let cols = $(seq 0 35 | each { echo $(build-string $it) | str lpad -c ' ' -l 3 } | str collect) -echo [$plus $cols] | str collect +let nl = (char newline) +let plus = $"($nl) + " +let cols = (seq 0 35 | each { |col| $"($col)" | str lpad -c ' ' -l 3 } | str collect) +$"($plus)($cols)" -let ansi_bg = $(ansi -e '48;5;') -let ansi_reset = $(ansi reset) -echo $nl $nl | str collect +let ansi_bg = (ansi -e '48;5;') +let ansi_reset = (ansi reset) +$"($nl)($nl)" # This prints the row headers let row_header = ' 0 ' -let row_data = $(seq 0 15 | each { - echo [$ansi_bg $it 'm' ' ' $ansi_reset ' '] +let row_data = (seq 0 15 | each { |row| + $"($ansi_bg)($row)m ($ansi_reset)" } | str collect) -echo [$row_header $row_data $nl $nl] | str collect +$"($row_header)($row_data)($nl)($nl)" # This is the meat of the script that prints the little squares of color -seq 0 6 | each { - let math_str = $(build-string $it ' * 36 + 16') - let i = $(echo $math_str | math eval) - let row_header = $(echo $i | str from -d 0 | str lpad -c ' ' -l 4) - let row_data = $(seq 0 35 | each { - let math_str2 = $(build-string $i + $it) - let val = $(echo $math_str2 | math eval | str from -d 0) - echo [$ansi_bg $val 'm' ' ' $(ansi -e 'm') ' '] +seq 0 6 | each { |row_idx| + let r = ($"($row_idx) * 36 + 16" | math eval) + let row_header = (echo $r | into string -d 0 | str lpad -c ' ' -l 4) + let row_data = (seq 0 35 | each { |row| + let val = ($"($r + $row)" | math eval | into string -d 0) + $"($ansi_bg)($val)m (ansi -e 'm') " } | str collect) - echo [$row_header ' ' $row_data $nl $nl] | str collect + $"($row_header) ($row_data)($nl)($nl)" } | str collect - diff --git a/coloring/sample.nu b/coloring/sample.nu index 80057c9..c2e5fd2 100644 --- a/coloring/sample.nu +++ b/coloring/sample.nu @@ -1,9 +1,7 @@ # Background Colors -echo 40..47 100..107 49 | each { - let clbg = $it +echo 40..47 100..107 49 | each { |clbg| # Foreground Colors - echo 30..37 90..97 39 | each { - let clfg = $it + echo 30..37 90..97 39 | each { |clfg| # 0 Normal # 1 Bold or increased intensity # 2 Faint or decreased intensity @@ -14,19 +12,14 @@ echo 40..47 100..107 49 | each { # 7 Reverse Video # 8 Conceal (not widely supported) # 9 Strike-through - let row = $(echo 0..9 | each { - let attr = $it - let ansi_str = $(echo [$(make-str $attr) ';' $(make-str $clbg) ';' $(make-str $clfg) 'm'] | str collect) - echo [$(ansi -e $ansi_str) ' ' $ansi_str ' ' $(ansi reset)] | str collect + let row = (echo 0..9 | each { |attr| + let ansi_str = $"($attr);($clbg);($clfg)m" + $"(ansi -e $ansi_str) ($ansi_str) (ansi reset)" } | str collect) - echo [$row $(char newline)] | str collect | autoview + $"($row)(char newline)" | autoview } | str collect } | str collect -def make-str [item] { - echo $item | str from -} - # Bash Script # for clbg in {40..47} {100..107} 49 ; do # #Foreground diff --git a/coloring/short_list.nu b/coloring/short_list.nu index fa6c894..42a8dab 100644 --- a/coloring/short_list.nu +++ b/coloring/short_list.nu @@ -1,7 +1,7 @@ source ../stdlib_candidate/nu_style.nu # # Regular Colors -echo ' Regular Colors' $(char newline) $(char newline) | str collect +$" Regular Colors (char newline) (char newline)" # | Value | Color | # | -------- | ------ | # | \e[0;30m | Black | @@ -12,20 +12,20 @@ echo ' Regular Colors' $(char newline) $(char newline) | str collect # | \e[0;35m | Purple | # | \e[0;36m | Cyan | # | \e[0;37m | White | -echo '| Value | Color | Name |' $(char newline) | str collect -echo '| ----- | ----- | --------- |' $(char newline) | str collect -echo '|' $(fg_black) ' 0;30m ' $(relet) '| ' Black ' | fg_black |' $(char newline) | str collect -echo '|' $(fg_red) ' 0;31m ' $(relet) '| ' Red ' | fg_red |' $(char newline) | str collect -echo '|' $(fg_green) ' 0;32m ' $(relet) '| ' Green ' | fg_green |' $(char newline) | str collect -echo '|' $(fg_yellow) ' 0;33m ' $(relet) '| ' Yellow ' | fg_yellow |' $(char newline) | str collect -echo '|' $(fg_blue) ' 0;34m ' $(relet) '| ' Blue ' | fg_blue |' $(char newline) | str collect -echo '|' $(fg_purple) ' 0;35m ' $(relet) '| ' Purple ' | fg_purple |' $(char newline) | str collect -echo '|' $(fg_cyan) ' 0;36m ' $(relet) '| ' Cyan ' | fg_cyan |' $(char newline) | str collect -echo '|' $(fg_white) ' 0;37m ' $(relet) '| ' White ' | fg_white |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | Name | (char newline)" +$"| ----- | ----- | --------- | (char newline)" +$"| (fg_black)0;30m(relet) | Black | fg_black | (char newline)" +$"| (fg_red)0;31m(relet) | Red | fg_red | (char newline)" +$"| (fg_green)0;32m(relet) | Green | fg_green | (char newline)" +$"| (fg_yellow)0;33m(relet) | Yellow | fg_yellow | (char newline)" +$"| (fg_blue)0;34m(relet) | Blue | fg_blue | (char newline)" +$"| (fg_purple)0;35m(relet) | Purple | fg_purple | (char newline)" +$"| (fg_cyan)0;36m(relet) | Cyan | fg_cyan | (char newline)" +$"| (fg_white)0;37m(relet) | White | fg_white | (char newline)" +char newline # # Bold -echo ' Bold Colors' $(char newline) $(char newline) | str collect +$" Bold Colors (char newline) (char newline)" # | Value | Color | # | -------- | -------- | @@ -38,20 +38,20 @@ echo ' Bold Colors' $(char newline) $(char newline) | str collect # | \e[1;36m | Cyan | # | \e[1;37m | White | # | \e[1m | No Color | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(fg_black) $(bold_on) ' 1;30m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(fg_red) $(bold_on) ' 1;31m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(fg_green) $(bold_on) ' 1;32m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(fg_yellow) $(bold_on) ' 1;33m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(fg_blue) $(bold_on) ' 1;34m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(fg_purple) $(bold_on) ' 1;35m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(fg_cyan) $(bold_on) ' 1;36m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(fg_white) $(bold_on) ' 1;37m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (fg_black)(bold_on)1;30m(relet) | Black | (char newline)" +$"| (fg_red)(bold_on)1;31m(relet) | Red | (char newline)" +$"| (fg_green)(bold_on)1;32m(relet) | Green | (char newline)" +$"| (fg_yellow)(bold_on)1;33m(relet) | Yellow | (char newline)" +$"| (fg_blue)(bold_on)1;34m(relet) | Blue | (char newline)" +$"| (fg_purple)(bold_on)1;35m(relet) | Purple | (char newline)" +$"| (fg_cyan)(bold_on)1;36m(relet) | Cyan | (char newline)" +$"| (fg_white)(bold_on)1;37m(relet) | White | (char newline)" +char newline # # Underline -echo ' Underline Colors' $(char newline) $(char newline) | str collect +$" Underline Colors (char newline) (char newline)" # | Value | Color | # | -------- | -------- | @@ -64,20 +64,20 @@ echo ' Underline Colors' $(char newline) $(char newline) | str collect # | \e[4;36m | Cyan | # | \e[4;37m | White | # | \e[4m | No Color | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(fg_black) $(underline_on) ' 4;30m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(fg_red) $(underline_on) ' 4;31m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(fg_green) $(underline_on) ' 4;32m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(fg_yellow) $(underline_on) ' 4;33m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(fg_blue) $(underline_on) ' 4;34m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(fg_purple) $(underline_on) ' 4;35m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(fg_cyan) $(underline_on) ' 4;36m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(fg_white) $(underline_on) ' 4;37m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (fg_black)(underline_on)4;30m(relet) | Black | (char newline)" +$"| (fg_red)(underline_on)4;31m(relet) | Red | (char newline)" +$"| (fg_green)(underline_on)4;32m(relet) | Green | (char newline)" +$"| (fg_yellow)(underline_on)4;33m(relet) | Yellow | (char newline)" +$"| (fg_blue)(underline_on)4;34m(relet) | Blue | (char newline)" +$"| (fg_purple)(underline_on)4;35m(relet) | Purple | (char newline)" +$"| (fg_cyan)(underline_on)4;36m(relet) | Cyan | (char newline)" +$"| (fg_white)(underline_on)4;37m(relet) | White | (char newline)" +char newline # # Background -echo ' Background Colors' $(char newline) $(char newline) | str collect +$" Background Colors (char newline) (char newline)" # | Value | Color | # | ------ | ------ | @@ -89,17 +89,17 @@ echo ' Background Colors' $(char newline) $(char newline) | str collect # | \e[45m | Purple | # | \e[46m | Cyan | # | \e[47m | White | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(bg_black) ' 0;40m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(bg_red) ' 0;41m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(bg_green) ' 0;42m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(bg_yellow) ' 0;43m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(bg_blue) ' 0;44m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(bg_purple) ' 0;45m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(bg_cyan) ' 0;46m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(bg_white) ' 0;47m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (bg_black)0;40m(relet)| Black | (char newline)" +$"| (bg_red)0;41m(relet)| Red | (char newline)" +$"| (bg_green)0;42m(relet)| Green | (char newline)" +$"| (bg_yellow)0;43m(relet)| Yellow | (char newline)" +$"| (bg_blue)0;44m(relet)| Blue | (char newline)" +$"| (bg_purple)0;45m(relet)| Purple | (char newline)" +$"| (bg_cyan)0;46m(relet)| Cyan | (char newline)" +$"| (bg_white)0;47m(relet)| White | (char newline)" +char newline # # Expand Background Horizontally @@ -108,7 +108,7 @@ echo $(char newline) # | \e[K | No Color | # # High Intensty -echo ' High Intensity' $(char newline) $(char newline) | str collect +$" High Intensity (char newline) (char newline)" # | Value | Color | # | -------- | ------ | @@ -120,20 +120,20 @@ echo ' High Intensity' $(char newline) $(char newline) | str collect # | \e[0;95m | Purple | # | \e[0;96m | Cyan | # | \e[0;97m | White | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(fg_light_black) ' 0;90m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(fg_light_red) ' 0;91m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(fg_light_green) ' 0;92m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(fg_light_yellow) ' 0;93m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(fg_light_blue) ' 0;94m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(fg_light_purple) ' 0;95m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(fg_light_cyan) ' 0;96m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(fg_light_white) ' 0;97m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (fg_light_black)0;90m(relet) | Black | (char newline)" +$"| (fg_light_red)0;91m(relet) | Red | (char newline)" +$"| (fg_light_green)0;92m(relet) | Green | (char newline)" +$"| (fg_light_yellow)0;93m(relet) | Yellow | (char newline)" +$"| (fg_light_blue)0;94m(relet) | Blue | (char newline)" +$"| (fg_light_purple)0;95m(relet) | Purple | (char newline)" +$"| (fg_light_cyan)0;96m(relet) | Cyan | (char newline)" +$"| (fg_light_white)0;97m(relet) | White | (char newline)" +char newline # # Bold High Intensty -echo ' Bold High Intensity' $(char newline) $(char newline) | str collect +$" Bold High Intensity (char newline) (char newline)" # | Value | Color | # | -------- | ------ | @@ -145,20 +145,20 @@ echo ' Bold High Intensity' $(char newline) $(char newline) | str collect # | \e[1;95m | Purple | # | \e[1;96m | Cyan | # | \e[1;97m | White | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(fg_light_black) $(bold_on) ' 1;90m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(fg_light_red) $(bold_on) ' 1;91m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(fg_light_green) $(bold_on) ' 1;92m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(fg_light_yellow) $(bold_on) ' 1;93m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(fg_light_blue) $(bold_on) ' 1;94m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(fg_light_purple) $(bold_on) ' 1;95m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(fg_light_cyan) $(bold_on) ' 1;96m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(fg_light_white) $(bold_on) ' 1;97m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (fg_light_black)(bold_on)1;90m(relet) | Black | (char newline)" +$"| (fg_light_red)(bold_on)1;91m(relet) | Red | (char newline)" +$"| (fg_light_green)(bold_on)1;92m(relet) | Green | (char newline)" +$"| (fg_light_yellow)(bold_on)1;93m(relet) | Yellow | (char newline)" +$"| (fg_light_blue)(bold_on)1;94m(relet) | Blue | (char newline)" +$"| (fg_light_purple)(bold_on)1;95m(relet) | Purple | (char newline)" +$"| (fg_light_cyan)(bold_on)1;96m(relet) | Cyan | (char newline)" +$"| (fg_light_white)(bold_on)1;97m(relet) | White | (char newline)" +char newline # # High Intensty backgrounds -echo ' High Intensity backgrounds' $(char newline) $(char newline) | str collect +$" High Intensity backgrounds (char newline) (char newline)" # | Value | Color | # | --------- | ------ | @@ -170,17 +170,17 @@ echo ' High Intensity backgrounds' $(char newline) $(char newline) | str collect # | \e[0;105m | Purple | # | \e[0;106m | Cyan | # | \e[0;107m | White | -echo '| Value | Color |' $(char newline) | str collect -echo '| ----- | ----- |' $(char newline) | str collect -echo '|' $(bg_light_black) ' 0;100m ' $(relet) '| ' Black ' |' $(char newline) | str collect -echo '|' $(bg_light_red) ' 0;101m ' $(relet) '| ' Red ' |' $(char newline) | str collect -echo '|' $(bg_light_green) ' 0;102m ' $(relet) '| ' Green ' |' $(char newline) | str collect -echo '|' $(bg_light_yellow) ' 0;103m ' $(relet) '| ' Yellow ' |' $(char newline) | str collect -echo '|' $(bg_light_blue) ' 0;104m ' $(relet) '| ' Blue ' |' $(char newline) | str collect -echo '|' $(bg_light_purple) ' 0;105m ' $(relet) '| ' Purple ' |' $(char newline) | str collect -echo '|' $(bg_light_cyan) ' 0;106m ' $(relet) '| ' Cyan ' |' $(char newline) | str collect -echo '|' $(bg_light_white) ' 0;107m ' $(relet) '| ' White ' |' $(char newline) | str collect -echo $(char newline) +$"| Value | Color | (char newline)" +$"| ----- | ----- | (char newline)" +$"| (bg_light_black)0;100m(relet) | Black | (char newline)" +$"| (bg_light_red)0;101m(relet) | Red | (char newline)" +$"| (bg_light_green)0;102m(relet) | Green | (char newline)" +$"| (bg_light_yellow)0;103m(relet) | Yellow | (char newline)" +$"| (bg_light_blue)0;104m(relet) | Blue | (char newline)" +$"| (bg_light_purple)0;105m(relet) | Purple | (char newline)" +$"| (bg_light_cyan)0;106m(relet) | Cyan | (char newline)" +$"| (bg_light_white)0;107m(relet) | White | (char newline)" +char newline # # Reset diff --git a/duplicates/duplicates.nu b/duplicates/duplicates.nu index 1b92bb4..0eb16ba 100644 --- a/duplicates/duplicates.nu +++ b/duplicates/duplicates.nu @@ -5,10 +5,10 @@ def duplicates [ ] { group-by $column | pivot | - insert count { = $it.Column1 | flatten | length } | + insert count { $it.Column1 | flatten | length } | where count > 1 | reject Column0 | - if $(= $count | empty?) { reject count } { each {= $it } } | + if ($count | empty?) { reject count } { each { $it } } | flatten | flatten } diff --git a/fehbg.nu b/fehbg.nu index a61711c..c788c19 100755 --- a/fehbg.nu +++ b/fehbg.nu @@ -20,13 +20,13 @@ # xinitrc. # # Dependencies; -# * nu version >0.25.1 (0.25.1 doesn't work due to coercion error bug) +# * nu version >=0.32.0 (requires new syntax introduced in 0.32.0) # * feh # * imagemagick # Path definitions let img_dir = $nu.env.WALLPAPER_DIR -let tmp_image = $(build-string $nu.env.TMP_DIR "/wallpaper.jpg") +let tmp_image = (echo [ $nu.env.TMP_DIR "wallpaper.jpg" ] | path join) # Monitor resolution let resolution_y = 1440 @@ -40,7 +40,7 @@ def select_random [] { shuffle | first } # List all images in a directory and all its subdirectories def list_images [dir] { - ls $(build-string $dir /**/*) | where type == File | where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff + ls (build-string $dir /**/*) | where type == File | where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff } # Set the caption text (just filename for now) @@ -50,15 +50,15 @@ def caption [img_f] { # Build the argument for the '-draw' command of the 'convert' utility def draw_str [img_f] { - build-string 'text ' $pos_x ',' $pos_y ' "' $(caption $img_f) '" ' + build-string 'text ' $pos_x ',' $pos_y ' "' (caption $img_f) '" ' } # Select random image -let img_name = $(list_images $img_dir | select_random | get name) +let img_name = (list_images $img_dir | select_random | get name) # Resize the image to the monitor height, draw the caption and save it -let res_str = $(build-string 'x' $resolution_y) -convert -resize $res_str -pointsize 15 -fill "rgb(255,200,150)" -draw $(draw_str $img_name) $img_name $tmp_image +let res_str = (build-string 'x' $resolution_y) +convert -resize $res_str -pointsize 15 -fill "rgb(255,200,150)" -draw (draw_str $img_name) $img_name $tmp_image # Set the created image as a background feh --no-fehbg --bg-max $tmp_image diff --git a/gen-ts-ext.nu b/gen-ts-ext.nu deleted file mode 100644 index a7ce95c..0000000 --- a/gen-ts-ext.nu +++ /dev/null @@ -1,95 +0,0 @@ -def gen-ts-cmds-begin [] { - # hooray for multi-line strings - build-string "import * as vscode from 'vscode'; - -export function activate(context: vscode.ExtensionContext) { - const keywordsWithSubCommandsProvider = vscode.languages.registerCompletionItemProvider( - 'nushell', - { - provideCompletionItems( - document: vscode.TextDocument, - position: vscode.Position, - token: vscode.CancellationToken, - context: vscode.CompletionContext - ) { - -" -} - -# generate typescript from nushell commands -def gen-ts-cmds [] { - # let cmds = $(help commands | do -i { each { where $it.subcommands == $nothing }} | where description != '' | select name description) - let cmds = $(help commands | where description != '' | select name description) - let updated_cmds = $(echo $cmds | insert camel { build-string $it.name 'Completion' | str camel-case } ) - - let ts = $(echo $updated_cmds | - each { - let line1 = $(build-string " const " $it.camel " = new vscode.CompletionItem('" $it.name "');" $(char newline)) - let line2 = $(build-string " " $it.camel ".commitCharacters = [' '];" $(char newline) $(char newline)) - build-string $line1 $line2 - } | str collect) - - build-string $(echo $ts) $(char nl) " return [ " $(echo $updated_cmds | get camel | str collect ', ') " ];" $(char nl) ' },' $(char nl) ' }' $(char nl) ' );' $(char nl) $(char nl) | str collect -} - -# generate typescript from nushell subcommands -def gen-ts-subs [] { - let cmds = $(help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten) - let updated_cmds = $(echo $cmds | insert camelProvider {build-string $it.base 'SubCommandsProvider' | str camel-case } | insert method {build-string $it.name | str camel-case}) - let subs_count = $(help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten | group-by base | pivot cmd cmd_count | update cmd_count { get cmd_count | length }) - let subs_collection = $(help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten | group-by base | pivot cmd sub_cmds) - - let ts = $(echo $subs_collection | - each { - let preamble = $(get sub_cmds | each --numbered { - # echo `index={{$it.index}} base={{$it.item.base}} sub={{$it.item.sub}}` - let method = $(build-string $it.item.name | str camel-case) - let camel = $(build-string $it.item.base 'SubCommandsProvider' | str camel-case) - if $it.index == 0 { - let line01 = $(build-string " const " $camel " = vscode.languages.registerCompletionItemProvider(" $(char newline)) - let line02 = $(build-string " 'nushell'," $(char nl)) - let line03 = $(build-string " {" $(char nl)) - let line04 = $(build-string " provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {" $(char nl) $(char nl)) - let line05 = $(build-string " const linePrefix = document.lineAt(position).text.substr(0, position.character);" $(char nl)) - let line06 = $(build-string " if (linePrefix.endsWith('" $it.item.base " ')) {" $(char nl) $(char nl)) - let line07 = $(build-string " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" $(char nl)) - let line08 = $(build-string ' ' $method '.detail = "' $it.item.description '";' $(char nl) $(char nl)) - build-string $line01 $line02 $line03 $line04 $line05 $line06 $line07 $line08 - } { - let line07 = $(build-string " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" $(char nl)) - let line08 = $(build-string ' ' $method '.detail = "' $it.item.description '";' $(char nl) $(char nl)) - build-string $line07 $line08 - } - } | str collect) - - let methods = $(echo $it.sub_cmds.name | str camel-case | str collect ', ') - - let line09 = $(build-string " return [" $(char nl)) - let line10 = $(build-string " " $methods $(char nl)) - let line11 = $(build-string " ];" $(char nl)) - let line12 = $(build-string " } else {" $(char nl)) - let line13 = $(build-string " return undefined;" $(char nl)) - let line14 = $(build-string " }" $(char nl)) - let line15 = $(build-string " }" $(char nl)) - let line16 = $(build-string " }," $(char nl)) - let line17 = $(build-string " ' '" $(char nl)) - let line18 = $(build-string " );" $(char nl) $(char nl)) - - build-string $preamble $line09 $line10 $line11 $line12 $line13 $line14 $line15 $line16 $line17 $line18 - } | str collect) - - echo $subs_collection | - let post01 = $(build-string " context.subscriptions.push(" $(char nl)) - let post02 = $(build-string " " $(echo $updated_cmds | get camelProvider | uniq | str collect ', ') $(char nl)) - let post03 = $(build-string " );" $(char nl) "}" $(char nl)) - - build-string $ts $post01 $post02 $post03 -} - -# def log [message:any] { -# let now = $(date now | date format '%Y%m%d_%H%M%S.%f') -# let mess = $(build-string $now '|DBG|' $message $(char newline)) -# echo $mess | autoview -# } - -build-string $(gen-ts-cmds-begin) $(gen-ts-cmds) $(gen-ts-subs) | save extension.ts diff --git a/git/git_branch_cleanup_.nu b/git/git_branch_cleanup_.nu new file mode 100644 index 0000000..b87d7ba --- /dev/null +++ b/git/git_branch_cleanup_.nu @@ -0,0 +1,4 @@ +# Script that remove outdated local branches from a git repo +# More information on this article https://www.techwatching.dev/posts/cleaning-git-branches + +git branch -vl '*/*' | lines | split column " " BranchName Hash Status --collapse-empty | where Status == '[gone]' | each { git branch -D $it.BranchName } \ No newline at end of file diff --git a/lint_directories.nu b/lint_directories.nu index 4bd4796..d2efac6 100755 --- a/lint_directories.nu +++ b/lint_directories.nu @@ -5,9 +5,10 @@ def ls-incorrect-dirs [] { ls | where type == 'Dir' && name != 'scripts'| match -v name '(\d+\.){2,}\d$' } -let incorrect_count = $(ls-incorrect-dirs | length); +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/ls_mods/ls-less.nu b/ls_mods/ls-less.nu index 4309718..67d3d64 100644 --- a/ls_mods/ls-less.nu +++ b/ls_mods/ls-less.nu @@ -2,11 +2,11 @@ def ls-less [ --dir(-d):any # The directory you want to list ] { - let is_empty = $(= $dir | empty?) + let is_empty = ($dir | empty?) if $is_empty { nu -c 'ls' | less -r } { - let command = $(build-string 'ls ' $dir) + let command = $"ls ($dir)" nu -c $command | less -r } } \ No newline at end of file diff --git a/ls_mods/ls-wide-with-color.nu b/ls_mods/ls-wide-with-color.nu index 983b534..32f4ae3 100644 --- a/ls_mods/ls-wide-with-color.nu +++ b/ls_mods/ls-wide-with-color.nu @@ -24,49 +24,51 @@ alias fg_light_white = ansi -e '97m' # A ls command that approximates the ls -sh command in bash def ls-wide2 [ + --dir(-d):any # The directory you want to list --columns(-c):int # The number of columns in your output ] { - let is_empty = $(= $columns | empty?) - let ls_data = $(ls) + let is_dir_empty = ($dir | empty?) + let is_columns_empty = ($columns | empty?) + let ls_data = (if $is_dir_empty { ls } { ls $dir }) let ansi_size = 9 # \x1b[36m + string + \x1b[0m, ~9 characters are added to each string for coloring - let max_fname_size = $(= $(echo $ls_data | get name | str from | str length | math max) + $ansi_size) - let max_fsize_size = $(echo $ls_data | get size | str from | str length | math max) - # log $(build-string 'max_fname_size=' $max_fname_size ' max_fsize_size=' $max_fsize_size) - ls | each -n { - let clr_file = $(colorize $it.item.name) - # log $(build-string $clr_file ' ' $max_fname_size) - let clr_size = $(echo $it.item.size | str from) - # log $(build-string $clr_size ' ' $max_fsize_size) - build-string $(echo $clr_file | str rpad -c ' ' -l $max_fname_size) ' ' $(echo $clr_size | str lpad -c ' ' -l $max_fsize_size) ' ' | autoview - if $is_empty { - if $(= $it.index + 1) mod 3 == 0 { - echo $(char newline) | autoview + let max_fname_size = ((echo $ls_data | get name | into string | str length | math max) + $ansi_size) + let max_fsize_size = (echo $ls_data | get size | into string | str length | math max) + # log (build-string 'max_fname_size=' $max_fname_size ' max_fsize_size=' $max_fsize_size) + ($ls_data) | each -n { |file| + let clr_file = (colorize $file.item.name) + # log (build-string $clr_file ' ' $max_fname_size) + let clr_size = (echo $file.item.size | into string) + # log (build-string $clr_size ' ' $max_fsize_size) + $"($clr_file | str rpad -c ' ' -l $max_fname_size) ($clr_size | str lpad -c ' ' -l $max_fsize_size) " | autoview + if $is_columns_empty { + if ($file.index + 1) mod 3 == 0 { + echo (char newline) | autoview } {} } { - if $(= $it.index + 1) mod $columns == 0 { - echo $(char newline) | autoview + if ($file.index + 1) mod $columns == 0 { + echo (char newline) | autoview } {} } } | str collect } def colorize [thing:any] { - let thing_as_string = $(echo $thing | str from) - let ext = $(echo $thing_as_string | path extension) - let is_empty = $(= $ext | empty?) + let thing_as_string = (echo $thing | into string) + let ext = (echo $thing_as_string | path parse | get extension) + let is_empty = ($ext | empty?) if $is_empty { - # build-string $(ansi -e '36m') $thing $(ansi -e '0m') - build-string $(fg_cyan) $thing $(relet) + # build-string (ansi -e '36m') $thing (ansi -e '0m') + $"(fg_cyan)($thing)(relet)" # build-string 'e[36m' $thing 'e[0m' } { if $ext == "nu" { - # build-string $(ansi -e '95m') $thing $(ansi -e '0m') - build-string $(fg_light_magenta) $thing $(relet) + # build-string (ansi -e '95m') $thing (ansi -e '0m') + $"(fg_light_magenta)($thing)(relet)" # build-string 'e[95m' $thing 'e[0m' } { - # build-string $(ansi -e '92m') $thing $(ansi -e '0m') - build-string $(fg_light_green) $thing $(relet) + # build-string (ansi -e '92m') $thing (ansi -e '0m') + $"(fg_light_green)($thing)(relet)" # build-string 'e[92m' $thing 'e[0m' } } @@ -81,17 +83,13 @@ def colorit [] { colorize " file.nu" # These all work - build-string $(fg_light_green) "abc" $(relet) - echo $(fg_cyan) "def" $(relet) | str collect - #echo '|' $(fg_light_green) ' 0;92m ' $(relet) '| ' Green ' |' $(char newline) | str collect + $"(fg_light_green)abc(relet)" + $"(fg_cyan)def(relet)" } # This is a first attempt and some type of logging -def log [ - message:any # Some log message - ] { - let now = $(date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $(build-string $now '|DBG|' $message $(char newline)) +def log [message:any] { + let now = (date now | date format '%Y%m%d_%H%M%S.%f') + let mess = $"($now)|DBG|($message)(char nl)" echo $mess | autoview -} - +} \ No newline at end of file diff --git a/ls_mods/ls-wide.nu b/ls_mods/ls-wide.nu index 1e59429..613c58b 100644 --- a/ls_mods/ls-wide.nu +++ b/ls_mods/ls-wide.nu @@ -3,8 +3,8 @@ def ls-wide [ --path(-p):string # The path you want to list --columns(-c):int # The number of columns in your output ] { - let is_columns_empty = $(= $columns | empty?) - let is_path_empty = $(= $path | empty?) + let is_columns_empty = ($columns | empty?) + let is_path_empty = ($path | empty?) let columns_default = 3 if $is_path_empty { @@ -26,29 +26,29 @@ def run_ls [ path:string columns:int ] { - let max_fname_size = $(ls $path | get name | str from | str length | math max) - let max_fsize_size = $(ls $path | get size | str from | str length | math max) + let max_fname_size = (ls $path | get name | into string | str length | math max) + let max_fsize_size = (ls $path | get size | into string | str length | math max) + + ls $path | each -n { |file| + let the_file = ($file.item.name | into string | str rpad -c ' ' -l $max_fname_size) + let the_size = ($file.item.size | into string | str lpad -c ' ' -l $max_fsize_size) + $"($the_file) ($the_size) " | autoview - ls $path | each -n { - build-string $(echo $it.item.name | str rpad -c ' ' -l $max_fname_size) ' ' $(echo $(build-string $it.item.size) | str lpad -c ' ' -l $max_fsize_size) ' ' if $is_columns_empty { - if $(= $it.index + 1) mod 3 == 0 { - echo $(char newline) | autoview + if ($file.index + 1) mod 3 == 0 { + echo (char newline) | autoview } {} } { - if $(= $it.index + 1) mod $columns == 0 { - echo $(char newline) | autoview + if ($file.index + 1) mod $columns == 0 { + echo (char newline) | autoview } {} } } | str collect } # This is a first attempt and some type of logging -def log [ - message:any # Some log message - ] { - let now = $(date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $(build-string $now '|DBG|' $message $(char newline)) +def log [message:any] { + let now = (date now | date format '%Y%m%d_%H%M%S.%f') + let mess = $"($now)|DBG|($message)(char nl)" echo $mess | autoview -} - +} \ No newline at end of file diff --git a/maintainer_time.nu b/maintainer_time.nu index 67a4d33..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' ' ']] +let m_table = ( + [['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' +let now = (date now) +$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 e29eac0..8f713bc 100644 --- a/make_readme_table.nu +++ b/make_readme_table.nu @@ -1,30 +1,32 @@ # A Script to try and create the table for the readme.md file -# | Category | File | Nu Version | Description | -# | ---------------- | --------------------------------------------------------- | ---------- | ----------- | -# | coloring | [color_table.nu](./coloring/color_table.nu) | 0.32 | desc | -# | coloring | [color_tables.nu](./coloring/color_tables.nu) | 0.32 | desc | +# | Category | File | +# | ---------------- | ----------------------------------------------------------------------------- | +# | coloring | [24bit-1.nu](./coloring\24bit-1.nu) | +# | coloring | [color_table.nu](./coloring\color_table.nu) | +# | coloring | [color_tables.nu](./coloring\color_tables.nu) | +# | coloring | [gradient.nu](./coloring\gradient.nu) | # Right now there is still manual manipulation in order to update the README.md # Hopefully, in the future someone will contribute a script to make this automatic. let nu_files = (ls **/*.nu) -let nu_table = ($nu_files | +let nu_table = ($nu_files | get name | - wrap File | - insert 'Nu Version' 0.32 | - insert Description desc | - insert Category { |it| + wrap File | + insert Category { |it| let cat = ($it.File | path dirname) if $cat == "" { "not assigned yet" } { $cat } - } | select Category File 'Nu Version' Description) + } | where Category !~ ".git" | select Category File | sort-by Category) + # Let's fix the file now let nu_table = ($nu_table | update File { |it| - let file_path = $it.File + let file_path = ($it.File | into string | str find-replace '\\' '/') let file_name = ($file_path | path basename) $"[($file_name)](char lparen)./($file_path)(char rparen)" }) -$nu_table | to md --pretty + +echo $nu_table | to md --pretty diff --git a/make_release/gen-ts-ext.nu b/make_release/gen-ts-ext.nu new file mode 100644 index 0000000..b617e21 --- /dev/null +++ b/make_release/gen-ts-ext.nu @@ -0,0 +1,94 @@ +def gen-ts-cmds-begin [] { + # hooray for multi-line strings + build-string "import * as vscode from 'vscode'; +export function activate(context: vscode.ExtensionContext) { + const keywordsWithSubCommandsProvider = vscode.languages.registerCompletionItemProvider( + 'nushell', + { + provideCompletionItems( + document: vscode.TextDocument, + position: vscode.Position, + token: vscode.CancellationToken, + context: vscode.CompletionContext + ) { +" +} + +# generate typescript from nushell commands +def gen-ts-cmds [] { + # let cmds = (help commands | do -i { each { where $it.subcommands == $nothing }} | where description != '' | select name description) + let cmds = (help commands | where description != '' | select name description) + let updated_cmds = (echo $cmds | insert camel { build-string $it.name 'Completion' | str camel-case } ) + + let ts = (echo $updated_cmds | + each { + let line1 = (build-string " const " $it.camel " = new vscode.CompletionItem('" $it.name "');" (char newline)) + let line2 = (build-string " " $it.camel ".commitCharacters = [' '];" (char newline) (char newline)) + $line1 + $line2 + } | str collect) + + build-string (echo $ts) (char nl) " return [ " (echo $updated_cmds | get camel | str collect ', ') " ];" (char nl) ' },' (char nl) ' }' (char nl) ' );' (char nl) (char nl) | str collect +} + +# generate typescript from nushell subcommands +def gen-ts-subs [] { + let cmds = (help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten) + let updated_cmds = (echo $cmds | insert camelProvider {build-string $it.base 'SubCommandsProvider' | str camel-case } | insert method {build-string $it.name | str camel-case}) + let subs_count = (help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten | group-by base | pivot cmd cmd_count | update cmd_count { get cmd_count | length }) + let subs_collection = (help commands | get subcommands | insert base { get name | split column ' ' base sub} | flatten | group-by base | pivot cmd sub_cmds) + + let ts = (echo $subs_collection | + each { + let preamble = (get sub_cmds | each --numbered { + let method = (build-string $it.item.name | str camel-case) + let camel = (build-string $it.item.base 'SubCommandsProvider' | str camel-case) + if $it.index == 0 { + let line01 = (build-string " const " $camel " = vscode.languages.registerCompletionItemProvider(" (char newline)) + let line02 = (build-string " 'nushell'," (char nl)) + let line03 = (build-string " {" (char nl)) + let line04 = (build-string " provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {" (char nl) (char nl)) + let line05 = (build-string " const linePrefix = document.lineAt(position).text.substr(0, position.character);" (char nl)) + let line06 = (build-string " if (linePrefix.endsWith('" $it.item.base " ')) {" (char nl) (char nl)) + let line07 = (build-string " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" (char nl)) + let line08 = (build-string ' ' $method '.detail = "' $it.item.description '";' (char nl) (char nl)) + $line01 + $line02 + $line03 + $line04 + $line05 + $line06 + $line07 + $line08 + } { + let line07 = (build-string " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" (char nl)) + let line08 = (build-string ' ' $method '.detail = "' $it.item.description '";' (char nl) (char nl)) + $line07 + $line08 + } + } | str collect) + + let methods = (echo $it.sub_cmds.name | str camel-case | str collect ', ') + + let lines = $" + return [ + ($methods) + ]; + } else { + return undefined; + } + } + }, + ' ' + ); + " + + build-string $preamble $lines + } | str collect) + + echo $subs_collection | + let post01 = (build-string " context.subscriptions.push(" (char nl)) + let post02 = (build-string " " (echo $updated_cmds | get camelProvider | uniq | str collect ', ') (char nl)) + let post03 = (build-string " );" (char nl) "}" (char nl)) + + build-string $ts $post01 $post02 $post03 +} + +# def log [message:any] { +# let now = (date now | date format '%Y%m%d_%H%M%S.%f') +# let mess = (build-string $now '|DBG|' $message (char newline)) +# echo $mess | autoview +# } + +build-string (gen-ts-cmds-begin) (gen-ts-cmds) (gen-ts-subs) | save extension.ts \ No newline at end of file diff --git a/nu_release.nu b/make_release/nu_release.nu similarity index 100% rename from nu_release.nu rename to make_release/nu_release.nu diff --git a/make_release/this_week_in_nu_release.nu b/make_release/this_week_in_nu_release.nu new file mode 100644 index 0000000..39a1237 --- /dev/null +++ b/make_release/this_week_in_nu_release.nu @@ -0,0 +1,59 @@ +# fetch https://api.github.com/repos/nushell/nushell/pulls?q=is%3Apr+merged%3A%3E%3D2021-04-20+ | select html_url user.login title body +# fetch https://api.github.com/search/issues?q=repo:nushell/nushell+is:pr+is:merged+merged:%3E2021-05-08 | get items | select html_url user.login title body +# Repos to monitor + +def do-work [] { + let site_table = [ + [site repo + ]; [Nushell nushell + ] [Extension vscode-nushell-lang + ] [Documentation nushell.github.io + ] [Wasm demo + ] [Nu_Scripts nu_scripts + ] [RFCs rfcs] + # ] [Jupyter jupyter] + ] + + let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/" + let query_date = (seq date --days 7 -r | last) + let query_suffix = $"+is:pr+is:merged+merged:%3E%3D($query_date)" + + let entries = ($site_table | each { + let query_string = $"($query_prefix)($it.repo)($query_suffix)" + let site_json = (fetch $query_string | get items | select html_url user.login title body) + $"## ($it.site)(char nl)(char nl)" + if ($site_json | all? ($it | empty?)) { + $"none found this week(char nl)(char nl)" + } { + $site_json | group-by user_login | pivot user prs | each { |row| + let user_name = $row.user + let pr_count = ($row.prs | length) + + # only print the comma if there's another item + let user_prs = ($row.prs | each -n { |pr| + if $pr_count == ($pr.index + 1) { + $"(char nl)### [($pr.item.title)](char lparen)($pr.item.html_url)(char rparen)(char nl)(char nl)($pr.item.body)(char nl)" + } { + $"(char nl)### [($pr.item.title)](char lparen)($pr.item.html_url)(char rparen)(char nl)(char nl)($pr.item.body)(char nl) and (char nl)" + } + } | str collect) + + $"### **($user_name)**(char nl)(char nl)---(char nl)($user_prs)(char nl)" + } | str collect + char nl + } + + # We need 2 seconds between fetches or github's api limiting will limit us + sleep 2sec + }) + + if ($entries | all? (echo $it | empty?)) { + } { + $entries | str collect + } +} + +# 2019-08-23 was the release of 0.2.0, the first public release +let week_num = (seq date -b '2019-08-23' -n 7 | length) +$"# This week in Nushell #($week_num)(char nl)(char nl)" +do-work | str collect diff --git a/make_release/this_week_in_nu_weekly.nu b/make_release/this_week_in_nu_weekly.nu new file mode 100644 index 0000000..e7341fb --- /dev/null +++ b/make_release/this_week_in_nu_weekly.nu @@ -0,0 +1,59 @@ +# fetch https://api.github.com/repos/nushell/nushell/pulls?q=is%3Apr+merged%3A%3E%3D2021-04-20+ | select html_url user.login title body +# fetch https://api.github.com/search/issues?q=repo:nushell/nushell+is:pr+is:merged+merged:%3E2021-05-08 | get items | select html_url user.login title body +# Repos to monitor + +def do-work [] { + let site_table = [ + [site repo + ]; [Nushell nushell + ] [Extension vscode-nushell-lang + ] [Documentation nushell.github.io + ] [Wasm demo + ] [Nu_Scripts nu_scripts + ] [RFCs rfcs] + # ] [Jupyter jupyter] + ] + + let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/" + let query_date = (seq date --days 7 -r | last) + let query_suffix = $"+is:pr+is:merged+merged:%3E%3D($query_date)" + + let entries = ($site_table | each { + let query_string = $"($query_prefix)($it.repo)($query_suffix)" + let site_json = (fetch $query_string | get items | select html_url user.login title) + $"## ($it.site)(char nl)(char nl)" + if ($site_json | all? ($it | empty?)) { + $"none found this week(char nl)(char nl)" + } { + $site_json | group-by user_login | pivot user prs | each { |row| + let user_name = $row.user + let pr_count = ($row.prs | length) + + # only print the comma if there's another item + let user_prs = ($row.prs | each -n { |pr| + if $pr_count == ($pr.index + 1) { + $"[($pr.item.title)](char lparen)($pr.item.html_url)(char rparen)" + } { + $"[($pr.item.title)](char lparen)($pr.item.html_url)(char rparen), and " + } + } | str collect) + + $"- ($user_name) created ($user_prs) (char nl)" + } | str collect + char nl + } + + # We need 2 seconds between fetches or github's api limiting will limit us + sleep 2sec + }) + + if ($entries | all? ($it | empty?)) { + } { + $entries | str collect + } +} + +# 2019-08-23 was the release of 0.2.0, the first public release +let week_num = (seq date -b '2019-08-23' -n 7 | length) +$"# This week in Nushell #($week_num)(char nl)(char nl)" +do-work | str collect diff --git a/nu_101/inner_outer_loop.nu b/nu_101/inner_outer_loop.nu index 0b0e0c4..be97228 100644 --- a/nu_101/inner_outer_loop.nu +++ b/nu_101/inner_outer_loop.nu @@ -2,10 +2,10 @@ # $it in and inner loop and an outer loop at # the same time, each having different values -seq 30 39 | each { - let row = $(echo [$it ' '] | str collect) - let data = $(seq 40 49 | each { - echo [$it ' '] | str collect +seq 30 39 | each { |outer| + let row = $"($outer) " + let data = (seq 40 49 | each { |inner| + $"($inner) " } | str collect) - echo [$row $data $(char newline)] | str collect + $"($row)($data)(char newline)" } | str collect \ No newline at end of file diff --git a/nu_101/nothing.nu b/nu_101/nothing.nu index 914d3a3..21b3536 100644 --- a/nu_101/nothing.nu +++ b/nu_101/nothing.nu @@ -14,7 +14,7 @@ def nada [ def nada2 [ --flat(-f) ] { - let flat = $(= $flat | empty?) + let flat = ($flat | empty?) if $flat { echo $true diff --git a/parsing/sample_andres.nu b/parsing/sample_andres.nu index efb44fb..edbb43f 100644 --- a/parsing/sample_andres.nu +++ b/parsing/sample_andres.nu @@ -6,14 +6,13 @@ def look_for [word] { get shoes_name | split row " " | each --numbered { - = [[idx, loc]; [$it.index, $(= $it.item | str index-of $word)]] + [[idx, loc]; [$it.index, ($it.item | str index-of $word)]] } } | flatten | - flatten | where comp.loc >= 0 | flatten | - update idx { = $it.idx + 1 } | + update idx { $it.idx + 1 } | reject name price loc | rename nameWords targetWordIndex } diff --git a/progress_bar/percent_meter.nu b/progress_bar/percent_meter.nu index 2e1e5f3..c336401 100644 --- a/progress_bar/percent_meter.nu +++ b/progress_bar/percent_meter.nu @@ -1,21 +1,20 @@ def loading [] { - echo Loading $(char newline) | str collect | autoview - echo 0..100 | each { + $"Loading (char newline)" | autoview + echo 0..100 | each { |tick| sleep 50ms - #hide_cursor # I believe '1000D' means move the cursor to the left 1000 columns - echo $(ansi -e '1000D') | autoview - echo $(build-string $it '%') | autoview + $"(ansi -e '1000D')" | autoview + $"($tick)%" | autoview } #show_cursor } def show_cursor [] { - echo $(ansi -e '?25h') | autoview + $"(ansi -e '?25h')" | autoview } def hide_cursor [] { - echo $(ansi -e '?25l') | autoview + $"(ansi -e '?25l')" | autoview } hide_cursor diff --git a/progress_bar/progress_bar.nu b/progress_bar/progress_bar.nu index 74d8872..c5f9b5a 100644 --- a/progress_bar/progress_bar.nu +++ b/progress_bar/progress_bar.nu @@ -20,32 +20,31 @@ let blocks = ["▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"] # "▏" #1/8 # Turn off the cursor -echo $(ansi cursor_off) +ansi cursor_off # Move cursor all the way to the left -echo $(ansi -e '1000D') | autoview +$"(ansi -e '1000D')" | autoview # Draw the background for the progress bar -echo $bg_fill | str lpad -c $bg_fill -l $pb_len +$bg_fill | str lpad -c $bg_fill -l $pb_len -echo 1..<$pb_len | each { +echo 1..<$pb_len | each { |cur_progress| # This is kind of a hack because it's not incrementally drawing a new box # It's drawing the entire row every time with a different padding amount # echo $blocks.7 | str lpad -c $blocks.7 -l $it | autoview - let cur_progress = $it - echo 0..7 | each { - let cur_idx = $(= $it mod 8) - let cur_block = $(echo $blocks | nth $cur_idx) - echo $cur_block | str lpad -c $blocks.7 -l $cur_progress | autoview - echo $(ansi -e '1000D') | autoview - sleep 50ms + echo 0..7 | each { |tick| + let cur_idx = ($tick mod 8) + let cur_block = (echo $blocks | nth $cur_idx) + $"($cur_block | str lpad -c $blocks.7 -l $cur_progress)" | autoview + $"(ansi -e '1000D')" | autoview + sleep 5ms } - echo $(ansi -e '1000D') | autoview + $"(ansi -e '1000D')" | autoview } # Fill in the last background block -echo $blocks.7 | str lpad -c $blocks.7 -l $pb_len | autoview -echo $(char newline) -echo "Done" -echo $(ansi cursor_on) +$"($blocks.7 | str lpad -c $blocks.7 -l $pb_len)" | autoview +char newline +"Done" +ansi cursor_on # Try to do this in the next version diff --git a/progress_bar/progress_bar_no_back.nu b/progress_bar/progress_bar_no_back.nu index 48c52bd..43f1ff9 100644 --- a/progress_bar/progress_bar_no_back.nu +++ b/progress_bar/progress_bar_no_back.nu @@ -1,17 +1,16 @@ let blocks = ["▏" "▎" "▍" "▌" "▋" "▊" "▉" "█"] let pb_size = 25 -echo $(ansi cursor_off) -echo 1..<$pb_size | each { - let cur_size = $it - echo 0..7 | each { - let idx = $(= $it mod 8) - let cur_block = $(echo $blocks | nth $idx) - echo $cur_block | str lpad -c $blocks.7 -l $cur_size | autoview - echo $(ansi -e '1000D') | autoview - sleep 50ms +ansi cursor_off +echo 1..<$pb_size | each { |cur_size| + echo 0..7 | each { |tick| + let idx = ($tick mod 8) + let cur_block = (echo $blocks | nth $idx) + $"($cur_block | str lpad -c $blocks.7 -l $cur_size)" | autoview + $"(ansi -e '1000D')" | autoview + sleep 5ms } } -echo $(char newline) -echo 'Done' -echo $(ansi cursor_on) +char newline +'Done' +ansi cursor_on diff --git a/prompt/git_status_prompt.nu b/prompt/git_status_prompt.nu index 7cc0603..654ba72 100644 --- a/prompt/git_status_prompt.nu +++ b/prompt/git_status_prompt.nu @@ -1,38 +1,40 @@ # Displays a prompt def git-status-prompt [] { - build-string $(ansi reset) $(ansi green) $(whoami | str trim) $(ansi reset) @ $(hostname -s | str trim) : $(ansi green_dimmed) $(prompt-pwd) $(ansi reset) $(git-branch-icon) $(ansi reset) $(char newline) '➤ ' + let not_windows = ($nu.path | first | into string | str contains '/') + $"(ansi reset)(ansi green)(if $not_windows {$nu.env.USER} {$nu.env.USERNAME})(ansi reset)@(hostname | str trim):(ansi green_dimmed)(prompt-pwd)(ansi reset)(git-branch-icon)(ansi reset)(char newline)(char prompt) " } # Returns a shortened pwd for use in prompt def prompt-pwd [] { - let path = $(pwd | split row "/") - let home = $(echo $nu.env.HOME | split row "/") + let not_windows = ($nu.path | first | into string | str contains '/') + let path = (pwd | if $not_windows { split row "/" } { split row "\" }) + let home = (if $not_windows { ($nu.env.HOME | split row "/") } { (echo [$nu.env.HOMEDRIVE $nu.env.HOMEPATH] | path join | split row "\") }) - if $(echo $path | count) > 1 { - if $(echo $home | reduce { = $it in $path }) { - let path-without-home = $(echo $path | skip $(echo $home | count)) + if ($path | length) > 1 { + if ($home | reduce { $it in $path }) { + let path-without-home = ($path | skip ($home | length)) - if $(echo $path-without-home | wrap | compact | count) > 0 { - let parent = $(echo $path | skip $(echo $home | count) | drop) + if ($path-without-home | wrap | compact | length) > 0 { + let parent = ($path | skip ($home | length) | drop) - if $(echo $parent | wrap | compact | count) > 0 { - let short-part = $(echo $parent | each { - if $(echo $it | str starts-with ".") { - echo $(echo $it | str substring [0 2]) "/" + if ($parent | wrap | compact | length) > 0 { + let short-part = ($parent | each { |part| + if ($part | str starts-with ".") { + $"($part | str substring [0 2])/" } { - echo $(echo $it | str substring [0 1]) "/" + $"($part | str substring [0 1])/" } }) - echo "~/" $short-part $(echo $path | last) | str collect + $"~/($short-part | str collect)($path | last)" } { - echo "~/" $(echo $path | last) | str collect + $"~/($path | last)" } } { - echo "~" + "~" } } { - let parent = $(echo $path | drop | str substring [0 1] | each { echo $it "/" }) - echo "/" $parent $(echo $path | last) | str collect + let parent = (echo $path | drop | str substring [0 1] | each { echo $it "/" }) + $"/($parent)($path | last)" } } { pwd @@ -43,8 +45,8 @@ def prompt-pwd [] { def git-prompt-map [] { echo a m r c d "??" u | rotate counter-clockwise | - reject Column0 | append $( - echo $(ansi green) $(ansi yellow_bold) $(ansi cyan) $(ansi blue) $(ansi red) $(ansi red_dimmed) $(ansi red) | + reject Column0 | append ( + echo (ansi green) (ansi yellow_bold) (ansi cyan) (ansi blue) (ansi red) (ansi red_dimmed) (ansi red) | rotate counter-clockwise | reject Column0 ) | headers @@ -55,11 +57,11 @@ def git-prompt-icons [k] { let icns = ["✚ " "* " "➜ " "⇒ " "✖ " "? " "! "]; git-prompt-map | - pivot status colour | each --numbered { - let idx = $it.index; + pivot status colour | each --numbered { |icon| + let idx = $icon.index; - if $it.item.status == $k { - build-string $it.item.colour $(echo $icns | nth $idx) + if $icon.item.status == $k { + $"($icon.item.colour)($icns | nth $idx)" } { = $nothing } @@ -69,26 +71,24 @@ def git-prompt-icons [k] { # Checks git status of current working directory and displays an icon def git-branch-icon [] { do -i { - let branch = $(do -i { git rev-parse --abbrev-ref HEAD } | str trim) - - if $(echo $branch | str length) > 0 { - let modified = $(do -i { git status --porcelain } | split row "\n" | str trim | split column " " status file); + let branch = (do -i { git rev-parse --abbrev-ref HEAD } | str trim) - if $(echo $modified | get | first | empty?) { - build-string "|" $(ansi green) $branch $(ansi reset) ":" $(ansi green) '✓' $(ansi reset) + if ($branch | str length) > 0 { + let modified = (do -i { git status --porcelain } | split row "\n" | str trim | split column " " status file); + + if ($modified | get | first | empty?) { + $"|(ansi green)($branch)(ansi reset):(ansi green)✓(ansi reset)" } { - let modified2 = $(do -i { git status --porcelain } | split row "\n" | str substring [0 1]) - let branch-colour = $(if $(echo $modified2 | each { = $it in [A M R C D] } | reduce { = $it || $acc }) { - echo yellow + let modified2 = (do -i { git status --porcelain } | split row "\n" | str substring [0 1]) + let branch-colour = (if (echo $modified2 | each { $it in [A M R C D] } | reduce { $it || $acc }) { + "yellow" } { - echo red + "red" }) - build-string "|" $(ansi $branch-colour) $branch $(ansi reset) ":" $(echo $modified | get status | uniq | str downcase | each { - git-prompt-icons $it - } | str collect) + $"|(ansi $branch-colour)($branch)(ansi reset):($modified | get status | uniq | str downcase | each { git-prompt-icons $it })" | str collect } } { - echo "" + "" } } } diff --git a/prompt/left_and_right_prompt.nu b/prompt/left_and_right_prompt.nu index eccd9e2..57f4aad 100644 --- a/prompt/left_and_right_prompt.nu +++ b/prompt/left_and_right_prompt.nu @@ -1,49 +1,49 @@ # This is a work in progress. Not working yet but you can see where I'm going. def construct_prompt [] { - # let decorator = $(char prompt) - let decorator = $(create_second_line) + # let decorator = (char prompt) + let decorator = (create_second_line) # not using machine name - # let machine_name = $(sys | get host.hostname) + # let machine_name = (sys | get host.hostname) # the current working directory - # let current_dir = $(pwd) - let current_dir = $(home_abbrev) + # let current_dir = (pwd) + let current_dir = (home_abbrev) # the current bit branch - # let git_status = $(git -c core.quotepath=false -c color.status=false status -uall --short --branch) - let git_info = $(do -i { git rev-parse --abbrev-ref HEAD } | str trim | str collect ) + # let git_status = (git -c core.quotepath=false -c color.status=false status -uall --short --branch) + let git_info = (do -i { git rev-parse --abbrev-ref HEAD } | str trim | str collect ) # what to put in the title - let title_bar = $(set_title) + let title_bar = (set_title) # get the terminal width - let term_width = $(term size -w) + let term_width = (term size -w) # get the curren time - let current_time = $(date now | date format '%I:%M:%S%.3f %p') + let current_time = (date now | date format '%I:%M:%S%.3f %p') # let's construct the left and right prompt # the left side of the prompt with ansi colors - let left_colored = $(build-string $(ansi gb) $current_dir $(ansi cb) '(' $git_info ')' $(ansi reset)) + let left_colored = $"(ansi gb)($current_dir)(ansi cb)(char lparen)($git_info)(char rparen)(ansi reset)" # the left prompt length without the ansi escapes - let left_len = $(echo $left_colored | ansi strip | str length) + let left_len = ($left_colored | ansi strip | str length) # the right side of the prompt with ansi colors - let right_colored = $(build-string $(ansi blue) $(echo $nu.env.CMD_DURATION) '|' $(ansi dark_gray) $current_time $(ansi reset)) + let right_colored = $"(ansi blue)($nu.env.CMD_DURATION)|(ansi dark_gray)($current_time)(ansi reset)" # the right prompt length *with* ansi escapes (need this to determine how many escape chars there are) - let right_colored_len = $(echo $right_colored | str length) + let right_colored_len = ( $right_colored | str length) # the right prompt length without the ansi escapes - let right_len = $(echo $right_colored | ansi strip | str length) + let right_len = ($right_colored | ansi strip | str length) # let's calcuate the length of the right prompt so we know how much to pad the left prompt - let calculated_right_len = $(= $term_width - $left_len + ($right_colored_len - $right_len)) + let calculated_right_len = ($term_width - $left_len + ($right_colored_len - $right_len)) # finally, let's make the prompt - let the_prompt = $(build-string $left_colored $(echo $right_colored | str lpad -c ' ' -l $calculated_right_len) $(char newline) $decorator ' ') + let the_prompt = $"($left_colored)($right_colored | str lpad -c ' ' -l $calculated_right_len)(char newline)($decorator) " # let's update the title bar now echo $title_bar @@ -60,37 +60,39 @@ def construct_prompt [] { # Abbreviate home path def home_abbrev [] { - let is_home_in_path = $(echo $(pwd) | str starts-with $nu.home-dir) + let is_home_in_path = (pwd | into string | str starts-with $nu.home-dir) if $is_home_in_path { - let lin-home = $(echo $nu.home-dir | str find-replace -a '\\' '/' | str downcase) - let lin-pwd = $(echo $(pwd) | str find-replace -a '\\' '/' | str downcase) - echo $lin-pwd | str find-replace $lin-home '~' + let lin-home = ($nu.home-dir | into string | str find-replace -a '\\' '/' | str downcase) + let lin-pwd = (pwd | into string | str find-replace -a '\\' '/' | str downcase) + $lin-pwd | str find-replace $lin-home '~' } { - echo $(pwd) + pwd } } # Get Git Info custom commands def git_br [] { - echo [ $(ansi gb) $(pwd) $(ansi reset) '(' $(ansi cb) $(do -i { git rev-parse --abbrev-ref HEAD } | str trim | str collect ) $(ansi reset) ')' $(char newline) $(ansi yb) $(date now | date format '%m/%d/%Y %I:%M:%S%.3f %p') $(ansi reset) ' ¯\\_(ツ)_/¯ ' $(char prompt) ' '] | str collect + $"(ansi gb)(pwd)(ansi reset)(char lparen)(ansi cb)(do -i { git rev-parse --abbrev-ref HEAD } | str trim | str collect)(ansi reset)(char rparen)(char newline)(ansi yb)(date now | date format '%m/%d/%Y %I:%M:%S%.3f %p')(ansi reset)¯\\_(ツ)_/¯(char prompt) " } # Set Title String custom commands def set_title_str [str-arg] { - echo [$(ansi title) ' ' $str-arg ' ' $(char bel)] | str collect -} -def get_abbrev_pwd_win [] { - echo [$(pwd | split row '\' | first $(pwd | split row '\' | length | each {= $it - 1} ) | str substring '0,1' | format '{$it}/' | append $(pwd | split row '\' | last ) | str collect)] | str collect + $"(ansi title) ($str-arg) (char bel)" } + +# def get_abbrev_pwd_win [] { +# echo [(pwd | split row '\' | first (pwd | split row '\' | length | each { $it - 1} ) | str substring '0,1' | format '{$it}/' | append (pwd | split row '\' | last ) | str collect)] | str collect +# } + def get_abbrev_pwd_lin [] { - # echo [$(pwd | split row '/' | first $(pwd | split row '/' | length | each {= $it - 1} ) | each { str substring '0,1' | format '{$it}/' } | append $(pwd | split row '/' | last ) | str collect)] | str collect - echo [$(home_abbrev | split row '/' | first $(home_abbrev | split row '/' | length | each {= $it - 1} ) | each { str substring '0,1' | format '{$it}/' } | append $(home_abbrev | split row '/' | last ) | str collect)] | str collect + # echo [(pwd | split row '/' | first (pwd | split row '/' | length | each { $it - 1} ) | each { str substring '0,1' | format '{$it}/' } | append (pwd | split row '/' | last ) | str collect)] | str collect + echo [(home_abbrev | split row '/' | first (home_abbrev | split row '/' | length | each { $it - 1} ) | each { str substring '0,1' | format '{$it}/' } | append (home_abbrev | split row '/' | last ) | str collect)] | str collect } def set_title [] { - set_title_str $(build-string $(get_abbrev_pwd_lin) ' ' $(term size -w) 'x' $(term size -t) | str collect) + set_title_str (build-string (get_abbrev_pwd_lin) ' ' (term size -w) 'x' (term size -t) | str collect) } def create_second_line [] { - build-string $(ansi gb) $(char -u "2514") $(char -u "2500") ' $ ' $(ansi cb) $(char prompt) $(ansi reset) + build-string (ansi gb) (char -u "2514") (char -u "2500") ' $ ' (ansi cb) (char prompt) (ansi reset) } \ No newline at end of file diff --git a/stdlib_candidate/flatter.nu b/stdlib_candidate/flatter.nu index 67e674c..2cf7fec 100644 --- a/stdlib_candidate/flatter.nu +++ b/stdlib_candidate/flatter.nu @@ -3,7 +3,7 @@ # Example: sys | flatter 3 def flatter [levels:int] { if $levels > 0 { - flatten | flatter $(= $levels - 1) + flatten | flatter ($levels - 1) } { each { echo $it } } diff --git a/stdlib_candidate/get-column.nu b/stdlib_candidate/get-column.nu index 988e086..d0eac0c 100644 --- a/stdlib_candidate/get-column.nu +++ b/stdlib_candidate/get-column.nu @@ -5,10 +5,10 @@ def get-col [ ] { # meant to be used like `ls | get-col 1` - # ls | select $(ls | get | nth 2) - + # ls | select (ls | get | nth 2) + each { - echo $it | select $(echo $it | get | nth $col_index) + echo $it | select (echo $it | get | nth $col_index) } } diff --git a/stdlib_candidate/get-latest-release-linux.nu b/stdlib_candidate/get-latest-release-linux.nu index 839f9ea..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 [] { - 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 redirected_url = $(fetch $download_url --raw) - let real_download_url = $(echo $redirected_url | xpath '//@href' | get '//@href') + # fetch the information about the latest release + let metadata = (fetch https://api.github.com/repos/nushell/nushell/releases/latest) + 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) + # 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/logging.nu b/stdlib_candidate/logging.nu index 734f84a..7d07979 100644 --- a/stdlib_candidate/logging.nu +++ b/stdlib_candidate/logging.nu @@ -1,6 +1,6 @@ # This is a first attempt and some type of logging def log [message:any] { - let now = $(date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $(build-string $now '|DBG|' $message $(char newline)) + let now = (date now | date format '%Y%m%d_%H%M%S.%f') + let mess = $"($now)|DBG|($message)(char nl)" echo $mess | autoview } \ No newline at end of file diff --git a/stdlib_candidate/nu_style.nu b/stdlib_candidate/nu_style.nu index 97618de..cfaf4b8 100644 --- a/stdlib_candidate/nu_style.nu +++ b/stdlib_candidate/nu_style.nu @@ -2,7 +2,7 @@ # found here https://github.com/PowerShell/PowerShell/blob/5f3dd938b792e1a395fd011ac1461246db7c0e1f/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs # Example Usage -# echo $(fg_blue) Darren $(relet) ' ' Schroeder | str collect +# echo (fg_blue) Darren (relet) ' ' Schroeder | str collect # More examples in the short_list.nu script alias fmt_error = ansi -e '31;1m' @@ -28,8 +28,8 @@ alias underline_on = ansi -e '4m' alias strikethrough_off = ansi -e '29m' alias strikethrough_on = ansi -e '9m' -# this doesn't work right. i need to have an $(ansi escape) defined but i don't think there is one -#def format_hyperlink [link text] {echo [$(ansi -o '8;;') $link '\' $text $(ansi -o '8;;') '\'] | str collect } +# this doesn't work right. i need to have an (ansi escape) defined but i don't think there is one +#def format_hyperlink [link text] {echo [(ansi -o '8;;') $link '\' $text (ansi -o '8;;') '\'] | str collect } alias fg_black = ansi -e '30m' alias fg_red = ansi -e '31m' @@ -59,7 +59,7 @@ def fg_from_rgb [ green:int # green component 0-255 blue:int # blue component 0-255 ] { - echo [$(ansi -e '38;2;') $red ';' $green ';' $blue 'm'] | str collect + echo [(ansi -e '38;2;') $red ';' $green ';' $blue 'm'] | str collect } alias bg_black = ansi -e '40m' @@ -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 670d8dc..a17eb0a 100644 --- a/stdlib_candidate/print.nu +++ b/stdlib_candidate/print.nu @@ -4,19 +4,19 @@ def print [ --separator(-s):any # Optional separator (not yet flagged as optional?) ...rest # All of the parameters ] { - let is_empty = $(= $separator | empty?) - let num_of_rest = $(echo $rest | length) - echo $rest | each --numbered { + let is_empty = ($separator | empty?) + 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 '--' @@ -32,12 +32,12 @@ def print2 [ --separator(-s):any # Optional separator (not yet flagged as optional?) ...rest # All of the parameters ] { - let is_empty = $(= $separator | empty?) - let num_of_rest = $(echo $rest | length) + let is_empty = ($separator | empty?) + 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 } } @@ -46,40 +46,40 @@ def print2 [ # A print command that concatenates arguments together with an optional separator. # This print command will also concatenate tables like [1 2 3] as well as most other primitives -# since the str from command has been updated with wider support. +# since the into string command has been updated with wider support. def print3 [ --separator(-s):any # Optional separator (not yet flagged as optional?) --flat(-f) # If tables are found, flatten them ...rest # All of the parameters ] { - let sep_empty = $(= $separator | empty?) - let num_of_rest = $(echo $rest | length) - let flat = $(= $flat | empty?) - echo $rest | each --numbered { + let sep_empty = ($separator | empty?) + let num_of_rest = ($rest | length) + let flat = ($flat | empty?) + $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 5b6fad6..2ab7ac9 100644 --- a/table_grouping.nu +++ b/table_grouping.nu @@ -1,4 +1,4 @@ -let table = $(echo [ +let table = (echo [ [url user_login title ]; [https://api.github.com/repos/nushell/nushell/issues/3382 ammkrn 'Dont unwrap rustyline helper in cli' ] [https://api.github.com/repos/nushell/nushell/issues/3379 jonathandturner 'Simplify down to one type of context' @@ -9,23 +9,28 @@ let table = $(echo [ ] [https://api.github.com/repos/nushell/nushell/issues/3367 fdncred 'tweaked the error handling to show specific errors'] ]) -echo $table +# Show what the table looks like +$"This is an example table (char nl)" +$table -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) +$"This is markdown created from the example table (char nl)" +# Now show what the table in Markdown looks like +$"## 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 # ╭───┬──────────────────────────────────────────────────────────┬─────────────────┬───────────────────────────────────────────────────────╮ @@ -41,7 +46,7 @@ echo $table | group-by user_login | pivot user prs | each { # ╰───┴──────────────────────────────────────────────────────────┴─────────────────┴───────────────────────────────────────────────────────╯ def log [message:any] { - let now = $(date now | date format '%Y%m%d_%H%M%S.%f') - let mess = $(build-string $now '|DBG|' $message $(char newline)) + let now = (date now | date format '%Y%m%d_%H%M%S.%f') + let mess = (build-string $now '|DBG|' $message (char newline)) echo $mess | autoview } diff --git a/temp.nu b/temp.nu index bdf709d..d02d04b 100644 --- a/temp.nu +++ b/temp.nu @@ -4,8 +4,8 @@ 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' + let celcius = (($fahren - 32) * 5 / 9) + $"($fahren) °F is ($celcius) °C" } # Convert Fahrenheit to Kelvin @@ -14,8 +14,8 @@ 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' + let kelvin = (($fahren - 32) * 5 / 9 + 273.15) + $"($fahren) °F is ($kelvin) °K" } # Convert Celcius to Fahrenheit @@ -24,8 +24,8 @@ 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' + let fahren = (($celcius * 9 / 5) + 32) + $"($celcius) °C is ($fahren) °F" } # Convert Celcius to Kelvin @@ -34,8 +34,8 @@ def "temp c-to-k" [ ] { # 100°C + 273.15 = 373.15K - let kelvin = $(= $celcius + 273.15) - build-string $celcius ' °C is ' $kelvin ' °K' + let kelvin = ($celcius + 273.15) + $"($celcius) °C is ($kelvin) °K" } # Convert Kelvin to Fahrenheit @@ -44,8 +44,8 @@ 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' + let fahren = (($kelvin - 273.15) * 9 / 5 + 32) + $"($kelvin) °K is ($fahren) °F" } # Convert Kelvin to Celcius @@ -54,19 +54,19 @@ def "temp k-to-c" [ ] { # 100K − 273.15 = -173.1°C - let celcius = $(= $kelvin - 273.15) - build-string $kelvin ' °K is ' $celcius ' °C' + let celcius = ($kelvin - 273.15) + $"($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 diff --git a/this_week_in_nu.nu b/this_week_in_nu.nu deleted file mode 100644 index b8d4dfb..0000000 --- a/this_week_in_nu.nu +++ /dev/null @@ -1,60 +0,0 @@ -# fetch https://api.github.com/repos/nushell/nushell/pulls?q=is%3Apr+merged%3A%3E%3D2021-04-20+ | select html_url user.login title body -# fetch https://api.github.com/search/issues?q=repo:nushell/nushell+is:pr+is:merged+merged:%3E2021-05-08 | get items | select html_url user.login title body -# Repos to monitor - -def do-work [] { - let site_table = [ - [site repo - ]; [Nushell nushell - ] [Extension vscode-nushell-lang - ] [Documentation nushell.github.io - ] [Wasm demo - ] [Nu_Scripts nu_scripts - ] [RFCs rfcs] - # ] [Jupyter jupyter] - ] - - let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/" - let query_date = $(seq date --days 7 -r | last) - let query_suffix = $(build-string "+is:pr+is:merged+merged:%3E%3D" $query_date) - - let entries = $(echo $site_table | each { - let query_string = $(build-string $query_prefix $it.repo $query_suffix) - let site_json = $(fetch $query_string | get items | select html_url user.login title body) - build-string '## ' $(echo $it.site) $(char nl) $(char nl) - if $(= $site_json | empty?) { - build-string "none found this week" $(char nl) $(char nl) - } { - echo $site_json | group-by user_login | pivot user prs | each { - let user_name = $it.user - let pr_count = $(echo $it.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 $(char nl) '### [' $it.item.title '](' $it.item.html_url ')' $(char nl) $(char nl) $it.item.body $(char nl) - } { - build-string $(char nl) '### [' $it.item.title '](' $it.item.html_url ')' $(char nl) $(char nl) $it.item.body $(char nl) 'and' $(char nl) - } - } | str collect) - - build-string '### **' $user_name '** ' $(char nl) $(char nl) '---' $(char nl) $user_prs $(char nl) - } | str collect - build-string $(char nl) - } - - # We need 2 seconds between fetches or github's api limiting will limit us - sleep 2sec - }) - - if $(= $entries | empty?) { - - } { - echo $entries | str collect - } -} - -# 2019-08-23 was the release of 0.2.0, the first public release -let week_num = $(seq date -b '2019-08-23' -n 7 | length) -build-string '# This week in Nushell #' $week_num $(char nl) $(char nl) -do-work | str collect