Skip to content

Commit 3d6b378

Browse files
authored
some tweaks for a variety of scripts (#1191)
These are some script tweaks that I've been holding onto for too long and am finally ready to get them into nu_scripts.
1 parent 2ef093b commit 3d6b378

File tree

5 files changed

+76
-51
lines changed

5 files changed

+76
-51
lines changed

make_release/20k_club.nu

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,22 @@ def get_pr_counts [debug_csv: bool, repos_root_folder = '/Users/fdncred/src'] {
7979
append (open vscode.csv)
8080
)
8181

82-
let data_polars = ($data | polars into-df)
83-
$data_polars |
84-
polars group-by name |
85-
polars agg [(polars col commits | polars sum | polars as "all_commits")] |
86-
polars collect |
87-
polars sort-by all_commits |
88-
polars reverse |
89-
polars into-nu |
90-
first 75
82+
# let data_polars = ($data | polars into-df)
83+
# $data_polars |
84+
# polars group-by name |
85+
# polars agg [(polars col commits | polars sum | polars as "all_commits")] |
86+
# polars collect |
87+
# polars sort-by all_commits |
88+
# polars reverse |
89+
# polars into-nu |
90+
# first 75
91+
$data |
92+
group-by name --to-table |
93+
upsert all_commits {|r| $r.items.commits | math sum } |
94+
reject items |
95+
sort-by all_commits --reverse |
96+
first 75 |
97+
to csv
9198
}
9299
}
93100

modules/coloring/color_table.nu

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def make_header [hi] {
88
let ansi105m = ('105m' | fill -a l -w 9 -c ' ')
99
let ansi106m = ('106m' | fill -a l -w 9 -c ' ')
1010
let ansi107m = ('107m' | fill -a l -w 9 -c ' ')
11-
$"(char newline)($ansi100m)($ansi101m)($ansi102m)($ansi103m)($ansi104m)($ansi105m)($ansi106m)($ansi107m)(char newline)"
11+
$"(char newline) ($ansi100m)($ansi101m)($ansi102m)($ansi103m)($ansi104m)($ansi105m)($ansi106m)($ansi107m)(char newline)"
1212

1313
} else {
1414
let ansi40m = ('40m' | fill -a l -w 10 -c ' ')
@@ -19,7 +19,8 @@ def make_header [hi] {
1919
let ansi45m = ('45m' | fill -a l -w 8 -c ' ')
2020
let ansi46m = ('46m' | fill -a l -w 8 -c ' ')
2121
let ansi47m = ('47m' | fill -a l -w 8 -c ' ')
22-
$"(char newline)($ansi40m)($ansi41m)($ansi42m)($ansi43m)($ansi44m)($ansi45m)($ansi46m)($ansi47m)(char newline)"
22+
let ansi49m = ('49m' | fill -a l -w 8 -c ' ')
23+
$"(char newline) ($ansi40m)($ansi41m)($ansi42m)($ansi43m)($ansi44m)($ansi45m)($ansi46m)($ansi47m)($ansi49m)(char newline)"
2324
}
2425
}
2526

@@ -34,58 +35,58 @@ def mk_header [color_range:range] {
3435
let lo_start_pad = 10
3536
let lo_regular_pad = 8
3637
echo $color_range | each { |color|
38+
if $color != 48 {
3739
let ansi_color = $"($color)m"
3840
if $color == $min_rng {
3941
if $min_rng == 100 {
4042
($ansi_color | fill -a l -w $hi_start_pad -c ' ')
41-
4243
} else {
4344
($ansi_color | fill -a l -w $lo_start_pad -c ' ')
44-
4545
}
46-
4746
} else {
4847
if $min_rng >= 100 {
4948
($ansi_color | fill -a l -w $hi_regular_pad -c ' ')
50-
5149
} else {
5250
($ansi_color | fill -a l -w $lo_regular_pad -c ' ')
53-
5451
}
55-
5652
}
57-
} | str join
53+
}
54+
} | str join
5855
echo (char newline)
5956
}
6057

6158
def color_row_range [num:int bg_rg:range] {
6259
let reset = (ansi reset)
6360
let row_header = $"($num)m ($reset)"
6461
let row_data = (echo $bg_rg | each { |back|
62+
if $back != 48 {
6563
let row_name = $"($num);($back)m"
6664
let ansi_color = (ansi -e $row_name)
6765
$"($ansi_color) ($row_name) ($reset)"
66+
}
6867
} | append (char newline) | str join)
6968
$"($row_header)($row_data)"
7069
}
7170

7271
def create_color_tables [fg_range:range bg_range:range] {
7372
echo $fg_range | each { |fg|
73+
if $fg != 38 {
7474
color_row_range $fg $bg_range
75+
}
7576
} | str join
7677
}
7778

