1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-31 14:17:45 +00:00

reorganize site in preparation for beta and releaes (#161)

This commit is contained in:
Darren Schroeder 2022-02-25 13:10:38 -06:00 committed by GitHub
parent 7b76a8e662
commit ca89da5242
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 1402 additions and 763 deletions

View file

@ -8,32 +8,3 @@ You can run nushell scripts in a few different ways.
1. You can type `nu <script name>`.
2. From with nushell, you can type `source <script name>` and if the script is just a bunch of commands it will run the script. If the script is a custom command it will load those custom commands into your current scope so you can run them like any other command.
## Included Scripts
| Category | File | Nu Version | Description |
| ---------------- | --------------------------------------------------------- | ---------- | ----------- |
| coloring | [color_table.nu](./coloring/color_table.nu) | 0.26 | Produces a color table of ansi foregroupd and background colors. |
| coloring | [color_tables.nu](./coloring/color_tables.nu) | 0.26 | Produces many tables with ansi foreground and background with styles |
| coloring | [gradient.nu](./coloring/gradient.nu) | 0.26 | Draws a simple blue gradient. |
| coloring | [nu_index_bg.nu](./coloring/nu_index_bg.nu) | 0.26 | Draws background colors using ansi escape sequences using an index |
| coloring | [nu_index_fg.nu](./coloring/nu_index_fg.nu) | 0.26 | Draws foreground colors using ansi escape sequences using an index |
| coloring | [nu_index_fg2.nu](./coloring/nu_index_fg2.nu) | 0.26 | Draws foreground colors using ansi escape sequences using an index a different way |
| coloring | [python_index_table.nu](./coloring/python_index_table.nu) | 0.26 | Draws foreground and background colors using ansi escape sequences using an index modeled after a python script |
| coloring | [ref_table.nu](./coloring/ref_table.nu) | 0.26 | A table with row and column headers indicating the colors |
| coloring | [sample.nu](./coloring/sample.nu) | 0.26 | An exhaustive list of colors and styles using ansi escape sequences |
| coloring | [short_list.nu](./coloring/short_list.nu) | 0.26 | A small color sample that uses another nu script to define the colors by name. |
| not assigned yet | [fehbg.nu](./fehbg.nu) | >0.25.1 | Sets a random image from a directory as a wallpaper (Linux only) |
| not assigned yet | [maintainer_time.nu](./maintainer_time.nu) | 0.26 | Looks up time by timezone for the nushell maintainers |
| not assigned yet | [make_readme_table.nu](./make_readme_table.nu) | 0.26 | Generates this table. |
| nu_101 | [demo.nu](./nu_101/demo.nu) | 0.26 | Creates a custom `ls` command |
| nu_101 | [inner_outer_loop.nu](./nu_101/inner_outer_loop.nu) | 0.26 | Demonstrates how to iterate in an inner and outer loop. |
| parsing | [sample_andres.nu](./parsing/sample_andres.nu) | 0.26 | Demonstrates some json parsing. |
| progress_bar | [percent_meter.nu](./progress_bar/percent_meter.nu) | 0.26 | Draws a percent meter. |
| progress_bar | [progress_bar.nu](./progress_bar/progress_bar.nu) | 0.26 | Draws a progress bar |
| progress_bar | [progress_bar_no_back.nu](./progress_bar/progress_bar_no_back.nu) | 0.26 | Draws a progress bar with no background |
| prompt | [git_status_prompt.nu](./prompt/git_status_prompt.nu) | 0.28 | Creates a prompt which includes short working directory and current git status. |
| stdlib_candidate | [nu_style.nu](./stdlib_candidate/nu_style.nu) | 0.26 | Define colors as names. |
| stdlib_candidate | [print.nu](./stdlib_candidate/print.nu) | 0.26 | Examples of a print statement. |
| virtual_envs | [conda.nu](./virtual_environments/conda.nu) | 0.32 | Activates a Conda environment. |
| virtual_envs | [venv.nu](./virtual_environments/venv.nu) | 0.32 | Activates a Python venv. |

View file

39
before_v0.60/README.md Normal file
View file

@ -0,0 +1,39 @@
# Nushell Scripts
This is a place to share Nushell scripts with each other. If you'd like to share your scripts, create a PR that adds it to the repo.
## Running Scripts
You can run nushell scripts in a few different ways.
1. You can type `nu <script name>`.
2. From with nushell, you can type `source <script name>` and if the script is just a bunch of commands it will run the script. If the script is a custom command it will load those custom commands into your current scope so you can run them like any other command.
## Included Scripts
| Category | File | Nu Version | Description |
| ---------------- | --------------------------------------------------------- | ---------- | ----------- |
| coloring | [color_table.nu](./coloring/color_table.nu) | 0.26 | Produces a color table of ansi foregroupd and background colors. |
| coloring | [color_tables.nu](./coloring/color_tables.nu) | 0.26 | Produces many tables with ansi foreground and background with styles |
| coloring | [gradient.nu](./coloring/gradient.nu) | 0.26 | Draws a simple blue gradient. |
| coloring | [nu_index_bg.nu](./coloring/nu_index_bg.nu) | 0.26 | Draws background colors using ansi escape sequences using an index |
| coloring | [nu_index_fg.nu](./coloring/nu_index_fg.nu) | 0.26 | Draws foreground colors using ansi escape sequences using an index |
| coloring | [nu_index_fg2.nu](./coloring/nu_index_fg2.nu) | 0.26 | Draws foreground colors using ansi escape sequences using an index a different way |
| coloring | [python_index_table.nu](./coloring/python_index_table.nu) | 0.26 | Draws foreground and background colors using ansi escape sequences using an index modeled after a python script |
| coloring | [ref_table.nu](./coloring/ref_table.nu) | 0.26 | A table with row and column headers indicating the colors |
| coloring | [sample.nu](./coloring/sample.nu) | 0.26 | An exhaustive list of colors and styles using ansi escape sequences |
| coloring | [short_list.nu](./coloring/short_list.nu) | 0.26 | A small color sample that uses another nu script to define the colors by name. |
| not assigned yet | [fehbg.nu](./fehbg.nu) | >0.25.1 | Sets a random image from a directory as a wallpaper (Linux only) |
| not assigned yet | [maintainer_time.nu](./maintainer_time.nu) | 0.26 | Looks up time by timezone for the nushell maintainers |
| not assigned yet | [make_readme_table.nu](./make_readme_table.nu) | 0.26 | Generates this table. |
| nu_101 | [demo.nu](./nu_101/demo.nu) | 0.26 | Creates a custom `ls` command |
| nu_101 | [inner_outer_loop.nu](./nu_101/inner_outer_loop.nu) | 0.26 | Demonstrates how to iterate in an inner and outer loop. |
| parsing | [sample_andres.nu](./parsing/sample_andres.nu) | 0.26 | Demonstrates some json parsing. |
| progress_bar | [percent_meter.nu](./progress_bar/percent_meter.nu) | 0.26 | Draws a percent meter. |
| progress_bar | [progress_bar.nu](./progress_bar/progress_bar.nu) | 0.26 | Draws a progress bar |
| progress_bar | [progress_bar_no_back.nu](./progress_bar/progress_bar_no_back.nu) | 0.26 | Draws a progress bar with no background |
| prompt | [git_status_prompt.nu](./prompt/git_status_prompt.nu) | 0.28 | Creates a prompt which includes short working directory and current git status. |
| stdlib_candidate | [nu_style.nu](./stdlib_candidate/nu_style.nu) | 0.26 | Define colors as names. |
| stdlib_candidate | [print.nu](./stdlib_candidate/print.nu) | 0.26 | Examples of a print statement. |
| virtual_envs | [conda.nu](./virtual_environments/conda.nu) | 0.32 | Activates a Conda environment. |
| virtual_envs | [venv.nu](./virtual_environments/venv.nu) | 0.32 | Activates a Python venv. |

77
before_v0.60/bin-utils.nu Normal file
View file

@ -0,0 +1,77 @@
# bin-utils.nu
def "get bits" [x: int, bits] {
if $x == 0 {
$bits
} else {
let new-x = ($x / 2 | into int)
let bit = if $new-x == ($x / 2 | math ceil | into int) {
0
} else {
1
}
get bits $new-x ($bits | append $bit)
}
}
def "get bits2" [x: int] {
let inp = $in
if $x != 0 {
let new-x = ($x / 2 | into int)
let bit = if $new-x == ($x / 2 | math ceil | into int) {
0
} else {
1
}
$inp | append $bit | get bits2 $new-x
} else {
$inp
}
}
export def "into bits" [] {
let inp = $in
let span = (metadata $inp).span
let type = ($inp | describe)
if "list" in $type {
$inp | each {
$it | into bits
}
} else if "int" in $type {
[] | get bits2 $inp
} else {
error make {
msg: "Cannot convert to bits",
label: {
text: "This value cannot be converted to bits"
start: $span.start
end: $span.end
}
}
}
}
export def "bits into int" [] {
reverse | reduce -f 0 { 2 * $it.acc + $it.item }
}
export def "test bits" [] {
0..4 | each {
let bits = ($it | into bits)
let res = ($bits | bits into int)
let span = (metadata $res).span
if $it == 1 {
error make {
msg: "Test mismatch",
label: {
text: $"Expected: ($it), bits: ($bits | str collect ''), result: ($res)"
start: $span.start
end: $span.end
}
}
}
} | compact
}

View file

View file

@ -0,0 +1,5 @@
# Coloring Scripts
### Definition
These scripts are used to demonstrate the `ansi` command using `ansi` coloring. This is mainly a demo area where we have taken typical `bash` scripts and ported them to nushell scripts. It would be nice if all scripts here showed the "other" version of script and the ported nushell version. We can show "other" flavors of scripts by including them as comments in the nushell scripts or by naming the nushell script and the other script the same basename.

View file

@ -0,0 +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 { |col|
let fgcolor = (iter_inc 2 2 $col)
if $fgcolor > 200 && $fgcolor < 210 {
$"(ansi -e '48;2;0;0;')($fgcolor)m($stamp)(ansi -e '0m')"
} {
$"(ansi -e '48;2;0;0;')($fgcolor)m(char sp)(ansi -e '0m')"
}
} | str collect)
$"($row_data)(char newline)" | autoview
} | str collect
def iter_inc [incr mult iter] {
$incr + $mult * $iter
}
# ╭────┬────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────╮
# │ # │ 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 │
# ╰────┴────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────╯

