Commit Graph

244 Commits

Author SHA1 Message Date
Jonathan Turner
aed386b3cd Always save history, add history command 2019-10-28 05:58:39 +13:00
Andrés N. Robalino
0611f56776 Can group cells by given column name. 2019-10-20 18:42:07 -05:00
Andrés N. Robalino
821ee5e726 count command introduced. 2019-10-15 05:19:06 -05:00
Thomas Hartmann
65546646a7 Pull in upstream changes. 2019-10-14 23:05:52 +02:00
Thomas Hartmann
de1c4e6c88 Implements from-ssv 2019-10-13 22:50:45 +02:00
Jonathan Turner
193b00764b
Stream support (#812)
* Moves off of draining between filters. Instead, the sink will pull on the stream, and will drain element-wise. This moves the whole stream to being lazy.
* Adds ctrl-c support and connects it into some of the key points where we pull on the stream. If a ctrl-c is detect, we immediately halt pulling on the stream and return to the prompt.
* Moves away from having a SourceMap where anchor locations are stored. Now AnchorLocation is kept directly in the Tag.
* To make this possible, split tag and span. Span is largely used in the parser and is copyable. Tag is now no longer copyable.
2019-10-13 17:12:43 +13:00
Yehuda Katz
c2c10e2bc0 Overhaul the coloring system
This commit replaces the previous naive coloring system with a coloring
system that is more aligned with the parser.

The main benefit of this change is that it allows us to use parsing
rules to decide how to color tokens.

For example, consider the following syntax:

```
$ ps | where cpu > 10
```

Ideally, we could color `cpu` like a column name and not a string,
because `cpu > 10` is a shorthand block syntax that expands to
`{ $it.cpu > 10 }`.

The way that we know that it's a shorthand block is that the `where`
command declares that its first parameter is a `SyntaxShape::Block`,
which allows the shorthand block form.

In order to accomplish this, we need to color the tokens in a way that
corresponds to their expanded semantics, which means that high-fidelity
coloring requires expansion.

This commit adds a `ColorSyntax` trait that corresponds to the
`ExpandExpression` trait. The semantics are fairly similar, with a few
differences.

First `ExpandExpression` consumes N tokens and returns a single
`hir::Expression`. `ColorSyntax` consumes N tokens and writes M
`FlatShape` tokens to the output.

Concretely, for syntax like `[1 2 3]`

- `ExpandExpression` takes a single token node and produces a single
  `hir::Expression`
- `ColorSyntax` takes the same token node and emits 7 `FlatShape`s
  (open delimiter, int, whitespace, int, whitespace, int, close
  delimiter)

Second, `ColorSyntax` is more willing to plow through failures than
`ExpandExpression`.

In particular, consider syntax like

```
$ ps | where cpu >
```

In this case

- `ExpandExpression` will see that the `where` command is expecting a
  block, see that it's not a literal block and try to parse it as a
  shorthand block. It will successfully find a member followed by an
  infix operator, but not a following expression. That means that the
  entire pipeline part fails to parse and is a syntax error.
- `ColorSyntax` will also try to parse it as a shorthand block and
  ultimately fail, but it will fall back to "backoff coloring mode",
  which parsing any unidentified tokens in an unfallible, simple way. In
  this case, `cpu` will color as a string and `>` will color as an
  operator.

Finally, it's very important that coloring a pipeline infallibly colors
the entire string, doesn't fail, and doesn't get stuck in an infinite
loop.

In order to accomplish this, this PR separates `ColorSyntax`, which is
infallible from `FallibleColorSyntax`, which might fail. This allows the
type system to let us know if our coloring rules bottom out at at an
infallible rule.

It's not perfect: it's still possible for the coloring process to get
stuck or consume tokens non-atomically. I intend to reduce the
opportunity for those problems in a future commit. In the meantime, the
current system catches a number of mistakes (like trying to use a
fallible coloring rule in a loop without thinking about the possibility
that it will never terminate).
2019-10-10 19:30:04 -07:00
Yehuda Katz
1ad9d6f199 Overhaul the expansion system
The main thrust of this (very large) commit is an overhaul of the
expansion system.

The parsing pipeline is:

- Lightly parse the source file for atoms, basic delimiters and pipeline
  structure into a token tree
- Expand the token tree into a HIR (high-level intermediate
  representation) based upon the baseline syntax rules for expressions
  and the syntactic shape of commands.

Somewhat non-traditionally, nu doesn't have an AST at all. It goes
directly from the token tree, which doesn't represent many important
distinctions (like the difference between `hello` and `5KB`) directly
into a high-level representation that doesn't have a direct
correspondence to the source code.

At a high level, nu commands work like macros, in the sense that the
syntactic shape of the invocation of a command depends on the
definition of a command.

However, commands do not have the ability to perform unrestricted
expansions of the token tree. Instead, they describe their arguments in
terms of syntactic shapes, and the expander expands the token tree into
HIR based upon that definition.

For example, the `where` command says that it takes a block as its first
required argument, and the description of the block syntactic shape
expands the syntax `cpu > 10` into HIR that represents
`{ $it.cpu > 10 }`.

This commit overhauls that system so that the syntactic shapes are
described in terms of a few new traits (`ExpandSyntax` and
`ExpandExpression` are the primary ones) that are more composable than
the previous system.

The first big win of this new system is the addition of the `ColumnPath`
shape, which looks like `cpu."max ghz"` or `package.version`.
Previously, while a variable path could look like `$it.cpu."max ghz"`,
the tail of a variable path could not be easily reused in other
contexts. Now, that tail is its own syntactic shape, and it can be used
as part of a command's signature.

This cleans up commands like `inc`, `add` and `edit` as well as
shorthand blocks, which can now look like `| where cpu."max ghz" > 10`
2019-10-10 08:27:51 -07:00
Barnaby Keene
c8671c719f fix: addressed unused imports and dead code 2019-10-08 21:50:28 +01:00
Barnaby Keene
0412c3a2f8 fix: remove the additional characters from highlighter
This resolves a small integration issue that would make custom prompts problematic (if they are implemented). The approach was to use the highlighter implementation in Helper to insert colour codes to the prompt however it heavily relies on the prompt being in a specific format, ending with a `> ` sequence. However, this should really be the job of the prompt itself not the presentation layer.

For now, I've simply stripped off the additional `> ` characters and passed in just the prompt itself without slicing off the last two characters. I moved the `\x1b[m` control sequence to the prompt creation in `cli.rs` as this feels like the more logical home for controlling what the prompt looks like. I can think of better ways to do this in future but this should be a fine solution for now.

In future it would probably make sense to completely separate prompts (be it, internal or external) from this code so it can be configured as an isolated piece of code.
2019-10-08 21:39:58 +01:00
Barnaby Keene
fb8cfeb70d feat: starship prompt
Kind of touches on #356 by integrating the Starship prompt directly into the shell.

Not finished yet and has surfaced a potential bug in rustyline anyway. It depends on https://github.com/starship/starship/pull/509 being merged so the Starship prompt can be used as a library.

I could have tackled #356 completely and implemented a full custom prompt feature but I felt this was a simpler approach given that Starship is both written in Rust so shelling out isn't necessary and it already has a bunch of useful features built in.

However, I would understand if it would be preferable to just scrap integrating Starship directly and instead implement a custom prompt system which would facilitate simply shelling out to Starship.
2019-10-08 16:25:12 +01:00
Jonathan Turner
7113c702ff
Merge pull request #706 from landaire/ctrlc_config
feat(cli): add `ctrlc_exit` config option
2019-09-26 09:22:11 +12:00
Lander Brandt
0377efdc16 feat(cli): add ctrlc_exit config option
This feature allows a user to set `ctrlc_exit` to `true` or `false` in their config to override how multiple CTRL-C invocations are handled. Without this change pressing CTRL-C multiple times will exit nu. With this change applied the user can configure the behavior to behave like other shells where multiple invocations will essentially clear the line.

This fixes #457.
2019-09-24 18:04:53 -07:00
Pirmin Kalberer
3480cdb3b4 Fix build without crossterm 2019-09-24 23:33:30 +02:00
Andrés N. Robalino
898b99d7c2 Ignore incompatible plugins and continue plugin search. 2019-09-23 17:27:18 -05:00
Andrés N. Robalino
95ea3fcf4e Load plugin if and only if it hasn't been registered. 2019-09-23 17:01:40 -05:00
Pirmin Kalberer
9623a255c4 Include history path in env command 2019-09-20 10:37:05 +02:00
Pirmin Kalberer
484d8c26ac Save history when leaving with Ctrl-C 2019-09-19 22:55:53 +02:00
Pirmin Kalberer
df7a3a4863 Store history.txt in user data path 2019-09-19 22:29:11 +02:00
Pirmin Kalberer
d7e7f48aaa Deactivate fuzzy search on Windows for now 2019-09-19 20:45:58 +02:00
Pirmin Kalberer
0a0be19bed Rename histsearch to fuzzysearch 2019-09-19 20:18:39 +02:00
Pirmin Kalberer
1c95bf05dc Process selected command 2019-09-19 20:18:39 +02:00
Pirmin Kalberer
1e3549571c Bind fuzzy history search to Ctrl-R 2019-09-19 20:18:39 +02:00
Jonathan Turner
5ff94004c6 Add urlencode/urldecode 2019-09-19 16:25:29 +12:00
Jonathan Turner
f6b82e4c0c Replace vtable with pivot command 2019-09-17 19:07:11 +12:00
Jonathan Turner
7fbd6ce232 Fix internal paths 2019-09-17 14:09:15 +12:00
Jonathan Turner
17855d37a4 Add env command 2019-09-16 19:52:58 +12:00
Andrés N. Robalino
6bb277baaa
Merge pull request #668 from nushell/span-to-tag
Span to tag
2019-09-14 15:10:04 -05:00
Jonathan Turner
2b88f1eed0 Serialize bigint/bigdecimal as i64/f64 2019-09-15 05:48:24 +12:00
Yehuda Katz
ab915f1c44 Revert "Revert "Migrate most uses of the Span concept to Tag""
This reverts commit bee7c5639c.
2019-09-14 11:30:24 -05:00
Andrés N. Robalino
d0d56deaf1 Permit Nu finding and picking up development plugins if there are any first. 2019-09-12 18:49:29 -05:00
Andrés N. Robalino
e4ed8c94ad dot character is valid in Windows plugin binaries. 2019-09-12 02:20:22 -05:00
Andrés N. Robalino
c57c0eb371 pass lint checks. 2019-09-12 01:49:01 -05:00
Andrés N. Robalino
b35549adac Removes regex crate dependency. 2019-09-11 22:20:42 -05:00
Jonathan Turner
bee7c5639c
Revert "Migrate most uses of the Span concept to Tag" 2019-09-11 19:53:05 +12:00
Yehuda Katz
58b7800172 Migrate most uses of the Span concept to Tag
Also migrate mv, rm and commands like that to taking a
SyntaxType::Pattern instead of a SyntaxType::Path for their first
argument.
2019-09-10 20:41:03 -07:00
Jonathan Turner
448b1a4848 Make some plugins optional, move ps to plugin 2019-09-08 19:06:15 +12:00
Jonathan Turner
4cdaed1ad4 Add echo command 2019-09-08 11:43:53 +12:00
Pradeep Chhetri
ee301f9f54 Adds pwd command 2019-09-07 23:53:56 +08:00
Jonathan Turner
dcd97b6346 Move internal terminology to tables/rows 2019-09-06 04:23:42 +12:00
Jonathan Turner
479f0a566e Covert to_* commands to work on whole table 2019-09-04 18:48:40 +12:00
Jan Koprowski
ab97459d0e Stop printing CTRL-D on EOF 2019-09-03 21:40:42 +02:00
Jonathan Turner
8a9cdcab17 Split fetch command away from open 2019-09-03 18:04:46 +12:00
Yehuda Katz
7fa09f59c2 Remove unused code
Closes #467
2019-09-01 23:11:05 -07:00
Jonathan Turner
7d46f9e860 Another attempt to fix the zombie processes 2019-09-02 04:45:30 +12:00
Andrés N. Robalino
ca0c6eaf58 This commit introduces a basic help feature. We can go to it
with the `help` command to explore and list all commands available.

Enter will also try to see if the location to be entered is an existing
Nu command, if it is it will let you inspect the command under `help`.

This provides baseline needed so we can iterate on it.
2019-08-31 19:06:11 -05:00
Jonathan Turner
1a67ac6102 Random fixes 2019-09-01 09:19:59 +12:00
Jonathan Turner
1d77595576 Merge branch 'master' into post 2019-08-31 15:12:03 +12:00
Jonathan Turner
2cec8168c7 Merge master 2019-08-31 13:30:41 +12:00
Patrick Meredith
3d147d1143 Add SQLite support 2019-08-30 20:54:45 -04:00
Jonathan Turner
fa2c6ec227 Merge master 2019-08-31 10:13:09 +12:00
Jonathan Turner
9e167713b3 Add post command 2019-08-31 06:27:15 +12:00
Jonathan Turner
729051fdd2
Merge pull request #407 from iamcodemaker/vi
WIP: add support for vi mode
2019-08-30 15:54:30 +12:00
Taiki Endo
58a32490c5 Remove usage of in_band_lifetimes feature 2019-08-30 01:32:31 +09:00
est31
c87fa14fc8 Replace crate visibility identifier with pub(crate)
Result of running:

find src -name *.rs -exec sed -i 's/crate /pub(crate) /g' {} \;
2019-08-29 13:09:09 +02:00
Andrés N. Robalino
f1e8c433c2 [from/to]tsv support. 2019-08-29 04:02:16 -05:00
Jonathan Turner
f730296e45 WIP supporting from/to automatically 2019-08-29 15:53:45 +12:00
Jonathan Turner
4576570275
Merge pull request #520 from est31/remove_try_trait
Remove try_trait feature use
2019-08-29 14:46:53 +12:00
est31
012d8f3d6f Remove try_trait feature use 2019-08-29 03:12:10 +02:00
Yehuda Katz
21ad06b1e1 Remove unwraps and clean up playground
The original intent of this patch was to remove more unwraps to reduce
panics. I then lost a ton of time to the fact that the playground isn't
in a temp directory (because of permissions issues on Windows).

This commit improves the test facilities to:

- use a tempdir for the playground
- change the playground API so you instantiate it with a block that
  encloses the lifetime of the tempdir
- the block is called with a `dirs` argument that has `dirs.test()` and
  other important directories that we were computing by hand all the time
- the block is also called with a `playground` argument that you can use
  to construct files (it's the same `Playground` as before)
- change the nu! and nu_error! macros to produce output instead of
  taking a variable binding
- change the nu! and nu_error! macros to do the cwd() transformation
  internally
- change the nu! and nu_error! macros to take varargs at the end that
  get interpolated into the running command

I didn't manage to finish porting all of the tests, so a bunch of tests
are currently commented out. That will need to change before we land
this patch.
2019-08-28 10:01:16 -07:00
Jonathan Turner
3750a04cfc
Merge branch 'master' into expand-tilde 2019-08-27 16:23:56 +12:00
Yehuda Katz
34292b282a Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.

The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.

As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.

For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.

This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).

The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.

This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.

By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.

In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:03:24 -07:00
Jonathan Turner
5313fc5568
Merge pull request #477 from jonathandturner/fix_dbg_release
Fix having to clean directories when switching between release and debug
2019-08-27 14:11:30 +12:00
Jonathan Turner
716517c13f Fix having to clean directories when switching between release and debug 2019-08-27 13:46:38 +12:00
Patrick Meredith
87a99bbabf Implement to-bson 2019-08-26 20:07:59 -04:00
Andrés N. Robalino
3e699db57c Aviso. 2019-08-26 17:41:57 -05:00
Andrés N. Robalino
91093f2ab2 Avoid panicking if history can't be saved. 2019-08-26 17:18:38 -05:00
Kyle Strand
9a31a6c296 Permit use of Windows Batch files 2019-08-26 11:17:47 -06:00
Jonathan Turner
dda4a707a7
Merge pull request #421 from ramonsnir/reverse
add reverse
2019-08-26 05:41:07 +12:00
Ramon Snir
9735c3fcea
add reverse 2019-08-25 12:14:17 -04:00
Patrick Meredith
93a1a0604e Update how extensions are set to default to path when no extension can be determined from mime 2019-08-25 09:50:25 -04:00
Matthew Nicholson
6ebf6f8a8f set rustyline's edit_mode based on a config option
This adds support for vi mode.
2019-08-25 01:12:23 -04:00
Issac Trotts
108f66941b add last command 2019-08-24 15:01:30 -07:00
Jonathan Turner
6354e0cc55 Remove X11 requirement 2019-08-23 15:29:08 +12:00
Jonathan Turner
e3e4e30fb3 Lots of fixes ahead of release 2019-08-21 18:39:57 +12:00
Odin Dutton
d71206ed9e Implement WholeStreamCommand for all remaining commands 2019-08-19 15:16:39 +10:00
Odin Dutton
4de6c941e1 Introduce version command 2019-08-19 11:30:29 +10:00
Yehuda Katz
5bfb96447a Reduce unwraps
Remove a number of unwraps. In some cases, a `?` just worked as is. I also made it possible to use `?` to go from Result<OutputStream, ShellError> to OutputStream. Finally, started updating PerItemCommand to be able to use the signature deserialization logic, which substantially reduces unwraps.

This is still in-progress work, but tests pass and it should be clear to merge and keep iterating on master.
2019-08-16 20:53:39 -07:00
Yehuda Katz
0dc4b2b686 Add support for external escape valve (^dir)
This commit makes it possible to force nu to treat a command as an external command by prefixing it with `^`. For example `^dir` will force `dir` to run an external command, even if `dir` is also a registered nu command.

This ensures that users don't need to leave nu just because we happened to use a command they need.

This commit adds a new token type for external commands, which, among other things, makes it pretty straight forward to syntax highlight external commands uniquely, and generally to treat them as special.
2019-08-15 15:18:18 -07:00
Jonathan Turner
dd18122a24 WIP 2019-08-15 17:02:02 +12:00
Andrés N. Robalino
154063013f mv introduced. \¡Viva\! 2019-08-14 15:29:05 -05:00
Jonathan Turner
99b881e42f Add first per-item commands 2019-08-15 05:02:39 +12:00
Jonathan Turner
4411a5b72c
Merge pull request #281 from jonathandturner/improve_arrays
Add from_array and improve array viewing
2019-08-12 18:16:08 +12:00
Jonathan Turner
3d5395fdd5 Add from_array and improve array viewing 2019-08-12 17:51:13 +12:00
Jonathan Turner
14e47f3d2c Add nth command 2019-08-12 17:13:58 +12:00
Jonathan Turner
e19c618ac5
Revert "Rewrite the ps command" 2019-08-11 13:41:21 +12:00
Jonathan Turner
7c2fec5851 Rewrite the ps command 2019-08-11 11:09:40 +12:00
Jonathan Turner
c97578bf6e Add which command 2019-08-10 19:06:08 +12:00
Jonathan Turner
eeed31837f cleanup 2019-08-10 08:49:43 +12:00
Jonathan Turner
34759b7646 Add back in cd/ls and completions 2019-08-10 07:42:23 +12:00
Jonathan Turner
cabd5bf009 Fix sink plugins 2019-08-09 19:54:21 +12:00
Jonathan Turner
aadacc2d36 Merge master 2019-08-09 16:51:21 +12:00
Jonathan Turner
80bcc51294 get tests passing by fixing classifying external 2019-08-08 17:09:38 +12:00
Andrés N. Robalino
c8b5329c5c mkdir. 2019-08-07 13:24:20 -05:00
Jonathan Turner
c231dd32cd
Multi shells (#254)
Add multi-shells
2019-08-08 05:49:11 +12:00
Yehuda Katz
14a52bc282 WIP - more streamlining 2019-08-06 09:26:33 -07:00
Jonathan Turner
99671b8ffc Move more parts to tags and away from spans 2019-08-05 20:54:29 +12:00
Yehuda Katz
586aa6bae1 WIP - types check 2019-08-02 19:17:28 -07:00
Yehuda Katz
fc173c46d8 Restructuring 2019-08-02 12:15:07 -07:00
Jonathan Turner
db3ff52973 Add tags command and fix source_map transfer 2019-08-01 15:25:59 +12:00