summaryrefslogtreecommitdiff
path: root/Userland/Shell/Builtin.cpp
AgeCommit message (Collapse)Author
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-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-05Shell: Cast unused smart-pointer return values to voidSam Atkins
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-06Shell: Add min and max iteration times to `time -n` in builtin_timeMusab Kılıç
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-12Shell: Use ElapsedTimer::start_new()Brian Gianforcaro
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-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-07-13Shell: Add unalias builtinTheFightingCatfish
Add shell unalias builtin to remove aliases
2021-07-08Shell: Use correct printf format string for `size_t`Daniel Bertalan
2021-06-30AK: Remove the LexicalPath::is_valid() APIMax Wipfli
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-08Shell: Make `time` stop parsing options on first non-optionJelle Raaijmakers
2021-06-08LibCore: Support fine-grained failure behavior for ArgsParserJelle Raaijmakers
2021-05-07Shell: Convert StringBuilder::appendf() => AK::FormatAndreas Kling
2021-05-02Shell: Replace fprintf(stderr) => warnln()Ali Mohammad Pur
2021-04-29Everywhere: Use "the SerenityOS developers." in copyright headersLinus Groh
We had some inconsistencies before: - Sometimes "The", sometimes "the" - Sometimes trailing ".", sometimes no trailing "." I picked the most common one (lowecase "the", trailing ".") and applied it to all copyright headers. By using the exact same string everywhere we can ensure nothing gets missed during a global search (and replace), and that these inconsistencies are not spread any further (as copyright headers are commonly copied to new files).
2021-04-25Everywhere: Remove empty line after function body opening curly braceLinus Groh
2021-04-23Shell: Add a 'kill' builtin that wraps the system's ownAli Mohammad Pur
Fixes #6578.
2021-04-23Shell: Add support for jobspecs in fg/bg/disown/waitAli Mohammad Pur
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-23Shell: Fix how cd handles the path argumentGunnar Beutner
Previously this didn't work: $ cd -- /usr Invalid path '--' This path fixes this issue and removes the unnecessary else branch because we're already using realpath() later on to resolve relative paths.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-13Shell: flush stderr and stdout when using builtinsjacob gw
This fixed some tests that were failing. Thanks @alimpfard for this fix!
2021-04-13Shell: add `type` builtinjacob gw
2021-03-31Shell: Handle SIGCHLD after sending SIGCONT to jobAnotherTest
This fixes `fg` and `bg` causing the shell to go into an infinite loop of trying to `waitpid` until some current job changes state. a.k.a. "Fix Shell backgrounding, yet again!" :P
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-07Shell: Make the 'not' builtin return the correct exit code for functionsAnotherTest
2021-03-07Shell: Skip caching PATH and history load/save when not interactiveAnotherTest
Non-interactive shells (i.e. when running scripts) do not need this functionality, so they are a boatload of wasted time. This significantly reduces the script startup and shutdown times when there are lots of executables in PATH or lots of entries in the history.
2021-01-19Shell: Add a `not` builtinAnotherTest
`not` just takes a command, runs it, then negates its exit code (0->1, non-zero->0).
2021-01-19Shell: Add a builtin that parses its sole argument and dumps its ASTAnotherTest
Pretty useful for debugging.
2021-01-12Shell: Move to Userland/Shell/Andreas Kling