Giter Club home page Giter Club logo

demo's Introduction

Nushell

Crates.io Build Status Nightly Build Discord The Changelog #363 @nu_shell GitHub commit activity GitHub contributors

A new type of shell.

Example of nushell

Table of Contents

Status

This project has reached a minimum-viable-product level of quality. Many people use it as their daily driver, but it may be unstable for some commands. Nu's design is subject to change as it matures.

Learning About Nu

The Nushell book is the primary source of Nushell documentation. You can find a full list of Nu commands in the book, and we have many examples of using Nu in our cookbook.

We're also active on Discord and Twitter; come and chat with us!

Installation

To quickly install Nu:

# Linux and macOS
brew install nushell
# Windows
winget install nushell

To use Nu in GitHub Action, check setup-nu for more detail.

Detailed installation instructions can be found in the installation chapter of the book. Nu is available via many package managers:

Packaging status

For details about which platforms the Nushell team actively supports, see our platform support policy.

Configuration

The default configurations can be found at sample_config which are the configuration files one gets when they startup Nushell for the first time.

It sets all of the default configuration to run Nushell. From here one can then customize this file for their specific needs.

To see where config.nu is located on your system simply type this command.

$nu.config-path

Please see our book for all of the Nushell documentation.

Philosophy

Nu draws inspiration from projects like PowerShell, functional programming languages, and modern CLI tools. Rather than thinking of files and data as raw streams of text, Nu looks at each input as something with structure. For example, when you list the contents of a directory what you get back is a table of rows, where each row represents an item in that directory. These values can be piped through a series of steps, in a series of commands called a 'pipeline'.

Pipelines

In Unix, it's common to pipe between commands to split up a sophisticated command over multiple steps. Nu takes this a step further and builds heavily on the idea of pipelines. As in the Unix philosophy, Nu allows commands to output to stdout and read from stdin. Additionally, commands can output structured data (you can think of this as a third kind of stream). Commands that work in the pipeline fit into one of three categories:

  • Commands that produce a stream (e.g., ls)
  • Commands that filter a stream (e.g., where type == "dir")
  • Commands that consume the output of the pipeline (e.g., table)

Commands are separated by the pipe symbol (|) to denote a pipeline flowing left to right.

> ls | where type == "dir" | table
╭────┬──────────┬──────┬─────────┬───────────────╮
│ #  │   name   │ type │  size   │   modified    │
├────┼──────────┼──────┼─────────┼───────────────┤
│  0 │ .cargo   │ dir  │     0 B │ 9 minutes ago │
│  1 │ assets   │ dir  │     0 B │ 2 weeks ago   │
│  2 │ crates   │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  3 │ docker   │ dir  │     0 B │ 2 weeks ago   │
│  4 │ docs     │ dir  │     0 B │ 2 weeks ago   │
│  5 │ images   │ dir  │     0 B │ 2 weeks ago   │
│  6 │ pkg_mgrs │ dir  │     0 B │ 2 weeks ago   │
│  7 │ samples  │ dir  │     0 B │ 2 weeks ago   │
│  8 │ src      │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  9 │ target   │ dir  │     0 B │ a day ago     │
│ 10 │ tests    │ dir  │ 4.0 KiB │ 2 weeks ago   │
│ 11 │ wix      │ dir  │     0 B │ 2 weeks ago   │
╰────┴──────────┴──────┴─────────┴───────────────╯

Because most of the time you'll want to see the output of a pipeline, table is assumed. We could have also written the above:

> ls | where type == "dir"

Being able to use the same commands and compose them differently is an important philosophy in Nu. For example, we could use the built-in ps command to get a list of the running processes, using the same where as above.

> ps | where cpu > 0
╭───┬───────┬───────────┬───────┬───────────┬───────────╮
│ # │  pid  │   name    │  cpu  │    mem    │  virtual  │
├───┼───────┼───────────┼───────┼───────────┼───────────┤
│ 0 │  2240 │ Slack.exe │ 16.40 │ 178.3 MiB │ 232.6 MiB │
│ 1 │ 16948 │ Slack.exe │ 16.32 │ 205.0 MiB │ 197.9 MiB │
│ 2 │ 17700 │ nu.exe    │  3.77 │  26.1 MiB │   8.8 MiB │
╰───┴───────┴───────────┴───────┴───────────┴───────────╯

