Commit graph

127 commits

Author SHA1 Message Date
AnotherTest
43199e5613 LibLine: Implement support for C-V<key>
This commit adds support for inserting in a "verbatim" mode where a
single uninterpreted key is appended to the buffer.
As this allows the user to input control characters, all control
characters except \n (^M) are rendered in their caret form, with
reverse video (SGR 7) applied to it.
To not break cursor movement, the concept of "masked" characters is
introduced to the StringMetrics interface, which can be mostly ignored
by the rest of the system.

It should be noted that unlike some other line editing libraries,
LibLine does _not_ render a hard tab as a tab, but rather as '^I',
which greatly simplifies cursor handling.
2021-01-10 16:58:08 +01:00
AnotherTest
9523bcbfe1 Shell: Fix completing barewords with escapes
e.g. completing `foo\ bar` now works as expected.
2021-01-10 00:03:52 +01:00
AnotherTest
335221d830 Shell: Run function declarations in the current process
Fixes #4817
2021-01-06 15:40:45 +01:00
AnotherTest
4adfdb98aa Shell: Remove debug log about child process going away
This is still an issue, but its existence isn't helping anyone, so just
remove it.
2021-01-04 19:13:18 +01:00
AnotherTest
a698af88fc Shell: Show a snippet of what caused the error (if possible)
Now we can have nice errors too:
```
Shell: Glob did not match anything!
  0| echo ?x
~~~~~~~~~~^^
  1|

```
2021-01-03 17:13:00 +01:00
William Marlow
96cd04f2ba Shell: Implement a very basic exec builtin
Other shells also support a number of other options with exec and
some have special behaviour when calling exec with no arguments except
redirections.

This PR only supports the basic case of replacing the Shell process
(or LibShell host process) with the provided command.
2020-12-30 02:13:53 +01:00
asynts
50d24e4f98 AK: Make binary_search signature more generic. 2020-12-30 02:13:30 +01:00
AnotherTest
5e5eb615ec Shell: Add runtime errors and implement break/continue
Such errors are raised when SyntaxError nodes are executed, and are also
used for internal control flow.
The 'break' and 'continue' commands are currently only allowed inside
for loops, and outside function bodies.

