Commit graph

55 commits

Author SHA1 Message Date
AnotherTest
f164b808b5 Shell: Move everything to the Shell namespace
Also provide a basic default-constructor.
2020-10-04 23:12:28 +02:00
AnotherTest
a10cfee0d4 Shell: Track line numbers and the positions of some keywords 2020-09-30 20:05:24 +02:00
AnotherTest
d64e00a5f6 Shell: Rename two 'fd' class members to have an 'm_' prefix 2020-09-26 21:28:35 +02:00
AnotherTest
51e598cf0b Shell: Use NonnullRefPtr to store non-null subnodes
Also replaces null-is-invalid nodes with syntax error nodes.
2020-09-26 21:28:35 +02:00
AnotherTest
4c6f7846b4 Shell: Add 'match' expressions
This commit adds an equivalent to the sh 'case' construct, except it's
much more pleasing to look at and write:
```sh
match "$something" {
    p1 { echo "p1!" }
    p2 { echo "p2!" }
    *  { echo "string catch-all!" }
}
```
is the equivalent of:
```sh
case $something in
    p1)
        echo "p1!"
        ;;
    p2)
        echo "p2!"
        ;;
    *)
        echo "catch-all!"
        ;;
esac
```

Since our shell does not treat lists as strings, matching lists is also
possible:

```sh
match (1foo 2foo foo3) {
    (?foo 2* *) { echo wowzers! }
    (* * *) { echo 3-element list catch-all }
}
```
2020-09-15 20:36:59 +02:00
AnotherTest
afe0ae586c Shell: Make Node::resolve_as_list(nullptr) resolve to a 'pure' repr
'pure' as in "not requiring a shell", similar to
JS::Value::to_string_without_side_effects().
2020-09-15 20:36:59 +02:00
asynts
f18e927827 AK: Remove OutputMemoryStream for DuplexMemoryStream.
OutputMemoryStream was originally a proxy for DuplexMemoryStream that
did not expose any reading API.

Now I need to add another class that is like OutputMemoryStream but only
for static buffers. My first idea was to make OutputMemoryStream do that
too, but I think it's much better to have a distinct class for that.

I originally wanted to call that class FixedOutputMemoryStream but that
name is really cumbersome and it's a bit unintuitive because
InputMemoryStream is already reading from a fixed buffer.

