Commit Graph

367 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
hanaa12G
19f137c1e6 LibLine: Remove duplicate members in CompletionSuggestion
Previously, we stored two representations of the same string in
`CompletionSuggestion` object: one for the bytes and the other for the
code points corresponding to those bytes. To minimize duplication, this
patch combine both representations into a single UTF-8 string, which is
already supported by our new String class.

Following this update, we successfully reduce the size of each object
from 376 bytes to 256 bytes
2023-12-15 16:58:03 +03:30
Andrew Kaster
c145d5410c Userland: Don't leak objects when constructor arguments throw
Similar to d253beb2f7.

Found with Ali's clang-query script in Shell:

```
for $(find AK Userland -type f -name '*.h' -o -name '*.cpp') {
    in_parallel -j 12 -- clang-query -p \
    Build/lagom/compile_commands.json $it -c \
    'm cxxNewExpr(has(cxxConstructExpr(hasAnyArgument(hasDescendant( \
        allOf(isExpandedFromMacro("TRY"), stmtExpr()))))))' \
    } | grep -v 'matches.' | tee results
```
2023-12-13 19:21:03 -07:00
Shannon Booth
6ce0d588ee Everywhere: Avoid calling from_utf8 on FlyString or String
We already have a String :^)
2023-12-10 09:45:03 +01:00
Ali Mohammad Pur
fde174645a Shell: Accept empty set of completions from program completer
Falling back to default completions goes directly against the users'
wishes :P
2023-12-01 19:24:57 +03:30
david072
0e1bd54896 Shell/PosixParser: Correctly parse the OR_IF token
This fixes an unfortunate typo where we would parse the OR_IF token as
an AST::And node. Now, it is parsed into an AST::Or node :^).
2023-11-20 22:02:30 +03:30
Ali Mohammad Pur
aa73a7c961 Shell: Accept null heredocs in POSIX mode
Fixes #21837.
2023-11-18 16:50:01 +03:30
Ali Mohammad Pur
2eb0a8f3d2 Shell: Expand for loop's iterated expr before iterating over it
This only applies to the POSIX mode.
Fixes #21715.
2023-11-18 16:50:01 +03:30
Ali Mohammad Pur
ad4470bc39 Shell: Escape program-provided completions unless they're marked as code
This makes it so program-provided completions don't have to worry about
escaping, making the Shell the only authority on escaping.
2023-11-17 11:02:02 +03:30
Adam Harald Jørgensen
e2f9011a8d Shell: Improve error propagation
This commit replaces 31 release_value_but_fixme_should_propagate_errors
calls with TRYs. :^)
2023-11-14 20:08:27 +03:30
Adam Harald Jørgensen
e89ba794d0 Shell: Include parent and base directories in expanded globs 2023-11-14 20:08:27 +03:30
Adam Harald Jørgensen
cc157629b4 Shell: Expand glob to only directories if it ends with a slash
The glob "*/" should only expand to directories, and the directories
should also have a trailing slash. This commit also replaces
Shell::split_path with StringView::split_view since it accomplishes the
same task.
2023-11-14 20:08:27 +03:30
hanaa12G
e6c363ac63 Shell: Allow to parse command interactively when hitting Enter key 2023-11-11 14:44:10 +03:30
Tim Schumacher
a2f60911fe AK: Rename GenericTraits to DefaultTraits
This feels like a more fitting name for something that provides the
default values for Traits.
2023-11-09 10:05:51 -05:00
Tim Ledbetter
ff81513634 Shell: Avoid infinite loop when parsing heredoc entry in POSIX mode
Previously, the shell would enter an infinite loop when attempting to
parse a heredoc entry within a `$(` command substitution.
2023-11-08 15:04:08 +03:30
Adam Harald Jørgensen
a1cdfe1b54 Shell: Add support for showing shortened prompt path with ellipsis 2023-11-07 07:46:52 +03:30
Adam Harald Jørgensen
4febd31dba Shell: Shorten prompt path if integer is provided with "\w" option 2023-11-07 07:46:52 +03:30
implicitfield
4b60a99573 Shell: Remove '#' from the list of acceptable bareword characters
This stops the shell from always interpreting '#' as the start of a
comment in non-Posix mode.
2023-10-29 01:35:40 +03:30
Adam Harald Jørgensen
491d61a2fd Shell: Add support for escaping backslash in prompt sequence 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
050c73d301 Shell: Add support for showing custom format time in prompt with "\D{}" 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
e40955e9c6 Shell: Add support for showing current time in prompt with "\{t|T|@}" 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
3d42e68265 Shell: Add support for showing number of jobs in prompt with "\j" 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
f81bc8b045 Shell: Add support for showing the history number in prompt with "\!" 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
f597d7c730 Shell: Add command to history before running, instead of after 2023-10-26 22:33:38 +03:30
Adam Harald Jørgensen
78b3703586 Shell: Refactor Shell::prompt to use GenericLexer to read the PROMPT var 2023-10-26 22:33:38 +03:30
Ali Mohammad Pur
cc43a7ecda Shell: Add a 'in_parallel' builtin for easy concurrency 2023-10-26 11:15:57 +02:00
implicitfield
2745b48e16 Shell: Don't try to cast NonnullRefPtrs when priting debug output
Fixes a regression from 8a48246e.
2023-10-22 02:02:35 +03:30
Ali Mohammad Pur
a8c7448ccb Shell: Implement the return POSIX builtin
This is also available in the regular shell mode, as it's a generally
useful builtin to have.
2023-10-17 11:02:48 -06:00
Ali Mohammad Pur
2d1c5dbfcb Shell: Allow word-expansion of ${var}, $N, $* and $-
Fixes #21463.
2023-10-17 11:02:48 -06:00
Ali Mohammad Pur
91bb3af505 Shell: Implement the '$*' special variable in the POSIX parser
Fixes #21421.
2023-10-16 19:11:37 +03:30
Ali Mohammad Pur
5cb994d4dd Shell: Minimally implement the 'set' builtin
This only implements the printing and argv setting behaviours.
2023-10-16 19:11:37 +03:30
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Ali Mohammad Pur
dc495e299e Shell: Add support for the bashy list literals in POSIX mode
This is currently only allowed in assignments, where x=(...) is parsed
as the assignment of the list (...) to the variable x.
2023-10-07 22:16:35 +03:30
Ali Mohammad Pur
986130d9ea Shell: Accept IoNumber as a valid redirection target 2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
0214e9b905 Shell: Rewrite 'FOR NAME do ... done' according to Dr.POSIX
Dr.POSIX says this form of the loop is supposed to iterate over exactly
`"$@"`, this commit makes us support that.
2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
764ea6104e Shell: Treat '(' and '{' as operators in POSIX mode 2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
9e978c6cd1 Shell: Recognise the (seemingly) bash-specific <<\WORD heredoc key
Bash eats the backslash in this format (similarly for W\ORD etc.).
Dr.POSIX doesn't specify this anywhere, but it's used all over the
place, so let's support it.
2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
21ea9cedff Shell: Add the POSIX-only 'eval' builtin
This just concatenates its arguments together, and executes it as a
command.
2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
e2af20a69b Shell: Correct the continue builtin's count guard
This builtin only supports count = 1 (as the error message says), but we
were looking for count = 0.
2023-10-02 21:21:38 +02:00
Ali Mohammad Pur
84777fbe62 Shell: Allow the user to set the prompt using PROMPT()
This allows the prompt to be dynamically configurable, making it
possible to display various bits of information in the prompt.
2023-09-07 11:52:37 -06:00
Ali Mohammad Pur
33a3f0e134 Shell: Implement close redirections in POSIX mode
Fixes #20631.
2023-08-31 11:02:57 +03:30
Ali Mohammad Pur
ba4db899d4 LibSyntax+Userland: Make LibSyntax not depend on LibGUI
This moves some stuff around to make LibGUI depend on LibSyntax instead
of the other way around, as not every application that wishes to do
syntax highlighting is necessarily a LibGUI (or even a GUI) application.
2023-08-29 07:57:39 -04:00
Liav A
fb60db7b00 Shell: Add builtin command to reset the internal state
The new builtin command "reset" now resets the entire internal state by
virtually destructing the Shell state and re-constructing it.

