Commit graph

323 commits

Author SHA1 Message Date
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
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
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
4f223793c0 Shell: Add some tests for 'match' 2020-09-15 20:36:59 +02:00
AnotherTest
4c6f7846b4 Shell: Add 'match' expressions
This commit adds an equivalent to the sh 'case' construct, except it's
much more pleasing to look at and write:
```sh
match "$something" {
    p1 { echo "p1!" }
    p2 { echo "p2!" }
    *  { echo "string catch-all!" }
}
```
is the equivalent of:
```sh
case $something in
    p1)
        echo "p1!"
        ;;
    p2)
        echo "p2!"
        ;;
    *)
        echo "catch-all!"
        ;;
esac
```

Since our shell does not treat lists as strings, matching lists is also
possible:

```sh
match (1foo 2foo foo3) {
    (?foo 2* *) { echo wowzers! }
    (* * *) { echo 3-element list catch-all }
}
```
2020-09-15 20:36:59 +02:00
AnotherTest
53b85bcdd0 Shell: Make Parser::expect() revert the offset when matching fails 2020-09-15 20:36:59 +02:00
AnotherTest
afe0ae586c Shell: Make Node::resolve_as_list(nullptr) resolve to a 'pure' repr
'pure' as in "not requiring a shell", similar to
JS::Value::to_string_without_side_effects().
2020-09-15 20:36:59 +02:00
asynts
f18e927827 AK: Remove OutputMemoryStream for DuplexMemoryStream.
OutputMemoryStream was originally a proxy for DuplexMemoryStream that
did not expose any reading API.

Now I need to add another class that is like OutputMemoryStream but only
for static buffers. My first idea was to make OutputMemoryStream do that
too, but I think it's much better to have a distinct class for that.

I originally wanted to call that class FixedOutputMemoryStream but that
name is really cumbersome and it's a bit unintuitive because
InputMemoryStream is already reading from a fixed buffer.

So let's just use DuplexMemoryStream instead of OutputMemoryStream for
any dynamic stuff and create a new OutputMemoryStream for static
buffers.
2020-09-15 20:36:45 +02:00
AnotherTest
cd0ddf27f3 Shell: Allow builtins and functions as conditions for 'if' 2020-09-14 17:40:18 +02:00
AnotherTest
2b867ff555 Shell: Complete named function parameters inside the function body 2020-09-14 17:40:18 +02:00
AnotherTest
b7661dee46 Shell: Add some tests for functions 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
519aa2048a Shell: Use a subshell instead of explicitly calling a shell binary in a test
This commit fixes a FIXME in a test, as we have subshells now.
2020-09-14 17:40:18 +02:00
AnotherTest
0b57cdff82 Shell: Add support for $0,$1,... 2020-09-14 17:40:18 +02:00