Commit graph

104 commits

Author SHA1 Message Date
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
AnotherTest
063fb02ef4 Shell: Move the first command in a pipeline to the pipeline pgid too
This process is supposed to be the session leader of the pipeline
process group, we can't *not* move it into that group :P
2020-09-12 21:18:24 +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
54b453be57 Shell: Fix event loop processing and backgrounding in subshells 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
Nico Weber
8b166e57df
Misc: Remove some unneeded includes of Timer.h and ElapsedTimer.h (#3286) 2020-08-25 09:41:56 +02:00
AnotherTest
cf18bff72a Shell: Do not attempt to yank the TTY from background processes
They don't own the TTY anyway!
2020-08-19 21:21:34 +02:00
AnotherTest
20d4287eaf Shell: Fix outdated debug log code 2020-08-19 21:21:34 +02:00
AnotherTest
4ee4c94d60 Shell: Respect the 'PROMPT_EOL_MARK' environment variable
This allows the users to customise what is shown when a command ends
without a newline.
2020-08-18 16:58:17 +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
2b51250863 Shell: Wait for the parent to deal with the PGID stuff before execvp() 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
8a17527bc5 Shell: Show the job id instead of the pid when a job exits in background 2020-08-12 11:41:18 +02:00
Nico Weber
37d5e3e0df Shell: Fix fd leak with pipes
Fixes the problem reported in #3073. While trying to write a test
for this, I thought I'd use

    Shell -c 'for i in $(seq 100) { echo $i }' | head -n 1

but that makes the cpu spin at 100% and doesn't terminate even
with this fix here. But at least piping disasm into head now works.
2020-08-10 20:57:38 +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
3b3d158649 Shell: Make Command::redirections a NonnullRefPtrVector 2020-08-07 09:42:12 +02:00
Andreas Kling
0c6ce063e6 Shell: Print job status after suspending a command 2020-08-06 15:33:04 +02:00
Andreas Kling
d9aecc8e08 Shell: Remove unnecessary ignore() in Shell::custom_event()
Ignoring an event means that it will bubble to the parent Core::Object.
This is not necessary here.
2020-08-06 14:27:06 +02:00
Andreas Kling
5bce0193de Shell: Make Job constructors private and use a create() helper
Also store PGIDs as pid_t since that's what they are.
2020-08-06 13:48:45 +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