Opening files

Nu can load file and URL contents as raw text or structured data (if it recognizes the format). For example, you can load a .toml file as structured data and explore it:

> open Cargo.toml
╭──────────────────┬────────────────────╮
│ bin              │ [table 1 row]      │
│ dependencies     │ {record 25 fields} │
│ dev-dependencies │ {record 8 fields}  │
│ features         │ {record 10 fields} │
│ package          │ {record 13 fields} │
│ patch            │ {record 1 field}   │
│ profile          │ {record 3 fields}  │
│ target           │ {record 3 fields}  │
│ workspace        │ {record 1 field}   │
╰──────────────────┴────────────────────╯

We can pipe this into a command that gets the contents of one of the columns:

> open Cargo.toml | get package
╭───────────────┬────────────────────────────────────╮
│ authors       │ [list 1 item]                      │
│ default-run   │ nu                                 │
│ description   │ A new type of shell                │
│ documentation │ https://www.nushell.sh/book/       │
│ edition       │ 2018                               │
│ exclude       │ [list 1 item]                      │
│ homepage      │ https://www.nushell.sh             │
│ license       │ MIT                                │
│ metadata      │ {record 1 field}                   │
│ name          │ nu                                 │
│ repository    │ https://github.com/nushell/nushell │
│ rust-version  │ 1.60                               │
│ version       │ 0.72.0                             │
╰───────────────┴────────────────────────────────────╯

And if needed we can drill down further:

> open Cargo.toml | get package.version
0.72.0

Plugins

Nu supports plugins that offer additional functionality to the shell and follow the same structured data model that built-in commands use. There are a few examples in the crates/nu_plugins_* directories.

Plugins are binaries that are available in your path and follow a nu_plugin_* naming convention. These binaries interact with nu via a simple JSON-RPC protocol where the command identifies itself and passes along its configuration, making it available for use. If the plugin is a filter, data streams to it one element at a time, and it can stream data back in return via stdin/stdout. If the plugin is a sink, it is given the full vector of final data and is given free reign over stdin/stdout to use as it pleases.

The awesome-nu repo lists a variety of nu-plugins while the showcase repo shows off informative blog posts that have been written about Nushell along with videos that highlight technical topics that have been presented.

Goals

Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.

  • First and foremost, Nu is cross-platform. Commands and techniques should work across platforms and Nu has first-class support for Windows, macOS, and Linux.

  • Nu ensures compatibility with existing platform-specific executables.

  • Nu's workflow and tools should have the usability expected of modern software in 2022 (and beyond).

  • Nu views data as either structured or unstructured. It is a structured shell like PowerShell.

  • Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.

Officially Supported By

Please submit an issue or PR to be added to this list.

Contributing

See Contributing for details. Thanks to all the people who already contributed!

License

The project is made available under the MIT license. See the LICENSE file for more information.

demo's People

Contributors

fdncred avatar jzaefferer avatar sophiajt avatar tanishqkancharla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

demo's Issues

Better error handling

Currently errors are serialized into a single text line with some structure, but no recognizable format, like this:

Error: ShellError { error: Diagnostic(ShellDiagnostic { diagnostic: Diagnostic { severity: Error, code: None, message: "Cannot canonicalize file "/file.json" because Custom { kind: Other, error: "operation not supported on wasm yet" }", labels: [Label { style: Primary, file_id: 0, range: 5..14, message: "Cannot canonicalize" }], notes: [] } }), cause: None }

In this case for running open file.json.

Jonathan mentioned the option to serialize errors as JSON, so that they can be formatted on the JS side.

Better list output

on the cli:

random dice -d 10 -s 12


───┬────
 0 │  4
 1 │  2
 2 │ 12
 3 │  4
 4 │  1
 5 │  2
 6 │  5
 7 │ 12
 8 │  1
 9 │  8
───┴────

here:

7341010121261212

Looks like this applies to all lists, e.g.

echo "[1,2,3]" | from json

results in 123

unhandled panics are swallowed, crashes wasm "runtime"

Running random bool panicks and only dumps that error with console.error

