Commit graph

120 commits

Author SHA1 Message Date
Ali Mohammad Pur 124ca30d49 Shell: Don't assume that only the current shell may continue children
That can happen because of anyone sending the process a SIGCONT.
Fixes an issue where continuing a process launched by the shell from
the System Monitor would cause the shell to spin on waitpid().
2021-07-17 02:00:24 +04:30
Gunnar Beutner c7265ee6bd Assistant: Keep the Terminal window open after the command has run 2021-07-16 13:05:55 +02:00
TheFightingCatfish 72e661b542 Shell: Add unalias builtin
Add shell unalias builtin to remove aliases
2021-07-13 11:57:11 +04:30
Daniel Bertalan e32692ea68 Shell: Use correct printf format string for size_t 2021-07-08 10:11:00 +02:00
Gunnar Beutner 3bbe86d8ea Everywhere: Prefer using "..."sv over StringView { "..." } 2021-07-04 14:24:03 +02:00
Max Wipfli 9b8f35259c AK: Remove the LexicalPath::is_valid() API
Since this is always set to true on the non-default constructor and
subsequently never modified, it is somewhat pointless. Furthermore,
there are arguably no invalid relative paths.
2021-06-30 11:13:54 +02:00
Daniel Bertalan 65b2d3add3 Shell: Don't do null check on NonnullRefPtr<T>
This will cause a problem when `NonnullRefPtr<T>::operator T*` will be
declared as RETURNS_NONNULL. Clang emits a warning for this pointless
null check, which breaks CI.
2021-06-29 22:57:52 +04:30
Daniel Bertalan f820917a76 Everywhere: Use nothrow new with adopt_{ref,own}_if_nonnull
This commit converts naked `new`s to `AK::try_make` and `AK::try_create`
wherever possible. If the called constructor is private, this can not be
done, so we instead now use the standard-defined and compiler-agnostic
`new (nothrow)`.
2021-06-24 17:35:49 +04:30
coderdreams 6bc7f2204e Tests: Run each test in their respective directories
This is so they can find their associated resources and it's
the same behavior as in Lagom.

This also required changing some tests so that they could
write their resources in a writable location.
2021-06-22 18:54:40 +04:30
Gunnar Beutner 631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Brian Gianforcaro 8063ca881d Shell: Remove unused InlineLinkedList header include 2021-06-16 10:40:01 +02:00
Gunnar Beutner d476144565 Userland: Allow building SerenityOS with -funsigned-char
Some of the code assumed that chars were always signed while that is
not the case on ARM hosts.

Also, some of the code tried to use EOF (-1) in a way similar to what
fgetc() does, however instead of storing the characters in an int
variable a char was used.

While this seemed to work it also meant that character 0xFF would be
incorrectly seen as an end-of-file.

Careful reading of fgetc() reveals that fgetc() stores character
data in an int where valid characters are in the range of 0-255 and
the EOF value is explicitly outside of that range (usually -1).
2021-06-13 18:52:58 +02:00
Andreas Kling dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Jelle Raaijmakers 00fc0a6cf0 Shell: Make time stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers 250f8eccf3 LibCore: Support fine-grained failure behavior for ArgsParser 2021-06-08 11:30:58 +02:00
Ali Mohammad Pur 71b4433b0d LibWeb+LibSyntax: Implement nested syntax highlighters
And use them to highlight javascript in HTML source.
This commit also changes how TextDocumentSpan::data is interpreted,
as it used to be an opaque pointer, but everyone stuffed an enum value
inside it, which made the values not unique to each highlighter;
that field is now a u64 serial id.
The syntax highlighters don't need to change their ways of stuffing
token types into that field, but a highlighter that calls another
nested highlighter needs to register the nested types for use with
token pairs.
2021-06-07 14:45:49 +04:30
Max Wipfli 261f233060 Shell: Fix off-by-one error in SyntaxHighlighter
This changes the Shell syntax highlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.