View file

@ -1,10 +1,11 @@
# this script will print a blue gradient on the screen
# First:
# pip install ansicolors
# this is a port of the gradient.nu script used for comparison
from colors import *
def iter_inc(incr, mult, it):
return incr + mult * it
height = 40
width = 160
stamp = "py"
@ -13,7 +14,7 @@ for line in range(0, height):
row_data = ""
for col in range(0, width):
fgcolor = 2 + 2 * col
fgcolor = iter_inc(2, 2, col)
if fgcolor > 200 and fgcolor < 210:
row_data = row_data + color(stamp, bg='rgb(0, 0, %d)' % fgcolor)
else:

45
engine-q/fehbg.nu → before_v0.60/fehbg.nu Executable file → Normal file
View file

@ -1,4 +1,4 @@
#!/usr/bin/env engine-q
#!/usr/bin/env nu
#
# ~/.fehbg.nu
#
@ -9,7 +9,7 @@
# The procedure is as follows::
# * Select a random image from a directory (recursively entering all
# subdirectories)
# * Print the path of the image on top of the selected image
# * Print the path of the image as an overlay on top of the selected image
# * Save the result in a temporary file
# * Set the temporary image as a wallpaper.
#
@ -20,50 +20,45 @@
# xinitrc.
#
# Dependencies;
# * new Nushell engine (https://github.com/nushell/engine-q)
# * nu version >=0.32.0 (tested on 0.36.0)
# * feh
# * imagemagick
# Path definitions
let img-dir = $env.WALLPAPER_DIR
let tmp-image = ([ $env.TMP_DIR "wallpaper.jpg" ] | path join)
let img_dir = $nu.env.WALLPAPER_DIR
let tmp_image = (echo [ $nu.env.TMP_DIR "wallpaper.jpg" ] | path join)
# Monitor resolution
let resolution-y = 1440
let res-str = ($"x($resolution-y)")
let resolution_y = 1440
# Position of the caption
let pos-x = 5
let pos-y = (0.995 * $resolution-y | into int)
let pos_x = 5
let pos_y = 0.995 * $resolution_y
# Select random item from input
def select-random [] {
shuffle | first
}
# Helper commands
def select_random [] { shuffle | first }
# List all images in a directory and all its subdirectories
def list-images [dir: path] {
ls $"($dir)/**/*" |
where type == file |
str downcase name |
where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff || name =~ png
def list_images [dir] {
ls (build-string $dir /**/*) | where type == File | where name =~ jpg || name =~ jpeg || name =~ tif || name =~ tiff
}
# Set the caption text (just filename for now)
def caption [img-f: string] {
echo $img-f
def caption [img_f] {
echo $img_f
}
# Build the argument for the '-draw' command of the 'convert' utility
def draw-str [img-f: string] {
$"text ($pos-x), ($pos-y) (char dq)(caption $img-f)(char dq) "
def draw_str [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) # TODO: change the env var to $img-dir
let img_name = (list_images $img_dir | select_random | get name)
# Resize the image to the monitor height, draw the caption and save it
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
feh --no-fehbg --bg-max $tmp_image

View file

@ -18,6 +18,6 @@ def spark [v: any] {
let scale = (($max - $min) / 7.)
for e in $v {
let i = (($e - $min) / $scale | into int)
$"($TICKS | get $i)"
$"($TICKS | nth $i)"
} | str collect
}

View file

0
git/git_gone.nu → before_v0.60/git/git_gone.nu Executable file → Normal file
View file

View file

View file

@ -0,0 +1,17 @@
cd crates
let first-wave = [nu-path, nu-ansi-term, nu-pretty-hex, nu-source, nu-errors, nu-protocol, nu-value-ext, nu-test-support, nu-table, nu-data, nu-parser, nu-plugin, nu-stream, nu-engine, nu-json, nu-serde]
echo $first-wave | each { enter $it; cargo publish; exit; sleep 1min }
let second-wave = [nu-command, nu-completion, nu-cli]
echo $second-wave | each { enter $it; cargo publish --no-verify; exit; sleep 1min }
ls nu_plugin_* | each { enter $it.name; cargo publish; exit }
sleep 1min
cd ..
cargo publish

View file

@ -0,0 +1,71 @@
# 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]
[engine-q engine-q]
[reedline reedline]
# ] [Jupyter jupyter]
]
let query_prefix = "https://api.github.com/search/issues?q=repo:nushell/"
let query_date = (seq date --days 7 -r | last)
let per_page = "100"
let page_num = "1" # need to implement iterating pages
let colon = "%3A"
let gt = "%3E"
let eq = "%3D"
let amp = "%26"
let query_suffix = $"+is($colon)pr+is($colon)merged+merged($colon)($gt)($eq)($query_date)&per_page=100&page=1"
let entries = ($site_table | each {
let query_string = $"($query_prefix)($it.repo)($query_suffix)"
# this is for debugging the rate limit. comment it out if things are working well
# fetch -u $nu.env.GITHUB_USERNAME -p $nu.env.GITHUB_PASSWORD https://api.github.com/rate_limit | get resources | select core.limit core.remaining graphql.limit graphql.remaining integration_manifest.limit integration_manifest.remaining search.limit search.remaining
let site_json = (fetch -u $nu.env.GITHUB_USERNAME -p $nu.env.GITHUB_PASSWORD $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
}
})
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)"
if ($nu.env | select GITHUB_USERNAME | empty?) || ($nu.env | select GITHUB_PASSWORD | empty?) {
echo 'Please set GITHUB_USERNAME and GITHUB_PASSWORD in $nu.env to use this script'
} {
do-work | str collect
}

View file

@ -0,0 +1,5 @@
# Prompt Scripts
### Definition
These scripts should be used to draw a custom command prompt in nushell. They can include anything that we think is appropriate for prompts such as `git` commands, `starship`, `oh-my-posh`, etc.

Some files were not shown because too many files have changed in this diff Show more