So let's just use DuplexMemoryStream instead of OutputMemoryStream for
any dynamic stuff and create a new OutputMemoryStream for static
buffers.
2020-09-15 20:36:45 +02:00
AnotherTest
cd0ddf27f3 Shell: Allow builtins and functions as conditions for 'if' 2020-09-14 17:40:18 +02:00
AnotherTest
2b867ff555 Shell: Complete named function parameters inside the function body 2020-09-14 17:40:18 +02:00
AnotherTest
d1550ea64f Shell: Add support for functions
This implementation does not have support for 'return' yet.
2020-09-14 17:40:18 +02:00
AnotherTest
927e2fc6bc Shell: Do not reset the terminal attributes when command is run in bg
Also removes a FIXME that no longer applies.
2020-09-10 11:20:22 +02:00
AnotherTest
b194d79c53 Shell: Add the (now) free subshell support 2020-09-09 20:35:21 +02:00
AnotherTest
aa2df9277d Shell: Allow control structures to appear in pipe sequences
This makes commands like the following to be possible:
```sh
$ ls && for $(seq 10) { echo $it }
$ ls | for $(seq 1) { cat > foobar }
```
2020-09-09 20:35:21 +02:00
AnotherTest
7b5ead64a5 Shell: Announce job events at the right times
This fixes a duplicate message when running `jobs` for the first time
after a job has been moved to the background.
Also actually announces background exits now :^)
2020-09-09 20:35:21 +02:00
AnotherTest
715e11f692 Shell: Fix job control and backgrounding
This patchset makes the shell capable of lazily resolving and executing
sequences of commands, to allow for putting logical sequences in the
background.
In particular, it enables And/Or/Sequence nodes to be run in the background,
and consequently unmarks them as `would_execute`.
Doing so also fixes job control to an extent, as jobs are now capable of
having 'tails', so sequences can be put in the background while
preserving their following sequences.
2020-09-09 20:35:21 +02:00
asynts
b68a873067 AK: Move memory streams into their own header. 2020-09-01 17:25:26 +02:00
AnotherTest
b90eb5c9ba Shell: Add 'if' expressions
```sh
if foo bar baz {
    quux
} else if foobar || whatever {
    echo I ran out of example words
} else {
    exit 2
}
```
2020-08-22 20:53:21 +02:00
AnotherTest
103f659ef6 Shell: Actually process for loop entries as a stream
This actually does what d4bcc68 meant to do.
2020-08-22 20:52:07 +02:00
AnotherTest
2c14abedd6 Shell: Do not flatten syntactic lists in for_each_entry() 2020-08-22 20:52:07 +02:00
AnotherTest
0676bd4afc Shell: Mark AST::Background as would_execute if its subnode does 2020-08-22 20:52:07 +02:00
AnotherTest
d4bcc689fb Shell: Make 'for' loops read their input as an stream
i.e. process an element as it becomes available.
2020-08-21 16:00:42 +02:00
AnotherTest
217eca3d3f Shell: Name the pipe ends correctly 2020-08-19 21:21:34 +02:00
Andreas Kling
85b02d887b Shell: Add create() factory function for PathRedirection 2020-08-12 12:15:30 +02:00
Andreas Kling
e8d665337a Shell: Fix another FdRedirection reference leak
Add a create() factory function to prevent this from happening again.
2020-08-12 12:13:33 +02:00
AnotherTest
1dc5574245 Shell: Eliminate reference leak in AST::Execute::run() 2020-08-12 11:41:18 +02:00
AnotherTest
ab3e787334 Shell: Moves pipelined processes to one process group 2020-08-12 11:41:18 +02:00
AnotherTest
69fc91d974 Shell: Cancel a running for loop upon receiving any non-SIGINT signal
And keep the old behaviour of needing two interruptions on SIGINT.
2020-08-10 20:50:06 +02:00
AnotherTest
5ae2f6e9ec Shell: Stop a for loop upon receiving two consecutive interruptions
This does not work perfectly (just like every other shell...), if the
running program handles the signal (SIGINT in this case) and quits
cleanly, the shell cannot detect the interruption.
This is the case with our `sleep(1)`.
2020-08-09 21:08:07 +02:00
Andreas Kling
e9c602bc83 Shell: Make resolve_without_cast() return NonnullRefPtr<Value> 2020-08-07 09:36:15 +02:00
Andreas Kling
420e809fee Shell: Store ListValue's values in a NonnullRefPtrVector<Value>
A ListValue never stores null Values, so it makes sense to restrict it.
This also propagates use of NonnullRefPtr to the create() helpers.
There's a small bit of awkwardness around the use of initializer_list,
since we cannot directly construct a NonnullRefPtrVector from one.
2020-08-07 09:33:05 +02:00
Andreas Kling
bf2cd9374c Shell: Make run_command() return a NonnullRefPtrVector<Job>
This never returns null Job pointers.
2020-08-06 13:44:30 +02:00
Andreas Kling
3cb8ae873c Shell: Use NonnullRefPtr to simplify some things in the parser/AST 2020-08-04 18:17:16 +02:00
AnotherTest
1d08cab9ab Shell: Correct FdRedirection inheriting from two RefCounted bases
Also add missing calls to `adopt()`.
2020-08-04 13:40:58 +02:00
AnotherTest
12af65c1c9 Shell: Add support for ARGV (and $*, $#)
This patchset also adds the 'shift' builtin, as well as the usual tests.
closes #2948.
2020-08-04 13:40:58 +02:00
Mathieu PATUREL
0622b60fbd Shell: factor out updating the path cache into a function. 2020-08-04 10:51:16 +02:00
Mathieu PATUREL
2b4b9d212e Shell: highlight runnable commands
And display in red the command which will result in something like "no
command, or is directory" (inspired by the fish shell).
2020-08-04 10:51:16 +02:00
Ben Wiederhake
782db88e82 Shell: Don't crash when autocompleting a non-bare word
For example, type 'Hello?' without the quotation marks but with the
question mark, and press TAB.

Previously, this would crash the Shell. Now, it merely refuses
to make any suggestions.

We could do better, but that is too hard for now.
2020-07-25 19:11:10 +02:00
AnotherTest
8e364b9780 Shell: Mark ForLoop as would_execute
This fixes #2825.
2020-07-17 23:18:15 +02:00
AnotherTest
b6066faa1f Shell: Add a 'for' loop
Closes #2760.
This commit adds a 'for' loop, and tweaks the syntax slightly to make &&
bind more tightly than || (allowing for `expr && if_ok || if_bad`) :^)
2020-07-16 16:01:10 +02:00
AnotherTest
95fc7dd03a Shell: Parse lists serially, and flatten them only when needed
This allows `((1 2 3) (4 5 6))` to remain nested until we explicitly
flatten it out.
2020-07-16 16:01:10 +02:00
AnotherTest
b0ce8d725a Shell: Move out run_commands and expand_aliases to be Shell member fns
This makes running commands from outside the AST chain easier.
2020-07-13 15:12:28 +02:00
AnotherTest
8d71eb9a6c Shell: Recursively resolve aliases 2020-07-12 17:45:18 +02:00
AnotherTest
5cdb0ef2e5 Shell: Keep the TTY on the same pgroup to get tty signals
This allows the shell to be notified about SIGWINCH even when a child
process is running in the foreground.
2020-07-06 22:39:32 +02:00
AnotherTest
f9d3055691 Shell: Do not treat the ending newline as part of a comment
This allows the parser to finally parse the entire source into a single
AST.
As a result of allowing comments inside sequences, Sequence is also
marked as would_execute if its left or right node would.
2020-07-06 13:25:42 +02:00
AnotherTest
ff857cd358 Shell: Initial support for 'option' completions
Take one small step towards #2357.
Handle completing barewords starting with '-' by piping the requests to
the Shell::complete_option(program_name, option) :^)

