Commit graph

338 commits

Author SHA1 Message Date
Lenny Maiorani
0cb16ffe08 Shell: Remove unused private member and includes
Problem:
- Clang reports unused private member warning in the `Shell::Formatter`.
- Vector is not used in the `Shell::Formatter`.

Solution:
- Remove unused private member variable.
- Remove unused includes.
2020-11-17 09:48:02 +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
1a4ac3531f Shell: Allow parts of globs to be named in match expressions
This patchset allows a match expression to have a list of names for its
glob parts, which are assigned to the matched values in the body of the
match.
For example,
```sh
stuff=foobarblahblah/target_{1..30}
for $stuff {
    match $it {
        */* as (dir sub) {
            echo "doing things with $sub in $dir"
            make -C $dir $sub # or whatever...
        }
    }
}
```

With this, match expressions are now significantly more powerful!
2020-10-29 11:53:01 +01:00
AnotherTest
2d6d1ca67f Shell: Add some basic tests for backgrounding 2020-10-29 11:53:01 +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
a46318d414 Shell: Do not bail early when printing jobs if waitpid() fails
This fixes running `jobs` in a child process.
Also makes sure that stdout is flushed when writing jobs out.
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
2610477836 Shell: Only prompt the user for a second 'exit' when in interactive mode 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
76a2c6e44d Shell: Fix cd' history (and cdh')
Previously, `cd` would push relative paths (and possibly nonexistent
ones too) into its history, so `cdh' would fail everywhere else.
2020-10-26 14:28:38 +01:00
AnotherTest
6d7b01a3cf Shell: Use kill() in fg/bg if killpg() fails
A job might not have its own pgid if it's created through run_tail().
2020-10-26 14:28:38 +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
AnotherTest
8de70e8ce7 Shell: Implement AK::Formatter::format() for AST::Command
...and use that to display jobs.
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
AnotherTest
f7dbd14a87 Shell: Add some tests for brace expansions 2020-10-25 10:09:27 +01:00
AnotherTest
5640e1bc3a Shell: Add support for brace expansions
This adds support for (basic) brace expansions with the following
syntaxes:
- `{expr?,expr?,expr?,...}` which is directly equivalent to `(expr expr
  expr ...)`, with the missing expressions replaced with an empty string
  literal.
- `{expr..expr}` which is a new range expansion, with two modes:
    - if both expressions are one unicode code point long, the range is
      equivalent to the two code points and all code points between the
      two (numerically).
    - if both expressions are numeric, the range is equivalent to both
      numbers, and all numbers between the two.
    - otherwise, it is equivalent to `(expr expr)`.

Closes #3832.
2020-10-25 10:09:27 +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
b1b202124c Shell: Use Node::kind() instead of Node::class_name() in formatter 2020-10-14 21:05:39 +02:00
AnotherTest
738f512919 Shell: Respect input sources' blank lines between sequences
But collapse them to a single empty line.
This makes the generated sources look significantly better.
2020-10-14 21:05:39 +02:00
AnotherTest
cd48ec2abd Shell: Put a space after the match pattern expression when formatting 2020-10-14 21:05:39 +02:00
Matthew L. Curry
5d5c32cec1 Style: Remove uses of NULL, substituting nullptr 2020-10-13 13:52:52 +02:00
AnotherTest
7f3e1fa826 Shell: Fix closest command node detection in Pipes and Sequences
This makes --option completions work for pipes and sequences too.
2020-10-04 23:12:28 +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
2c3842bfe6 Shell: Fix badly worded help string for '--format' 2020-10-03 12:40:03 +02:00
Linus Groh
bcfc6f0c57 Everywhere: Fix more typos 2020-10-03 12:36:49 +02:00
asynts
6351a56d27 AK+Format: Do some housekeeping in the format implementation. 2020-10-02 20:48:19 +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
a7828434c0 Shell: Sneak a way into being a session leader 2020-10-01 21:20:14 +02:00
AnotherTest
a10cfee0d4 Shell: Track line numbers and the positions of some keywords 2020-09-30 20:05:24 +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
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
e94ee08eca Shell: Fix a FIXME in the a test about using functions 2020-09-26 21:28:35 +02:00
AnotherTest
b3dd97a694 Shell: Add a (very basic) formatter 2020-09-26 21:28:35 +02:00
AnotherTest
6e6be8e56e Shell: Ignore '\\\n' in input
This allows the user to break a line:
```sh
$ echo \
   foo
```
is the same as
```sh
$ echo    foo
```
2020-09-26 21:28:35 +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