panicked at 'could not initialize thread_rng: getrandom: this target is not supported', /Users/jzaefferer/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.7.3/src/rngs/thread.rs:65:17

Screenshot 2020-07-17 at 20 47 49

I guess the console.error comes from the console_error_panic_hook crate

Is there some way to have the wasm.run_nu Promise rejected instead, to handle the error in our "application" code?

If not, can we deal with panics on the Rust side and forward them through the existing serialized error channel?

It also looks like something "exits" once this type of error occurs, and running other commands isn't possible anymore (a page reload helps).

Should we make this notebook style?

This is what I'm thinking. The UI something like this now.
[button1] [button2] [button3]
text box command
results

If it worked more like a notebook ala jupyter it would have
text box command
results

text box command
results

text box command
results

And so on. You could scroll up and down through all your text box commands & results and execute them, change them or whatever. Or, if we were really slick, the output of one result could be stored as a variable and used in the next text box command just like jupyter.

Interactive table exploration

Some ideas for exploring tables in the browser:

For table headers:

  • select column => Appends | get {name} to the current command and reruns it.
  • group-by column, append | group-by {name}
  • sort-by column, append | sort-by {name}

A pivot shortcut already shows up when the table is too wide.

..to be continued...

Deploy to GitHub Pages

Until this is properly integrated into the nushell website, we should deploy it on GitHub Pages, to have a public preview.

Probably use GitHub Actions to build from mastmain.

Reset button?

I seem to get it into a state where no command is interpreted any longer. I can click the top buttons and they put text in the window but if I hit run or ctrl/cmd-enter nothing happens. There are no errors visible. So, would it be possible to have some type of a reset button? I'm not sure what that would do since when this happens today I have to ctrl-c out and do npm start again.

Show version in the footer

At the time of writing, the demo seems to be using Nushell v0.38, so lots of the more recent features won't be available. It would be nice if the version (and possibly the commit date as well) was indicated somewhere in the page, e.g. in the footer.

Demo flags security issues

I was running through the demo at https://www.nushell.sh/demo/ and was contacted by the infosec team at my firm regarding "nuvfs.zip" and was informed that it matched multiple malicious signatures.

The infosec team requested I no longer continue accessing the website and refrain from investigating nushell. I did request permission to file an issue regarding the matter, as I doubt this was intentional. Either the wasm module has actually been infected or there is some pattern employed in the layout of the VFS which is triggering a security rule.

Unfortunately, I have no additional details I am able to provide.

Add error tracking with trackjs or sentry

It would be pretty helpful for us to see what errors demo users run into, to prioritize fixes.

I have plenty experience with Sentry, so I'd check their free/OSS options first.

I'd make sure to enable all anonymization options - we don't need to collect anyone's IP address. Only basic user agent info to reproduce issues.

config.toml location

Maybe we could have a config.toml in a special BrowserFS folder like /nu/config/config.toml and then load that config so we have some sort of environment variables and aliases to play around with.

Update to html

Can you bring over the new to html code that was committed yesterday? I'd like to see what the new to html --html_color and to html --no_color does for things like this.

Virtual file system with some sample files

Having a playground for opening, selecting and modifying files in the browser makes this project pretty interesting, but right now there's no files, and open generally doesn't work in wasm.

There might be some way to mock a few files (json, csv, toml), at least enough for ls and open to do something useful.

Should we add auto-rotation?

We use auto-rotation in the terminal to help fit things on the screen when it's a single long row. Feels like we might want to consider that for wasm-nu also:

Screenshot from 2020-07-20 06-55-50

Notice size of scrollbar.

As editor for json and other formats