Also implements completion for a single builtin (setopt) until we figure out how
to handle #2357.
2020-07-05 15:43:14 +02:00
AnotherTest
b8d1edb2a2 Shell: Add a 'setopt' builtin
This builtin sets (and unsets) boolean flags that alter the behaviour of
the shell.
The only flags added are
- inline_exec_keep_empty_segments: Keep empty segments in the result of
  splitting $(...) by $IFS
- verbose: Announce each command before executing it

It should be noted that the (rather extreme) verbosity of the names is
intentional, and will hopefully be alleviated by the next commit :^)
2020-07-05 15:43:14 +02:00
AnotherTest
d6de2b5828 Shell: Show descriptions about syntax errors
The description contains an error message and where in the source the
error happened.
2020-07-05 15:43:14 +02:00
AnotherTest
639c1a1737 Shell: Build as part of Lagom as well
Bringing the Serenity Shell to your very own host system :^)
2020-07-05 15:43:14 +02:00
AnotherTest
d2bdbc3e77 Shell: Mark And and Or nodes as execute nodes 2020-07-05 15:43:14 +02:00
AnotherTest
3a37e8c56f Shell: Provide completions to Tilde and its Juxtaposition.
This commit also removes the ExecutionInputType and directly uses
RefPtr<Shell> instead, since nothing else is needed for execution
purposes, and also makes the shell refuse to evaluate commands with
any sort of syntax error.
2020-07-05 15:43:14 +02:00