Commit graph

197 commits

Author SHA1 Message Date
AnotherTest
cd8495f1d4 Shell: Explicitly declare 'environ' to make the macOS Lagom build happy 2020-07-15 00:09:01 +02:00
AnotherTest
dc62371439 Shell: Avoid waiting for jobs that were *just* unblocked
This fixes the issue with C-z not suspending the job on the first try.
...and further signal issues when the suspended job is contiued.
2020-07-13 19:48:45 +02:00
AnotherTest
151e4d41ed Shell: Put children in their own process groups and fix job control
This commit fixes job control by putting children in their own process
group, and proxying TTY signals to active jobs.
This also cleans up the code around builtin_disown a bit to use
the newer job interfaces.
2020-07-13 15:29:16 +02:00
AnotherTest
7170df7dd8 Shell: Resolve aliases in builtin_time 2020-07-13 15:12:28 +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
Tom
5d9ea2c787 Shell: Pledge sigaction
The shell is wiring up signal handlers, and when they get torn
down by Core::EventLoop, they are reset, which requires sigaction.
2020-07-09 21:58:07 +02:00
Tom
6dfd503518 Shell: Handle signals asynchronously
Fixes #2717
2020-07-09 21:58:07 +02:00
AnotherTest
173effc88d Shell: Suggest aliases when completing program names :^)
Closes #2732
2020-07-07 23:11:01 +02:00
AnotherTest
b5e04cb070 Shell: Skip creating a Join node when nothing was parsed
This fixes a crash when Shell tries to highlight `|`.
2020-07-07 14:52:53 +02:00
Andreas Kling
1bc6bb0421 Shell: Run both /etc/shellrc and ~/.shellrc on startup
The global script runs before the local (per-user) one.
2020-07-07 11:35:22 +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
dec27e5e6f Shell: Handle the case where the child we're waiting for doesn't exist
Normally, this should not happen, as the child should stay around until
we do a waitid on it.
2020-07-06 17:06:57 +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
6d17fe38a4 Shell: Do not treat the absence of an init script as an error 2020-07-06 13:25:42 +02:00
AnotherTest
ddbdd0e686 Shell: Do not remove more than 2 dashes from the option being completed
This makes '------inl' a completion request for an option named
'----inl' instead of 'inl'.
2020-07-05 16:11:49 +02:00
AnotherTest
3a072332f4 Shell: Add some tests 2020-07-05 15:43:14 +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
034be8e74c Shell: Allow a command sequence to be delimited by newlines 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
AnotherTest
c5d0aa9a44 Shell: Allow commands in variables, and properly substitute them on use
This allows the below interaction to work:
```
$ silence=(2>&1 >/dev/null)
$ do_noisy_thing with these args $silence
<nothing here lol>
```
2020-07-05 15:43:14 +02:00
AnotherTest
42304d7bf1 Shell: Parse a pipe sequence inside $(...) 2020-07-05 15:43:14 +02:00
AnotherTest
8e078cf4ab Shell: Expand Juxtaposition of lists to list products
This commit makes `echo x(foo bar)` create an argv of `echo xfoo xbar`,
essentially modeling brace expansions in some shells.
2020-07-05 15:43:14 +02:00
AnotherTest
16def040af Shell: Do not try to recreate a command from a list of args in time
Shell already provides a run_command(AST::Command) which can be
constructed from a list of arguments, use that instead.
2020-07-05 15:43:14 +02:00
AnotherTest
bc3285abb0 Shell: Read and evaluate an init file on start
This behaviour is overridable with the `--skip-init' flag.
The default file is at '~/shell-init.sh'
2020-07-05 15:43:14 +02:00
AnotherTest
3d6a035d0f Shell: Use ArgsParser for argument parsing 2020-07-05 15:43:14 +02:00
AnotherTest
2915dcfcc3 Shell: Add the alias builtin and resolve aliases
This follows the other shells in alias resolution, and resolves the
alias only once.
2020-07-05 15:43:14 +02:00
AnotherTest
a4627f2439 Shell: Switch to a new parser and AST
This commit also completely reworks the execution, highlighting and
completion model to work with the new AST.
New additions:
- $(...) stdout captures
- fd>&fd redirections
- fd>&- redirections (close fd)
- read-write redirections (<> path)
- completely event-based execution
- the weird idea of allowing the user to redirect the shell's own fds
- variables in strings
- local variables
- minimal list support
- adding hyperlinks to all paths that exist
2020-07-05 15:43:14 +02:00
AnotherTest
a6fd969d93 LibLine: Support multiline editing
This commit also updates Shell, which uses actual_rendered_length.
2020-06-27 15:39:03 +02:00
Andreas Kling
723f4e5ee6 Meta: Scale back overly informal user-facing strings
We were getting a little overly memey in some places, so let's scale
things back to business-casual.

Informal language is fine in comments, commits and debug logs,
but let's keep the runtime nice and presentable. :^)
2020-06-17 18:35:49 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
AnotherTest
2714bba3f0 Shell: Highlight redirections 2020-06-08 09:27:51 +02:00
AnotherTest
889a8e7d0f LibLine: Handle interrupts again
This commit makes LibLine handle interrupts (as reported via
interrupted() and resized()) again.
There is a little catch with the shell:
```
$     ls |
pipe> <C-c> (prompt stays here until a key is pressed)
```
2020-06-01 19:52:20 +02:00
AnotherTest
8c05e78b6c Shell: Treat ^D as builtin_exit when not in a continuation 2020-05-30 23:01:36 +02:00
AnotherTest
77039e5354 Shell: Correctly complete paths in redirections
This commit allows the Shell to complete paths in redirections.
A closing quote is added if the path is an unclosed quote.
```
$ foo > "foob<tab>
$ foo > "foobar"
```
2020-05-30 00:36:51 +02:00
AnotherTest
abfcd7b1b8 Shell: Save the history when quitting via the exit builtin 2020-05-27 11:13:02 +02:00
AnotherTest
ce61cad933 Shell: Never assign equal job ids to two different jobs
Since the last job need not have an ID of size()-1, we need to find the
max job id and give that+1 out
2020-05-27 11:13:02 +02:00
AnotherTest
d582c03233 Shell: Provide some information to inspectors 2020-05-27 11:13:02 +02:00
AnotherTest
d5e9213683 Shell: Avoid messing with sigaction while waiting for a child 2020-05-27 11:13:02 +02:00
AnotherTest
70a213a6ec LibLine: Use Core::EventLoop for outer read loop
This commit changes LibLine's internal structure to work in an event
loop, and as a result, also switches it to being a Core::Object.
2020-05-27 11:13:02 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Sergey Bugaev
4139838a93 Userland et al: Pledge sigaction when needed
* In some cases, we can first call sigaction()/signal(), then *not* pledge
  sigaction.
* In other cases, we pledge sigaction at first, call sigaction()/signal()
  second, then pledge again, this time without sigaction.
* In yet other cases, we keep the sigaction pledge. I suppose these could all be
  migrated to drop it or not pledge it at all, if somebody is interested in
  doing that.
2020-05-26 14:35:10 +02:00
AnotherTest
42114c5784 Shell: Refuse to be suspended with ^Z
Suspending the shell while interacting with it is pretty weird, so let's
just disallow this behaviour.
2020-05-25 21:36:51 +02:00
AnotherTest
bc9013f706 LibLine: Change get_line to return a Result<String, Error>
This fixes a bunch of FIXME's in LibLine.
Also handles the case where read() would read zero bytes in vt_dsr() and
effectively block forever by erroring out.

Fixes #2370
2020-05-25 21:36:51 +02:00
AnotherTest
b4ca563637 Shell: Warn the user about active jobs on exit
And make sure that the user means to exit and kill current jobs before exiting.
2020-05-25 00:08:32 +02:00
AnotherTest
c23c354779 Shell: Parse and correctly evaluate 'command &' and 'command &&'
This commit adds the InBackground and ShortCircuitOnFailure attributes
to commands, which respectively cause the command to be run in the
background, and abort the command chain with exit status != 0.
2020-05-25 00:08:32 +02:00