summaryrefslogtreecommitdiff
path: root/Userland/Shell
AgeCommit message (Collapse)Author
2022-02-23Shell: Use an opaque color for SyntaxErrorkperdlich
Use an opaque color for SyntaxError in Syntax Highlighter to avoid transparent errors.
2022-02-22Shell: Start history counter from 1Ryan Chandler
Previously would show the list of history items starting from an index of 0. This is a bit misleading though. Running `!0` would actually cause the parser to error out and prevent you from running the command.
2022-02-19Shell: Use an opaque default color for BarewordLiteralkperdlich
Use an opaque default color for BarewordLiteral in Syntax Highlighter to avoid transparent barewords.
2022-02-05Shell: Use strncmp() instead of string.compare() for name completionsAli Mohammad Pur
The "at most n bytes" behaviour of strncmp is required for this logic to work, this was overlooked in 5b64abe when converting Strings to StringViews, which lead to broken autocomplete.
2022-02-04Shell: Add total time to builtin_time Timing ReportTom Martin
2022-01-29Shell: Use StringView instead of String const& where feasibleDaniel Bertalan
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-21Shell: Make Juxtaposition autocompletion smarterAli Mohammad Pur
Now something like `"$HOME"/` autocompletes correctly. Note that only the first element of lists is used to autocomplete things.
2022-01-21Shell: Make SimpleVariable::hit_test_position not hit irrelevant offsetsAli Mohammad Pur
Without this, any offset would be accepted as being part of the SimpleVariable. Fixes #11976 (by making it no longer crash).
2022-01-09Shell: Add a "noop" builtin aliased to ":"Ali Mohammad Pur
POSIX comes up with such silly names sometimes... This builtin does nothing. at all.
2022-01-09Shell: Refresh PATH cache after 'unset PATH'Ali Mohammad Pur
Note that `execvp` has a default value for PATH (both on Serenity and on Linux) and so this does not 'fix' #11608.
2022-01-09Shell: Don't reset 'last_return_code' before running commandsAli Mohammad Pur
Some variables depend on its value to function correctly. Fixes the following issue: $ false; echo $? 1 $ false $ echo $? 128
2022-01-09Shell: Make interrupts kill the whole chain and not just the current jobAli Mohammad Pur
This makes interrupting `sleep 10; echo hi` not print `hi` anymore, which is the expected behaviour anyway. Also fixes the problem with fast-running loops "eating" interrupts and not quitting.
2022-01-09Shell: Port to LibMainLucas CHOLLET
2022-01-04Userland: Fail Core::find_executable_in_path on empty inputsAndrew Kaster
Before this patch, `which ""` or `type ""` would say that the empty string is `/usr/local/bin/`. Convert callers to consistently call is_empty() on the returned string while we're at it, to support eventually removing the is_null() String state in the future.
2021-12-31Shell: Make redirection errors raise ShellErrorsAli Mohammad Pur
Naturally, this means that a command with a failing redirection will not start, and so will terminate the pipeline (if any). This also applies to the `exit` run when the shell is closed, fixing a fun bug there as well (thanks to Discord user Salanty for pointing that out) where closing the terminal (i.e. I/O error on the tty) with a failing `exit` command would make the shell retry executing `exit` every time, leading to an eventual stack overflow.
2021-12-30Shell: Avoid many single byte write() syscalls when printing the promptDaniel Bertalan
Whenever the prompt is printed, we write a line's worth of space characters to the terminal to ensure that the prompt ends up on a new line even if there is dangling output on the current line. We write these to the stderr, which is unbuffered, so each putc() call would come with the overhead of a system call. Let's use a buffer + fwrite() instead, since heap allocation is much faster.
2021-12-16Shell: Don't skip over the first brace expansion entry if it's emptyAli Mohammad Pur
Previously we were simply ignoring the empty entry in '{,x}', making it resolve to a list with a single element '(x)', this commit makes that work as expected and resolve to '("" x)'.
2021-12-16Shell: Set subshell flag after checking for its value in parent shellAli Mohammad Pur
This also reverts commit 07cc7eed295a29afef37c4bfaabaf57a3f4af0c1, as that attempted to fix the issue this caused (and succeeded...but it broke something else on linux).
2021-12-13Shell: Make the Join operation respect nodes that have a next chainAli Mohammad Pur
This would show up when resolving aliases, when an alias contains a sequence. Fixes #11219.
2021-12-13Shell: Remove sigpipe.sh.out artefact after failureMichel Hermier
Helps to avoid to erroneously add the file to git.
2021-12-11Everywhere: Fix -Winconsistent-missing-override warnings from ClangDaniel Bertalan
This option is already enabled when building Lagom, so let's enable it for the main build too. We will no longer be surprised by Lagom Clang CI builds failing while everything compiles locally. Furthermore, the stronger `-Wsuggest-override` warning is enabled in this commit, which enforces the use of the `override` keyword in all classes, not just those which already have some methods marked as `override`. This works with both GCC and Clang.
2021-12-05Shell: Cast unused smart-pointer return values to voidSam Atkins
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-10AK+Everywhere: Stop including Vector.h from StringView.hAndreas Kling
Preparation for using Error.h from Vector.h. This required moving some things out of line.
2021-11-08Shell: Replace Result<T, E> use with ErrorOr<T>Andreas Kling
2021-11-06Shell: Add min and max iteration times to `time -n` in builtin_timeMusab Kılıç
2021-11-01Everywhere: Remove unused ArgsParser headerBen Wiederhake
Found while trying to enumerate all programs that use ArgsParser.
2021-10-31Shell: Unwind execution after runtime errorsAli Mohammad Pur
This commit makes the Shell check for errors after a node is run(), and prevents further execution by unwinding until the error is cleared. Fixes #10649.
2021-10-23Shell: Prevent exponential explosion around '$(('Ben Wiederhake
When parse_expression looks at '$((', there are two ways it can end up in parse_expression again, three consumed characters later. All these ways fail, so what happened was that the parser tried all possible combinations, hence taking potentially an exponential amount of time. 1. parse_evaluate swallows the '$(', a new invocation of parse_expression swallows the other '(', and through parse_list_expression we're at another parse_expression. 2. parse_evaluate swallows the '$(', but returns a SyntaxError. parse_expression used to not recognize the error, and treated it as a regular AST node, calling into read_concat, then a new invocation of parse_expression swallows the other '(', and through parse_list_expression we're at another parse_expression. Fixes #10561. Found by OSS Fuzz, long-standing issue https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28113
2021-10-11Shell: Raise an error if an execute node ends up trying to run nothingAli Mohammad Pur
...while capturing its standard output. As `$()` is an invalid construct, execute nodes are not supposed to capture the output of no command being run; but it is possible to create empty commands such as CastToCommand(Redirection(...)) or similar. Make this a hard error instead of an unescapable select(). This was noticed in #10432, which should now error out like so: ``` Error: Cannot capture standard output when no command is being executed 0| $(<$file) ~~~~~^^^^^^^^^ 1| ```
2021-10-08Shell: Fix -Wunreachable-code warnings from clangNico Weber
2021-09-20Shell: Make ArgsParser not exit on failure in builtin_exit()Ali Mohammad Pur
Fixes #10128.
2021-09-16Shell: Use default instead of an empty constructor/destructorBrian Gianforcaro
Default implementations allow for more optimizations. See: https://pvs-studio.com/en/docs/warnings/v832/
2021-09-12Shell: Use ElapsedTimer::start_new()Brian Gianforcaro
2021-09-07Everywhere: Behaviour => BehaviorAndreas Kling
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-03Everywhere: Prevent risky implicit casts of (Nonnull)RefPtrDaniel Bertalan
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
2021-09-03AK: Rename create<T> => make_ref_counted<T>Andreas Kling
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
2021-09-02Userland: Migrate to argument-less deferred_invokesin-ack
Only one place used this argument and it was to hold on to a strong ref for the object. Since we already do that now, there's no need to keep this argument around since this can be easily captured. This commit contains no changes.
2021-08-31Shell: Use new Statistics tool in 'time -n' commandTobias Christiansen
The new Statistics utility is now used when calling 'time -n' to get some more information of the timings. For now only the standard deviation is given in addition to the average. This commit completely undos #9645 because everything that touched moved into AK::Statistics.
2021-08-30Shell: Fix a TOCTOU in `popd` by simplifying itAndreas Kling
This builtin was doing a lot of redundant work, including doing a stat() followed by a chdir(), when just a chdir() would suffice. SonarCloud: https://sonarcloud.io/project/issues?id=SerenityOS_serenity&issues=AXuVPAHNk92xXUF3qTNb&open=AXuVPAHNk92xXUF3qTNb
2021-08-28Shell: Use a relative path in builtin_cd for chdir if possibleAli Mohammad Pur
This kinda sorta addresses the Shell side of #9655, however the fact that `chdir` (and most other syscalls that take paths) are artifically limited to a length of PATH_MAX remains.
2021-08-27Shell: Use variable instead of iteration_times.size() in builtin_timeMusab Kılıç
2021-08-27Shell: Add iteration_times.ensure_capacity() in builtin_timeMusab Kılıç
2021-08-23Shell: Use String::join for the command in timing reportRalf Donau
2021-08-23Shell: Avoid a needless loop in builtin_time()Valtteri Koskivuori
Not performance sensitive, but perhaps a bit neater? :^)
2021-08-23Shell: Support `time -n <iterations>`Andreas Kling
You can now specify a number of iterations when timing a command. The default value is 1 and behaves exactly as before. If the iteration count is greater than 1, the command will be executed that many times, and then you get a little timing report afterwards with the average runtime per iteration, and also the average runtime excluding the very first iteration. (Excluding the first iteration is useful when it's slowed down by cold caches, etc.) This is something I've been doing manually forever (running `time foo` and then eyeballing the results to headmath an average) and this makes that whole process so much nicer. :^)
2021-08-19AK: Move FormatParser definition from header to implementation fileTimothy Flynn
This is primarily to be able to remove the GenericLexer include out of Format.h as well. A subsequent commit will add AK::Result to GenericLexer, which will cause naming conflicts with other structures named Result. This can be avoided (for now) by preventing nearly every file in the system from implicitly including GenericLexer. Other changes in this commit are to add the GenericLexer include to files where it is missing.