This also adds some debug output to make debugging easier.
2021-06-05 00:32:28 +04:30
Max Wipfli bc8d16ad28 Everywhere: Replace ctype.h to avoid narrowing conversions
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
2021-06-03 13:31:46 +02:00
Ali Mohammad Pur 944855ca18 AK+Everywhere: Fix compiletime format parsing of replacement fields 2021-06-01 23:12:17 +04:30
Andreas Kling 12a42edd13 Everywhere: codepoint => code point 2021-06-01 10:01:11 +02:00
Max Wipfli 628c7f094f LibGUI+Shell+bt+ls: Use proper APIs for creating file URLs
This patch replaces ad-hoc generation of file URL strings with using
URL::create_with_file_scheme().
2021-06-01 09:28:05 +02:00
Ben Wiederhake a7c265f341 Everywhere: Sort out superfluous QuickSort.h imports
They were sorta unneeded. :^)
2021-05-29 23:41:54 +01:00
Andrew Kaster fae7c436e6 Shell: Disable the valid test as it has a high failure rate on target
Tracked by #7336
2021-05-27 15:18:03 +02:00
Ali Mohammad Pur b2ef18d538 LibLine+Shell: Allow some programs to modify the current termios
This setting can be controlled by setting the
PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS _local_ shell variable to a
list containing such programs.
2021-05-24 23:26:49 +04:30
Andreas Kling de395a3df2 AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both
of them into String::find() and use that everywhere.

Also add some tests to cover basic behavior.
2021-05-24 11:59:18 +02:00
Andrew Kaster c6eff55439 Shell: Make sure all tests put their temp dirs in /tmp
Follow-on to #7337. Been seeing other CI test failures that point to
these temp directories, so let's just move all of them to /tmp. I'm sure
someone will write ext2fs stress tests later :^)

Example:

/usr/Tests/Shell/control-structure-as-command.sh
  Core::Socket: Failed to connect() to /tmp/portal/inspectables: ...
  + rm -rf shell-test 2>/dev/null
  + mkdir shell-test
  Error: The action has timed out.
2021-05-22 00:24:27 +04:30
Andrew Kaster 413d98fb45 Shell: Use /tmp for all file operations valid.sh test
Not doing so sometimes intermittently caused the '*' glob expansion test
to fail and lock up the shell.
2021-05-21 13:30:45 +04:30
Andrew Kaster a5889b9aad Shell: Hide job times behind SHELL_JOB_DEBUG flag 2021-05-21 12:05:34 +04:30
Ali Mohammad Pur fdfa5c0bc7 Shell: Avoid moving AK::Function instances while inside them 2021-05-19 21:36:57 +02:00
Andreas Kling 31d4bcf5bf Userland: Tighten a *lot* of pledges! :^)
Since applications using Core::EventLoop no longer need to create a
socket in /tmp/rpc/, and also don't need to listen for incoming
connections on this socket, we can remove a whole bunch of pledges!
2021-05-13 23:28:40 +02:00
sin-ack f248145e64 Shell: Fix incorrect fcntl usage
FD_CLOEXEC is a file descriptor flag, so one must use F_{G,S}ETFD
instead.
2021-05-13 19:18:22 +01:00
Ali Mohammad Pur a91a49337c LibCore+Everywhere: Move OpenMode out of IODevice
...and make it an enum class so people don't omit "OpenMode".
2021-05-12 11:00:45 +01:00
sin-ack ecbe17fb11 LibLine+Shell: Add dirty history flag and use it
This patch adds a new flag called history_dirty to Line::Editor that is
set when history is added to but written.  Applications can leverage
this flag to write history only when it changes.  This patch adds an
example usage of this functionality to Shell, which will now only save
the history when it is dirty.
2021-05-11 17:26:30 +01:00
Ali Mohammad Pur a527256356 Shell: Add an option to autosave history every N ms
...and set it to 10 seconds by default.
2021-05-11 10:19:07 +01:00
Ali Mohammad Pur b1fe5d5517 Shell: Parse '\t' in doublequoted strings as a tab character
This not being recognised is surprising.
2021-05-10 10:43:23 +02:00
Ali Mohammad Pur 417910fd28 Shell: Make escaping more intelligent
Instead of the previous only-escape-with-backslashes, extend the
escaping to one of:
- No escape
- Escape with backslash
- Escape with "\xhh" if control character that isn't easily represented
  as \X
- Escape with "\uhhhhhhhh" if unicode character that is too big to
  represent as "\xhh".