This helps for example when setting a new hostname and wanting to view
it in the current Shell program.
2023-08-11 18:48:53 +03:30
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Andreas Kling
34344120f2 AK: Make "foo"_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Andreas Kling
26647f2b10 LibCore: Remove the Core::Objects::all_objects() list
Nobody actually used the list of all Core::Objects anyway.
2023-08-06 18:09:25 +02:00
ronak69
1453028975 Shell: Color bareword yellow if it's a prefix of at least one command
Before, if a bareword wasn't a runnable program's filename it got
colored red and white otherwise. Now, additionally it will be checked if
it is a "prefix" of a possible command and colored yellow if it is and
red if not.

Coloring this way provides another "feedback" to the user: If while
typing out a command name the color changes from yellow to red then a
typo occurred :^)

To check if a bareword is a prefix the `Shell::complete_program_name()`
function is utilized (if pressing tab gives you some suggestions then it
is a prefix).
2023-08-04 23:27:59 +03:30
Ali Mohammad Pur
da7bf5f785 Shell: Add support for the '!' POSIX pipeline prefix
This prefix simply inverts the exit code of the pipeline, which we
implement using the 'not' builtin.
2023-08-04 13:28:59 +03:30
Ali Mohammad Pur
b6d7c5fb0e Shell: Correctly track nested expansions in POSIX mode
Previously any expansion closing sequence would've caused the entire
expansion chain to be terminated, fix this by keeping track of active
expansions and running the parser in 'skip' mode.

Fixes #19110.
2023-08-04 13:28:59 +03:30