To make this more than a slightly crippled demo for nushell, we could offer a textarea (and upload/dnd section) for providing JSON, toml, csv or other data that nushell can parse (maybe auto detect the format), then a pipeline for processing it and an output area for the result, as HTML table and whatever structured output is desired (default to input format, can switch to something else.

The format selects could be fed with a list of subcommands from "from" and "to".

Since everything runs on the client, we could update everything automatically while typing, as long as the pipeline is a valid command

Readme button?

Was thinking that maybe there should be a readme button somewhere on the page that tells what's working and what's not working (i.e. @jzaefferer 's issue that lists it). Error handling is still in it's infancy and I don't want people trying it and getting aggravated and then assuming nushell as a whole doesn't support all the commands we claim it does.

More complicated example

How about a more complicated example blue button to show a little more power?

open samples/movies.csv | group-by Year | get "2010" | update "Worldwide Gross" { get 'Worldwide Gross' | str trim --char '$' | str to-decimal } | sort-by 'Worldwide Gross' | reverse | update 'Worldwide Gross' { get 'Worldwide Gross' | str from -d 2 | format "${$it}" }

I wish we could write it with comments like:

open samples/movies.csv     # open the file as a csv
| group-by Year             # group the data by Year
| get "2010"                # get only the column labeled "2010"
| update "Worldwide Gross"  # update the Worldwide Gross column
{ get 'Worldwide Gross'     # get the Worldwide Gross column
| str trim --char '$'       # remove the $ character
| str to-decimal }          # convert the string numbers to actual decimal numbers
| sort-by 'Worldwide Gross' # sort by these newly created decimal numbers in the Worldwide Gross column
| reverse                   # reverse the order putting the largest numbers at the top
| update 'Worldwide Gross'  # update/overwrite the Worldwide Gross column again
{ get 'Worldwide Gross'     # get the data from the Worldwide Gross column
| str from -d 2             # convert the decimals to strings with 2 decimal places
| format "${$it}" }         # expand $it with the format command to add the $ back again

List of commands that don't work here

alias: alias say-hi [] { echo 'Hello!' }; say-hi => error: Failed to spawn process

autoenv: might be possible to emulate with #3 or #34, but seems like overkill

cal, date: panicked at 'not implemented', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/time-0.1.43/src/sys.rs:101:9

cd, cp, du, enter, exit, mkdir, mv, pwd, rm, save, touch: depends on #34

clear is meaningless in the browser

config: not supported in wasm; not sure how useful this really is though

debug: not sure how this works, since all the examples are using FS. Simply running debug outputs �[38;5;10mnothing.

describe: similar to debug, it partially outputs ansi color codes, e.g. for echo '[{"name":"Bob","age":25},{"name":"Fred","age":35}]' | from json | describe it outputs this:
Screenshot 2020-07-18 at 11 27 26

empty?: not sure how to use this, since neither inline docs nor the website have examples (no docs for the command there at all)

fetch: 'failed to spawn'. We could make a custom implementation using the browser's fetch API.

history: error: Could not open history - maybe we can create that file with the vfs and update it with each command that the user runs?

kill: not supported in wasm; could emulate processes as web workers, list them with ps and kill them.

lines: the example shells out to native echo (^echo "two\nlines" | lines), which doesn't work here. I'm not sure how else to use lines

n/p: next, previous shell, doesn't do anything, not even output an error, though that also applies for the CLI. Help text doesn't explain how to use these.

random bool: needs a custom implementation like random dice

run_external: this looks like it makes no sense in this context, and should show a proper error message. Currently run_external echo gives back Failed to spawn process.

shells: This actually works, but without other shell-related commands, its difficult to test properly.

shuffle: fails badly (#12), probably same issue as with random bool.

split-by: no example, no markdown docs, and based on the description I have no idea how to use this

table: I'm not sure what this actually does, since, for example, sys and sys | table seem to do the same thing. Though here it breaks badly (#12)

with-env: error: operation not supported on wasm yet

Extend vfs, support other fs-related commands

#3 provided a basic virtual file system, with support for ls and open.

ls only provides names and no other details, which is a bit of a problem since so many of our examples use various columns from ls.

Other fs related commands need to be replaced to use the vfs: cd, cp, du, enter, exit, mkdir, mv, pwd, rm, save, touch (maybe more)

syntax highlighting

Nu makes syntax highlighting available internally, so in theory we could expose this to wasm-nu, and then use the syntax highlighting information to color the user input.

So long as we don't interfere with them typing, it should be okay?

row colors a bit too light

Now that the alternating rows are a bit lighter, it's harder to see the difference between them. I think having at least some alternative color would be nice to make the tables more readable.

Here's what it looks like for me in Linux/Firefox

Screenshot from 2020-07-26 14-59-08

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.