Skip to content

nushell-prophet/dotnu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

dotnu

dotnu - tools for Nushell module developers ๐Ÿ› ๏ธ

(A good companion for numd)

dotnu augments Nushell with helpers for literate programming, dependency analysis, and script profiling.

dotnu video demo

dotnu demo

Quickstart

git

git clone https://github.com/nushell-prophet/dotnu; cd dotnu
use dotnu
nupm install https://github.com/nushell-prophet/dotnu --git
# if nupm modules are not in  `NU_LIB_DIRS`:
$env.NU_LIB_DIRS ++= [ ($env.NUPM_HOME | path join "modules") ]

use dotnu

Embeds โ€” keeping examples in sync

dotnu lets you write literate Nushell: ordinary Nushell scripts that include the real command output right after each pipeline ending in | print $in. See the capture example to grasp the idea quickly.

The | print $in suffix acts as a simple print in native Nushell and as a capture marker for dotnu, so scripts remain valid and functional even when run without loading the dotnu module.

The main command is dotnu embeds-update.

dotnu embeds-update takes a script, rewrites every print $in line so its output is easy to parse, runs the modified script, captures what each marked line prints, and then replaces the old # => blocks in the original file with the fresh output.

You can run it on a file path (e.g., dotnu embeds-update dotnu-capture.nu) or pipe a script into it (e.g., "ls | print $in" | dotnu embeds-update).

use dotnu
dotnu embeds-update --help
# => Inserts captured output back into the script at capture points
# =>
# => Usage:
# =>   > embeds-update {flags} (file)
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>   --echo: output updates to stdout
# =>
# => Parameters:
# =>   file <path>:  (optional)
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€โ”€inputโ”€โ”€โ”ฌโ”€outputโ”€โ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ string  โ”‚ nothing โ”‚
# =>   โ”‚ 1 โ”‚ string  โ”‚ string  โ”‚
# =>   โ”‚ 2 โ”‚ nothing โ”‚ string  โ”‚
# =>   โ”‚ 3 โ”‚ nothing โ”‚ nothing โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€โ”€inputโ”€โ”€โ”ดโ”€outputโ”€โ”€โ•ฏ
# =>

Embeds helper commands

While it is easy to write scripts in editor, there are several convenience helper commands that facilitate populating script files from terminal.

dotnu embeds-setup

define or change the capture file (add --auto-commit to autoโ€‘commit snapshots).

dotnu embeds-setup --help
# => Set environment variables to operate with embeds
# =>
# => Usage:
# =>   > embeds-setup {flags} (path)
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>   --auto-commit
# =>
# => Parameters:
# =>   path <path>:  (optional)
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€inputโ”€โ”ฌโ”€outputโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ any   โ”‚ any    โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€inputโ”€โ”ดโ”€outputโ”€โ•ฏ
# =>

dotnu embeds-capture-start and dotnu embeds-capture-stop

record every result printed in the interactive session.

dotnu embeds-capture-start --help
# => start capturing commands and their outputs into a file
# =>
# => Usage:
# =>   > embeds-capture-start (file)
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>
# => Parameters:
# =>   file <path>:  (optional, default: 'dotnu-capture.nu')
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€โ”€inputโ”€โ”€โ”ฌโ”€outputโ”€โ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ nothing โ”‚ nothing โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€โ”€inputโ”€โ”€โ”ดโ”€outputโ”€โ”€โ•ฏ
# =>

dotnu embed-add

capture only the pipeline you run it on; useful for fineโ€‘grained examples.

dotnu embed-add --help
# => Embed stdin together with its command into the file
# =>
# => Usage:
# =>   > embed-add {flags}
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>   -p, --pipe-further: output input further to the pipeline
# =>   --published: output the published representation into terminal
# =>   --dry_run: todo: --
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€inputโ”€โ”ฌโ”€outputโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ any   โ”‚ any    โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€inputโ”€โ”ดโ”€outputโ”€โ•ฏ
# =>

dotnu embeds-remove

strip all captured output, leaving clean code.

dotnu embeds-remove --help
# => Removes annotation lines starting with "# => " from the script
# =>
# => Usage:
# =>   > embeds-remove
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€inputโ”€โ”ฌโ”€outputโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ any   โ”‚ any    โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€inputโ”€โ”ดโ”€outputโ”€โ•ฏ
# =>

Commands

dotnu dependencies

