Commit Graph

15 Commits

Author SHA1 Message Date
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
est31
8bdc715e3e Remove async_await feature gates 2019-08-24 09:09:26 +02:00
Jonathan Turner
e3e4e30fb3 Lots of fixes ahead of release 2019-08-21 18:39:57 +12:00
Jonathan Turner
dd18122a24 WIP 2019-08-15 17:02:02 +12:00
Jonathan Turner
aea8bbf945 Clean up ghz view 2019-08-11 15:33:26 +12:00
Jonathan Turner
8e652850dc add some battery stats 2019-08-11 15:01:09 +12:00
Jonathan Turner
1cc661b916 Remove comments 2019-08-11 10:13:58 +12:00
Jonathan Turner
894958d5e8 Improve sys a bit 2019-08-11 10:13:03 +12:00
Jonathan Turner
aadacc2d36 Merge master 2019-08-09 16:51:21 +12:00
Jonathan Turner
99671b8ffc Move more parts to tags and away from spans 2019-08-05 20:54:29 +12:00
Jonathan Turner
462f783fac initial change to Tagged<Value> 2019-08-01 13:58:42 +12:00
Jonathan Turner
583ef0da32 Fix unwraps in sys 2019-07-30 13:14:01 +12:00
Jonathan Turner
c85b7728bc Remove old sysinfo and finish sys 2019-07-28 14:02:42 +12:00
Jonathan Turner
2464a33660 Progress the sys plugin a bit further 2019-07-28 08:09:25 +12:00
Jonathan Turner
a09361698e Update plugin protocol for begin, and create new sys plugin 2019-07-27 19:45:00 +12:00