Commit graph

49 commits

Author SHA1 Message Date
AnotherTest
1aed61964a Shell: Do not leak the value of ARGV in nested function calls 2020-11-01 18:45:05 +01:00
AnotherTest
bedad383b5 Shell: Store LocalFrames as NonnullOwnPtr<LocalFrame> instead
As Vector<T> will relocate objects to resize, we cannot assume that the
address of a specific LocalFrame will stay constant, or that the
reference will not be dangling to begin with.
Fixes an assertion that fires when a frame push causes the Vector to
reallocate.
2020-11-01 18:45:05 +01:00
AnotherTest
6e2a383f25 Shell: Wait for the rest of the members of a pipeline when one exits
Assuming we were blocking on one to begin with.
2020-10-29 11:53:01 +01:00
AnotherTest
71bb62d03c Shell: Add the `wait' builtin
This builtin...waits...for the jobs it's given (or all the existing
jobs).
2020-10-29 11:53:01 +01:00
AnotherTest
5a4673d468 Shell: Ensure that jobs going through run_tail() retain should_wait
This allows putting logic in the background as well.
2020-10-26 14:28:38 +01:00
Linus Groh
b2e4fe1299 Shell+LibLine: Move Shell::{load,save}_history() to Line::Editor
This allows us to easily re-use history loading and saving in other
programs using Line::Editor, as well as implementing universally
recognized HISTCONTROL.
2020-10-26 11:27:54 +01:00
AnotherTest
f164b808b5 Shell: Move everything to the Shell namespace
Also provide a basic default-constructor.
2020-10-04 23:12:28 +02:00
AnotherTest
519d1811fd Shell: Wait for *any* child to change state when receiving a SIGCHLD
This really just works around the core issue, which is that we have no
reliable way to know exactly who raised the signal (yet).
Fixes #3645, in a very weird (yet apparently standard) way.
2020-10-01 21:20:14 +02:00
AnotherTest
b91be8b9fd Shell: Make 'editor' a member of Shell, and provide a LibShell 2020-09-30 20:05:24 +02:00
AnotherTest
fa03a2848f Shell: Add live formatting and take an option to enable it
This patchset makes it possible for the shell to format the current
buffer of the line editor live, with somewhat accurate cursor tracking.
Since this feature is pretty goofy at best, let's keep it off by default
for now :^)
2020-09-26 21:28:35 +02:00
AnotherTest
b3dd97a694 Shell: Add a (very basic) formatter 2020-09-26 21:28:35 +02:00
Andreas Kling
e2f32b8f9d LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing
a pretty asymmetric job of implementing the various properties, let's
add a bit of structure here.

Object properties are now represented by a Core::Property. Properties
are registered with a getter and setter (optional) in constructors.
I've added some convenience macros for creating and registering
properties, but this does still feel a bit bulky. We'll have to
iterate on this and see where it goes.
2020-09-15 21:46:26 +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
0b57cdff82 Shell: Add support for $0,$1,... 2020-09-14 17:40:18 +02:00
AnotherTest
54b453be57 Shell: Fix event loop processing and backgrounding in subshells 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
AnotherTest
14a54a72fa Shell: Ensure that the cursor starts on a new line
And print an indicator when it doesn't, a la zsh.
2020-08-17 17:44:02 +02:00
AnotherTest
c589625418 Shell: Allow redirections and pipes on builtins
Fixes #3072.
2020-08-15 20:48:17 +02:00
AnotherTest
9fde92db38 Shell: Make redirections without commands apply to all future commands
This restirects redirection-only commands' scope, and keeps their
usefulness too!
2020-08-09 21:50:33 +02:00
Andreas Kling
b8440b12b7 Shell: Store jobs as NonnullRefPtr<Job> 2020-08-06 14:09:13 +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
AnotherTest
7b15c85ff5 Shell: Do not assume that stdin/stdout is a TTY
This closes #2989.
2020-08-05 17:30:31 +02:00
AnotherTest
771751258e Shell: Give the TTY to the foreground process
This fixes the bug with the shell not waiting for any foreground process
that attempts to read from the terminal in the Lagom build.
2020-08-04 21:22:44 +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
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
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
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
Tom
6dfd503518 Shell: Handle signals asynchronously
Fixes #2717
2020-07-09 21:58:07 +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
6d17fe38a4 Shell: Do not treat the absence of an init script as an error 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
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
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
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
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
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
143be7234f Shell: Kill existing jobs when exiting 2020-05-25 00:08:32 +02:00
AnotherTest
0d39418b0b Shell: Add the `disown' shell builtin 2020-05-25 00:08:32 +02:00
AnotherTest
7fba21aefc LibLine: Unify completion hooks and adapt its users
LibLine should ultimately not care about what a "token" means in the
context of its user, so force the user to split the buffer itself.
This also allows the users to pick up contextual clues as well, since
they have to lex the line themselves.

This commit pacthes Shell and the JS repl to better handle completions,
so certain wrong behaviours are now corrected as well:
- JS repl can now complete "Object . getOw<tab>"
- Shell can now complete "echo | ca<tab>" and paths inside strings
2020-05-20 13:41:37 +02:00
AnotherTest
1469d20e63 Shell: Treat builtin names as programs and suggest them 2020-05-17 12:54:31 +02:00
AnotherTest
a398898c12 Shell: Switch to using Core::EventLoop
This commit refactors Shell to a Core::Object and switches its looping
to Core::EventLoop.
2020-05-17 11:58:08 +02:00