Commit Graph

190 Commits

Author SHA1 Message Date
Edward Betts
3e93ae8af4
Correct spelling (#4152) 2021-11-25 11:11:20 -06:00
ahkrr
649b3804c1
fix: panic! during parsing (#4107)
Typing `selector -qa` into nu would cause a `panic!`
This was the case because the inner loop incremented the `idx`
that was only checked in the outer loop and used it to index into
`lite_cmd.parts[idx]`
With the fix we now break loop.

Co-authored-by: ahkrr <alexhk@protonmail.com>
2021-11-05 21:46:46 +13:00
Jakub Žádník
349af05da8
Do not throw error for files not found in lib_dirs (#4029) 2021-09-20 13:44:47 -05:00
Jakub Žádník
cc5c4d38bb
Small fixes and refactors to paths & source command (#3998)
* Expand path when converting value -> PathBuf

Also includes Tagged<PathBuf>.

Fixes #3605

* Expand path for PATH env. variable

Fixes #1834

* Remove leftover Cows after nu-path refactor

There were some unnecessary Cow conversions leftover from the old
nu-path implementation.

* Use canonicalize in source command; Improve errors

Previously, `source` used `expand_path()` which does not follow
symlinks.

As a follow up, I improved the source error messages so they now tell
why the source file could not be canonicalized or read into string.
2021-09-12 02:36:14 +03:00
Tom Panton
55eafadf02
Improve error message when bash-style alias syntax is mistakenly used (#3995) 2021-09-10 10:44:55 +12:00
Marcin Puc
51c74eebd0
Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
Jakub Žádník
d95375d494
nu-path crate refactor (#3730)
* Resolve rebase artifacts

* Remove leftover dependencies on removed feature

* Remove unnecessary 'pub'

* Start taking notes and fooling around

* Split canonicalize to two versions; Add TODOs

One that takes `relative_to` and one that doesn't.
More TODO notes.

* Merge absolutize to and rename resolve_dots

* Add custom absolutize fn and use it in path expand

* Convert a couple of dunce::canonicalize to ours

* Update nu-path description

* Replace all canonicalize with nu-path version

* Remove leftover dunce dependencies

* Fix broken autocd with trailing slash

Trailing slash is preserved *only* in paths that do not contain "." or
"..". This should be fixed in the future to cover all paths but for now
it at least covers basic cases.

* Use dunce::canonicalize for canonicalizing

* Alow cd recovery from non-existent cwd

* Disable removed canonicalize functionality tests

Remove unused import

* Break down nu-path into separate modules

* Remove unused public imports

* Remove abundant cow mapping

* Fix clippy warning

* Reformulate old canonicalize tests to expand_path

They wouldn't work with the new canonicalize.

* Canonicalize also ~ and ndots; Unify path joining

Also, add doc comments in nu_path::expansions.

* Add comment

* Avoid expanding ndots if path is not valid UTF-8

With this change, no lossy path->string conversion should happen in the
nu-path crate.

* Fmt

* Slight expand_tilde refactor; Add doc comments

* Start nu-path integration tests

* Add tests TODO

* Fix docstring typo

* Fix some doc strings

* Add README for nu-path crate

* Add a couple of canonicalize tests

* Add nu-path integration tests

* Add trim trailing slashes tests

* Update nu-path dependency

* Remove unused import

* Regenerate lockfile
2021-08-28 15:59:09 +03:00
Markus Westerlind
1c1c58e802
Remove duplicate dependencies (#3961)
* chore: Replace surf with reqwest

Removes a lot of older, duplication versions of some dependencies
(roughtly 90 dependencies removed in total)

* chore: Remove syn 0.11

* chore: Remove unnecessary features from ptree

Removes some more duplicate dependencies

* cargo update

* Ensure we run the fetch and post plugins on the tokio runtime

* Fix clippy warning

* fix: Github requires a user agent on requests

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2021-08-28 15:34:11 +12:00
Hristo Filaretov
b8e2bdd6b1
Allow different names for ...rest (#3954)
* Allow different names for ...rest

* Resolves #3945

* This change requires an explicit name for the rest argument in `WholeStreamCommand`,
  which is why there are so many changed files.

* Remove redundant clone

* Add tests
2021-08-27 05:58:53 +12:00
Andrés N. Robalino
9d8845d7ad
Allow custom lib dir path for sourcing nu script libraries. (#3940)
Given we can write nu scripts. As the codebase grows, splitting into many smaller nu scripts is necessary.

In general, when we work with paths and files we seem to face quite a few difficulties. Here we just tackle one of them and it involves sourcing
files that also source other nu files and so forth. The current working directory becomes important here and being on a different directory
when sourcing scripts will not work. Mostly because we expand the path on the current working directory and parse the files when a source command
call is done.

For the moment, we introduce a `lib_dirs` configuration value and, unfortunately, introduce a new dependency in `nu-parser` (`nu-data`) to get
a handle of the configuration file to retrieve it. This should give clues and ideas as the new parser engine continues (introduce a way to also know paths)

With this PR we can do the following:

Let's assume we want to write a nu library called `my_library`. We will have the code in a directory called `project`: The file structure will looks like this:

```
project/my_library.nu
project/my_library/hello.nu
project/my_library/name.nu
```

This "pattern" works well, that is, when creating a library have a directory named `my_library` and next to it a `my_library.nu` file. Filling them like this:

```

source my_library/hello.nu
source my_library/name.nu
```

```

def hello [] {
  "hello world"
}
```

```

def name [] {
  "Nu"
end
```

Assuming this `project` directory is stored at `/path/to/lib/project`, we can do:

```
config set lib_dirs ['path/to/lib/project']
```

Given we have this `lib_dirs` configuration value, we can be anywhere while using Nu and do the following:

```
source my_library.nu

echo (hello) (name)

```
2021-08-26 02:04:04 -05:00
Jakub Žádník
e11b400a75
Allow source to accept paths with emojis (#3939)
* Allow sourcing paths with emojis

* Add source command tests for emoji paths

* Fmt

* Disable source tests on Windows with illegal paths

* Test sourcing also ASCII and single-quoted paths
2021-08-19 19:06:18 +12:00
soumil-07
9bd408449e
Add the ability to remove and list aliases (#3879)
* Add the ability to remove and list aliases

* Fix failing unit tests

* Add a test to check unalias shadowing blocks
2021-08-17 08:56:35 -05:00
Lily Mara
762e528ec5
Support equals sign in shorthand environment variable values (#3869)
Some environment variables, such as `RUST_LOG` include equals signs. Nushell
should support this in the shorthand environment variable syntax so that
developers using these variables can control them easily. We accomplish this by
swapping `std::str::split` for `std::str::splitn`, which ensures that we only
consider the first equals sign in the string instead of all of them, which we
did previously.

Closes #3867
2021-07-31 09:10:28 +12:00
Darren Schroeder
1e15f26e98
fix interpolated strings when using unicode (#3866)
* fix interpolated strings when using unicode

* added test case
2021-07-29 19:07:34 -05:00
JT
0c82c1920e
Support multiple shorthand env vars (#3692) 2021-06-26 14:15:57 +12:00
JT
b1970f79ee
Add support for arbitrarily nested subcommands (#3688) 2021-06-26 09:09:06 +12:00
Võ Anh Duy
6cdd8a2b07
Fix string interpolation is not working with external command (#3686) 2021-06-26 08:14:54 +12:00
JT
93b5f3f421
Make lexing configurable wrt newlines (#3682) 2021-06-25 17:50:24 +12:00
JT
cac2875c96
Improve def parse errors (#3681) 2021-06-25 17:18:38 +12:00
Andrés N. Robalino
03c9eaf005
Variable completions. (#3666)
In Nu we have variables (E.g. $var-name) and these contain `Value` types.
This means we can bind to variables any structured data and column path syntax
(E.g. `$variable.path.to`) allows flexibility for "querying" said structures.

Here we offer completions for these. For example, in a Nushell session the
variable `$nu` contains environment values among other things. If we wanted to
see in the screen some environment variable (say the var `SHELL`) we do:

```
> echo $nu.env.SHELL
```

with completions we can now do: `echo $nu.env.S[\TAB]` and we get suggestions
that start at the column path `$nu.env` with vars starting with the letter `S`
in this case `SHELL` appears in the suggestions.
2021-06-23 19:21:39 +12:00
JT
318d13ed58
Add built-in var to refer to pipeline values (#3661) 2021-06-21 12:31:01 +12:00
Niklas Jonsson
a8f6a13239
Move path handling to nu-path (#3653)
* fixes #3616
2021-06-20 11:07:26 +12:00
JT
d9d956e54f
Fix issue in external subexpression paths (#3642)
* Fix issue in external subexpression paths

* new clippy dropped

* clippy
2021-06-18 07:59:58 +12:00
Niklas Jonsson
a59414203f
Only discard command comment if prev token was comment (#3628)
This fixes issues where a file with multiple def commands with their own
doc comments, some of the comments would be discarded.
2021-06-17 14:11:05 +12:00
Andrés N. Robalino
7c8fb060f1
Extract completions into subcrate. (#3631) 2021-06-16 15:20:01 -05:00
Võ Anh Duy
774be79321
Fix syntax hightlight when using Circumflex-Operator (#3613) 2021-06-14 14:21:36 +12:00
JT
fadcdde7f8
Add help flag support to alias (#3595) 2021-06-10 16:28:33 +12:00
JT
d056bf070f
Improve alias highlighting/completions (#3594)
* Improve alias highlighting/completions

* Add example
2021-06-10 13:13:08 +12:00
JT
e8dfd4ba39
Enable syntax/completions for source (#3589) 2021-06-10 09:01:40 +12:00
JT
383e874166
Fix a bunch of future clippy warnings (#3586)
* Fix a bunch of future clippy warnings

* Fix a bunch of future clippy warnings
2021-06-10 07:08:12 +12:00
JT
e8a2250ef8
Improve expr parse (#3584)
* Require '-' to be a number for math

* Add test

* improve parse logic, add test
2021-06-10 05:17:45 +12:00
Jakub Žádník
25ba6ea459
Def cleanup (#3580)
* Remove impossible condition

* Improve def error

* Fmt
2021-06-09 10:06:44 +12:00
JT
16faafb7a8
Rename the use of invocation to subexpression (#3568)
* Rename the use of invocation to subexpression

* Fix test name
2021-06-07 20:08:35 +12:00
JT
c4dc61425d
Simpler parse improvement (#3566) 2021-06-07 18:39:23 +12:00
JT
128f5bce30
Improve partial completion/highlight (#3564) 2021-06-07 16:33:44 +12:00
JT
a2e6f5ebdb
Add hex, octal, binary (#3562) 2021-06-06 17:14:51 +12:00
Andrés N. Robalino
a5c14ba7d4
Ensure correct partial key=value flag. (#3518) 2021-05-29 23:19:58 -05:00
Andrés N. Robalino
6fdfc84904
Parse key=value named flag support. (#3515) 2021-05-29 20:42:03 -05:00
Jakub Žádník
6ae7884786
Fix path dots expansion (#3491)
* Fix parser expanding dots where it shouldn't

Previously, the parser would expand "a...b" as "a../..b". Now, >2 dots
are only expanded when the whole path component consists of dots (i.e.,
"..." expands to "../.." while "a...b" stays as it is).

* Respect OS separator when expanding >2 dots

"..." now expands to either "../.." or "..\..", based on the host OS.
2021-05-26 20:17:18 +12:00
JT
5fcc7f2328
Fix bad operator (#3479) 2021-05-24 17:27:10 +12:00
Andrés N. Robalino
3bcc2aad80
Pass command's span correctly when reporting unexpected flags. (#3478)
Not all lite command's first part denotes a real command (for cases like sub commands that it's second lite part accounts for the command name). This is important so that we can refer to it's span correctly. Here we fix to include the command's name span correctly whether it's a command or sub command when reporting missing flag errors.
2021-05-23 19:30:30 -05:00
JT
751de20f93
Do a bit more cleanup of block params (#3455)
* Do a bit more cleanup of block params

* Do a bit more cleanup of block params
2021-05-21 19:04:27 +12:00
JT
28388b4e3a
Split unit into duration and filesize (#3453) 2021-05-21 13:21:46 +12:00
JT
4fdbf30308
Paren interpolation (#3452)
* Switch interp to use parens

* improve interp parsing
2021-05-21 10:55:38 +12:00
JT
20f6114617
Improve block params (#3450) 2021-05-20 16:26:54 +12:00
JT
e2973d2176
Add explicit block params (#3444)
* Add explicit block params

* Add explicit block params
2021-05-19 20:23:45 +12:00
JT
d79a3130b8
Make the default int an i64 (#3428)
* Make the default int an i64

* fmt

* Fix random integer

* Treat pids as i64 for now
2021-05-14 20:35:09 +12:00
JT
efac712f62
Fix string interp/shorthand overlap (#3412) 2021-05-12 16:20:29 +12:00
JT
311c0e3f50
Simplify string interpolation (#3401)
* [DRAFT] simplify string interpolation

* Fix test
2021-05-12 13:53:57 +12:00
JT
25a8caa9b0
Simplify expressions (#3389)
* WIP: experiment with simpler expressions

* fix simple invoke

* update tests

* fix a few tests

* Make paren parsing more robust

* fix external args

* Remove old invocation

* Update tests

* Update tests
2021-05-12 13:01:48 +12:00