7879
def color_table [] {
7980
[
80-
# make_header $false
81-
(mk_header 40..47)
82-
(create_color_tables 30..37 40..47)
81+
(make_header false)
82+
# (mk_header 40..49)
83+
(create_color_tables 30..39 40..49)
8384

8485
# put a line between tables
8586
(char newline)
8687

87-
#make_header $true
88-
(mk_header 100..107)
88+
(make_header true)
89+
# (mk_header 100..107)
8990
(create_color_tables 90..97 100..107)
9091
] | str join
9192
}

modules/coloring/color_tables.nu

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
# echo ""
1212

1313
0..8 | each {|x|
14-
let row = (30..37 | each {|i|
15-
let row = (40..47 | each {|a|
14+
let row = (30..39 | each {|i|
15+
let row = (40..49 | each {|a|
16+
if ($a != 48) {
17+
if ($i != 38) {
1618
let color = $"($x);($i);($a)"
1719
$"(ansi -e $color)m\\e[($color)(ansi -e '0;37;40')m "
20+
}}
1821
} | str join)
1922
$"($row)(char newline)"
2023
} | str join)

modules/coloring/sample.nu

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
# Background Colors
2-
[40..47 100..107 49] | each { flatten } | flatten | each { |clbg|
3-
# Foreground Colors
4-
[30..37 90..97 39] | each { flatten } | flatten | each { |clfg|
5-
# 0 Normal
6-
# 1 Bold or increased intensity
7-
# 2 Faint or decreased intensity
8-
# 3 Italic (not widely supported)
9-
# 4 Underline
10-
# 5 Slow Blink < 150 per minute
11-
# 6 Rapid Blink > 150 per minute
12-
# 7 Reverse Video
13-
# 8 Conceal (not widely supported)
14-
# 9 Strike-through
15-
let row = (0..9 | each { |attr|
16-
let ansi_str = $"($attr);($clbg);($clfg)m"
17-
$"(ansi -e $ansi_str) ($ansi_str) (ansi reset)"
18-
} | str join)
19-
$"($row)(char newline)"
20-
} | str join
21-
} | str join
1+
def "into list" []: any -> list {
2+
let input = $in
3+
let type = ($input | describe --detailed | get type)
4+
match $type {
5+
range => {$input | each {||}}
6+
list => $input
7+
table => $input
8+
record => {$input | transpose -d key value}
9+
_ => [ $input ]
10+
}
11+
}
2212

13+
def print_sample [] {
14+
# Background Colors
15+
[40..47 49 100..107] | each { into list } | flatten | each { |clbg|
16+
# Foreground Colors
17+
[30..37 39 90..97] | each { into list } | flatten | each { |clfg|
18+
# 0 Normal
19+
# 1 Bold or increased intensity
20+
# 2 Faint or decreased intensity
21+
# 3 Italic (not widely supported)
22+
# 4 Underline
23+
# 5 Slow Blink < 150 per minute
24+
# 6 Rapid Blink > 150 per minute
25+
# 7 Reverse Video
26+
# 8 Conceal (not widely supported)
27+
# 9 Strike-through
28+
let row = (0..9 | each { |attr|
29+
let ansi_str = $"($attr);($clbg);($clfg)m"
30+
$"(ansi -e $ansi_str) ($ansi_str) (ansi reset)"
31+
} | str join)
32+
$"($row)(char newline)"
33+
} | str join
34+
} | str join
35+
}
36+
print_sample
2337
# Bash Script
2438

2539
# #!/bin/bash

modules/prompt/oh-my.nu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
# Abbreviate home path
1515
def home_abbrev [os_name] {
16-
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
16+
let is_home_in_path = ($env.PWD | str starts-with $nu.home-dir)
1717
if $is_home_in_path {
1818
if ($os_name =~ "windows") {
19-
let home = ($nu.home-path | str replace -ar '\\' '/')
19+
let home = ($nu.home-dir | str replace -ar '\\' '/')
2020
let pwd = ($env.PWD | str replace -ar '\\' '/')
2121
$pwd | str replace $home '~'
2222
} else {
23-
$env.PWD | str replace $nu.home-path '~'
23+
$env.PWD | str replace $nu.home-dir '~'
2424
}
2525
} else {
2626
if ($os_name =~ "windows") {
@@ -39,7 +39,7 @@ def path_abbrev_if_needed [apath term_width] {
3939
let P = (ansi { fg: "#E4E4E4" bg: "#3465A4" }) # path
4040
let PB = (ansi { fg: "#E4E4E4" bg: "#3465A4" attr: b }) # path bold
4141
let R = (ansi reset)
42-
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
42+
let is_home_in_path = ($env.PWD | str starts-with $nu.home-dir)
4343

4444
if (($apath | str length) > ($term_width / 2)) {
4545
# split out by path separator into tokens
@@ -325,7 +325,7 @@ def git_left_prompt [gs os] {
325325
] | str join
326326
)
327327

328-
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
328+
let is_home_in_path = ($env.PWD | str starts-with $nu.home-dir)
329329
let path_segment = (
330330
if (($is_home_in_path) and ($branch_name == "")) {
331331
[

0 commit comments

Comments
 (0)