This also adds a 'loop' keyword for infinite loops.
2020-12-29 16:55:43 +01:00
AnotherTest
9bd81f34a5 Shell: Make for/match/functions put their variables only in the new scope
Otherwise, a function would, for example, overwrite its parent scope:
```sh
foo(x) { }
x=1
foo 2 # would make x=2 otherwise
```
2020-12-29 16:55:43 +01:00
Linus Groh
3d7b8de64f Shell: Don't run commands with failing redirections
Fixes #3423.
2020-12-16 23:26:19 +01:00
AnotherTest
4668dfa7c7 Shell: Make Subshell actually create a subshell
Previously, a "subshell" would just be executed in the parent shell.
2020-12-15 20:58:32 +01:00
AnotherTest
a2879f53c8 Shell: Restore the terminal PGID before printing out job status on exit
This fixes the assert tripping when interrupting a foreground job.
Also make `bg` mark the job as 'should announce exit'.
2020-12-10 16:20:39 +01:00
AnotherTest
17e1e1f114 Shell: Actually make shebangs work
Also check for executable permissions before actually trying to run, and
print a helpful message if not executable.
Fixes #4358
2020-12-08 23:34:38 +01:00
AnotherTest
0141f7e7fd Shell: Avoid recreating the event loop before exec()
This stops the local socket creation spam.
2020-12-08 23:34:38 +01:00
AnotherTest
cd8268e6fb Shell: Put background jobs into new process groups too
Fixes #4345.
This was done in 54b453b in the name of "fixing event loop processing in
subshells", but I do not see how a new PGID is supposed to affect the event
loop.
This seems to have been done by mistake, let's see if any tests fail
because of this.
2020-12-08 23:34:38 +01:00
AnotherTest
59b46a1f51 Shell: Show termination signal if job did not exit cleanly 2020-12-08 23:34:38 +01:00
AnotherTest
48a1f7e55c Shell: Silence TCSETPGRP errors when not interactive 2020-12-08 23:34:38 +01:00
AnotherTest
57728ef29f Shell: Replace all dbg()'s with dbgln() 2020-12-08 23:34:38 +01:00
AnotherTest
5325d6871d Shell: Make <return> go to a new line when the command is incomplete
"incomplete" meaning that it has a syntax error that can be recovered
from by continuing the input.
2020-12-08 23:34:38 +01:00
AnotherTest
1aed61964a Shell: Do not leak the value of ARGV in nested function calls 2020-11-01 18:45:05 +01:00
AnotherTest
e87e580eb3 Shell: Search for variables in the last frame first
Otherwise, we'll end up overwriting another frame's variables if the
names match up.
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
c92865bd05 Shell: Use kill_job() to kill jobs 2020-10-29 11:53:01 +01:00
AnotherTest
384e872ff9 Shell: Add redirections to the formatted command string 2020-10-29 11:53:01 +01:00
AnotherTest
f4b7a688b1 Shell: Rename {source,dest}_fd to {old,new}_fd
This makes `Rewiring' much more understandable, and un-confuses the uses
of `dup2()'.
Also fixes `dup2()' bugs.
2020-10-29 11:53:01 +01:00
AnotherTest
0bc758d34a Shell: Run builtins that cannot be run in the main process in a new child
e.g. `$(jobs | wc -l)` would blow up horribly otherwise.
(it still does)
2020-10-29 11:53:01 +01:00
AnotherTest
a8c18f9fd2 Shell: Drop all the jobs after killing them in stop_all_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
AnotherTest
9ad858bcbf Shell: Make the ENSURE_WAITID_ONCE requirements a bit less strict
waitid() *may* be called many times if a job does not exit, so only
assert this fact when the job has in fact exited.
Also allows Background nodes to contain non-execute nodes.
2020-10-26 14:28:38 +01:00
Linus Groh
4a4b1b1131 Shell: Support HISTFILE environment variable
This allows changing the Shell's history file path.
2020-10-26 11:27:54 +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
956e9aa736 Shell: Fix off-by-one in EOL mark printing
Fixes #3844.
2020-10-25 16:39:18 +01:00
Andreas Kling
1d96ecf148 Everywhere: Add missing <AK/TemporaryChange.h> includes
Don't rely on HashTable.h pulling this in.
2020-10-15 23:49:53 +02:00
AnotherTest
a9cee8ee02 Shell+LibLine: Record the input offset of completions
This makes the completion entry retain information about how much of the
suggestion was part of the string that caused the match.
2020-10-04 23:12:28 +02:00
AnotherTest
f164b808b5 Shell: Move everything to the Shell namespace
Also provide a basic default-constructor.
2020-10-04 23:12:28 +02:00
asynts
d5ffb51a83 AK: Don't add newline for outf/dbgf/warnf.
In the future all (normal) output should be written by any of the
following functions:

    out    (currently called new_out)
    outln
    dbg    (currently called new_dbg)
    dbgln
    warn   (currently called new_warn)
    warnln

However, there are still a ton of uses of the old out/warn/dbg in the
code base so the new functions are called new_out/new_warn/new_dbg. I am
going to rename them as soon as all the other usages are gone (this
might take a while.)

I also added raw_out/raw_dbg/raw_warn which don't do any escaping,
this should be useful if no formatting is required and if the input
contains tons of curly braces. (I am not entirely sure if this function
will stay, but I am adding it for now.)
2020-10-04 17:04:55 +02:00
AnotherTest
254d66cd81 Shell: Assert that the same pid is not given to waitpid()
Theoretically, this assertion should never trip (at least, on serenity
where we don't really reuse PIDs).
This change should be considered temporary, until we figure out whether
waitpid() is being called twice (and succeeding) for one given PID.
2020-10-01 21:20:14 +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
asynts
afa2523724 Shell: Don't execute scripts interactively.
The following example should illustrate one issue arising from this:

    $ echo 'exit 1' > example.sh
    $ Shell example.sh
    Good-bye!

This message is meant to be shown to an interactive user, but not in a
shell script.
2020-09-28 17:39:50 +02:00
AnotherTest
5f1cc64504 Shell: Fix use-after-move in alias resolution
This unbreaks aliases!
2020-09-26 22:11:28 +02:00
AnotherTest
b3dd97a694 Shell: Add a (very basic) formatter 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
29ef65c458 Shell: Fix Vector OOB access in `add_entry_to_cache()'
Fixes #3530.
2020-09-19 00:38:41 +02:00
AnotherTest
a43d9c4fe0 Shell: Make a new session at start if there's no active session 2020-09-19 00:38:41 +02:00
AnotherTest
4c2f86c24f Shell: Do not strip glob base path when it was explicitly requested
Fixes #3544.
2020-09-19 00:24:16 +02:00
AnotherTest
cd0ddf27f3 Shell: Allow builtins and functions as conditions for 'if' 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
0b57cdff82 Shell: Add support for $0,$1,... 2020-09-14 17:40:18 +02:00