Fixes #6986.
2021-05-10 10:43:23 +02:00
Ali Mohammad Pur 22b244df45 Shell: Add support for \uhhhhhhhh escapes in strings
This will be replaced with the unicode character whose codepoint is
given by the unsigned 32-bit number 'hhhhhhhh' (hex).
2021-05-10 10:43:23 +02:00
Andreas Kling 8c3b603da3 Shell: Convert StringBuilder::appendf() => AK::Format 2021-05-07 21:12:09 +02:00
Ali Mohammad Pur b7fb12338c Shell: Only match entries from PATH when a program name is given
This commit makes the shell:
- highlight executables in the current directory as invalid, unless an
  explicit `./' is given (so, `./foo` isn't red, but `foo` is)
- not suggest executables in the current directory unless explicitly
  requested (by prepending `./`)
- not attempt to run an executable in the current directory that has
  been invoked as a program name and failed execvp().
  Note that `./foo` is still executed because it's not invoked as
  a name, but rather as a path.

Fixes the other half of #6774.
2021-05-02 19:46:33 +02:00
Ali Mohammad Pur bda69a5f59 Shell: Replace fprintf(stderr) => warnln() 2021-05-02 19:46:33 +02:00
Ali Mohammad Pur 6a9dced790 Shell: Update shebang handling logic
This bit of code was kept unmodified since it was first implemented,
and I'm not entirely convinced that it ever actually worked :P
This commit updates the code to use "modern" classes and constructs,
and fixes an issue where the shebang would still contain the '#!'
when it was passed to execvp().
Fixes #6774.
2021-05-02 19:46:33 +02:00
Ali Mohammad Pur 70728b49e2 Shell: Move the heredocs vector to a local value before processing it
Otherwise we would end up trying to parse the same heredoc entry, if it
contained a sequence terminated by a newline.
e.g. `<<-x\n$({` would attempt to read a heredoc entry after `x`, and
then after `{` while inside the first heredoc entry.
To make this work, we can simply empty the instance vector and keep the
state on the stack.
Issue found through oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33852
2021-05-01 15:58:31 +02:00
Ali Mohammad Pur 323a408d8c Shell: Make set_is_syntax_error() also copy the error location 2021-05-01 15:58:31 +02:00
Ali Mohammad Pur f1d49d391e Shell: Disallow non-bareword nodes as part of a heredoc key
Found by oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33854
2021-05-01 15:58:31 +02:00
Ali Mohammad Pur 4c40151160 Shell: Implement formatting for Heredocs 2021-04-29 20:25:56 +02:00
Ali Mohammad Pur d70f25bbe5 Shell: Add some tests for heredocs 2021-04-29 20:25:56 +02:00
Ali Mohammad Pur 3048274f5e Shell: Add support for heredocs
Closes #4283.
Heredocs are implemented in a way that makes them feel more like a
string (and not a weird redirection, a la bash).
There are two tunables, whether the string is dedented (`<<-` vs `<<~`)
and whether it allows interpolation (quoted key vs not).
To the familiar people, this is how Ruby handles them, and I feel is the
most elegant heredoc syntax.
Unlike the oddjob that is bash, heredocs are treated exactly as normal
strings, and can be used _anywhere_ where a string can be used.
They are *required* to appear in the same order as used after a newline
is seen when parsing the sequence that the heredoc is used in.
For instance:
```sh
echo <<-doc1 <<-doc2 | blah blah
contents for doc1
doc1
contents for doc2
doc2
```
The typical nice errors are also implemented :^)
2021-04-29 20:25:56 +02:00
Ali Mohammad Pur 7c8d39e002 Shell: Do not assume that all parts of a node are enclosed in the node
For instance, heredocs are made of two parts, and the second part is not
within the bounds of the first one.
2021-04-29 20:25:56 +02:00
Ali Mohammad Pur cf4935e806 Shell: Avoid position push/pop when checking for next_is()
This operation is not a rule and cannot produce nodes.
2021-04-29 20:25:56 +02:00
Ali Mohammad Pur 0d742557c6 Shell: Allow Syntax errors to be mutated while parsing
Some nodes (such as heredocs) cannot be validated immediately, so the
entire tree will need to be revalidated if we don't allow mutating
syntax errors.
2021-04-29 20:25:56 +02:00