dotnu dependencies --help
# => Check .nu module files to determine which commands depend on other commands.
# =>
# => Usage:
# =>   > dependencies {flags} ...(paths)
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>   --keep-builtins: keep builtin commands in the result page
# =>   --definitions-only: output only commands' names definitions
# =>
# => Parameters:
# =>   ...paths <path>: paths to nushell module files
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€inputโ”€โ”ฌโ”€outputโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ any   โ”‚ any    โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€inputโ”€โ”ดโ”€outputโ”€โ•ฏ
# =>
# => Examples:
# =>
# =>   > dotnu dependencies ...(glob tests/assets/module-say/say/*.nu)
# =>   โ•ญโ”€#โ”€โ”ฌโ”€โ”€callerโ”€โ”€โ”ฌโ”€filename_of_callerโ”€โ”ฌโ”€โ”€calleeโ”€โ”€โ”ฌโ”€stepโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ hello    โ”‚ hello.nu           โ”‚          โ”‚    0 โ”‚
# =>   โ”‚ 1 โ”‚ question โ”‚ ask.nu             โ”‚          โ”‚    0 โ”‚
# =>   โ”‚ 2 โ”‚ say      โ”‚ mod.nu             โ”‚ hello    โ”‚    0 โ”‚
# =>   โ”‚ 3 โ”‚ say      โ”‚ mod.nu             โ”‚ hi       โ”‚    0 โ”‚
# =>   โ”‚ 4 โ”‚ say      โ”‚ mod.nu             โ”‚ question โ”‚    0 โ”‚
# =>   โ”‚ 5 โ”‚ hi       โ”‚ mod.nu             โ”‚          โ”‚    0 โ”‚
# =>   โ”‚ 6 โ”‚ test-hi  โ”‚ test-hi.nu         โ”‚ hi       โ”‚    0 โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€โ”€callerโ”€โ”€โ”ดโ”€filename_of_callerโ”€โ”ดโ”€โ”€calleeโ”€โ”€โ”ดโ”€stepโ”€โ•ฏ
# =>

dotnu filter-commands-with-no-tests

dotnu filter-commands-with-no-tests --help
# => Filter commands after `dotnu dependencies` that aren't used by any other command containing `test` in its name.
# =>
# => Usage:
# =>   > filter-commands-with-no-tests
# =>
# => Flags:
# =>   -h, --help: Display the help message for this command
# =>
# => Input/output types:
# =>   โ•ญโ”€#โ”€โ”ฌโ”€inputโ”€โ”ฌโ”€outputโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ any   โ”‚ any    โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€inputโ”€โ”ดโ”€outputโ”€โ•ฏ
# =>
# => Examples:
# =>
# =>   > dependencies ...(glob tests/assets/module-say/say/*.nu) | filter-commands-with-no-tests
# =>   โ•ญโ”€#โ”€โ”ฌโ”€โ”€callerโ”€โ”€โ”ฌโ”€filename_of_callerโ”€โ•ฎ
# =>   โ”‚ 0 โ”‚ hello    โ”‚ hello.nu           โ”‚
# =>   โ”‚ 1 โ”‚ question โ”‚ ask.nu             โ”‚
# =>   โ”‚ 2 โ”‚ say      โ”‚ mod.nu             โ”‚
# =>   โ•ฐโ”€#โ”€โ”ดโ”€โ”€callerโ”€โ”€โ”ดโ”€filename_of_callerโ”€โ•ฏ
# =>

dotnu set-x

dotnu set-x opens a regular .nu script. It divides it into blocks using the specified regex (by default, it is "\n\n") and generates a new script that will print the code of each block before executing it, along with the timings of each block's execution.

Let's check the code of the simple set-x-demo.nu script

let $filename = [tests assets set-x-demo.nu] | path join
open $filename | lines | table -i false
# => โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
# => โ”‚ sleep 0.5sec โ”‚
# => โ”‚              โ”‚
# => โ”‚ sleep 0.7sec โ”‚
# => โ”‚              โ”‚
# => โ”‚ sleep 0.8sec โ”‚
# => โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Let's see how dotnu set-x will modify this script

dotnu set-x $filename --echo | lines | table -i false
# => โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
# => โ”‚ mut $prev_ts = ( date now )                                                     โ”‚
# => โ”‚ print ("> sleep 0.5sec" | nu-highlight)                                         โ”‚
# => โ”‚ sleep 0.5sec                                                                    โ”‚
# => โ”‚ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ”‚
# => โ”‚                                                                                 โ”‚
# => โ”‚                                                                                 โ”‚
# => โ”‚ print ("> sleep 0.7sec" | nu-highlight)                                         โ”‚
# => โ”‚ sleep 0.7sec                                                                    โ”‚
# => โ”‚ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ”‚
# => โ”‚                                                                                 โ”‚
# => โ”‚                                                                                 โ”‚
# => โ”‚ print ("> sleep 0.8sec" | nu-highlight)                                         โ”‚
# => โ”‚ sleep 0.8sec                                                                    โ”‚
# => โ”‚ print $'(ansi grey)((date now) - $prev_ts)(ansi reset)'; $prev_ts = (date now); โ”‚
# => โ”‚                                                                                 โ”‚
# => โ”‚                                                                                 โ”‚
# => โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

About

dotnu - tools for Nushell module developers ๐Ÿ› ๏ธ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors 4

  •  
  •  
  •  
  •