summaryrefslogtreecommitdiff
path: root/Userland/Shell/Shell.cpp
AgeCommit message (Collapse)Author
2021-06-03Everywhere: Replace ctype.h to avoid narrowing conversionsMax Wipfli
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-01AK+Everywhere: Fix compiletime format parsing of replacement fieldsAli Mohammad Pur
2021-06-01LibGUI+Shell+bt+ls: Use proper APIs for creating file URLsMax Wipfli
This patch replaces ad-hoc generation of file URL strings with using URL::create_with_file_scheme().
2021-05-29Everywhere: Sort out superfluous QuickSort.h importsBen Wiederhake
They were sorta unneeded. :^)
2021-05-24LibLine+Shell: Allow some programs to modify the current termiosAli Mohammad Pur
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-13Shell: Fix incorrect fcntl usagesin-ack
FD_CLOEXEC is a file descriptor flag, so one must use F_{G,S}ETFD instead.
2021-05-12LibCore+Everywhere: Move OpenMode out of IODeviceAli Mohammad Pur
...and make it an enum class so people don't omit "OpenMode".
2021-05-11LibLine+Shell: Add dirty history flag and use itsin-ack
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-11Shell: Add an option to autosave history every N msAli Mohammad Pur
...and set it to 10 seconds by default.
2021-05-10Shell: Make escaping more intelligentAli Mohammad Pur
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-07Shell: Convert StringBuilder::appendf() => AK::FormatAndreas Kling
2021-05-02Shell: Only match entries from PATH when a program name is givenAli Mohammad Pur
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-02Shell: Replace fprintf(stderr) => warnln()Ali Mohammad Pur
2021-05-02Shell: Update shebang handling logicAli Mohammad Pur
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-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-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-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-21Shell: Convert String::format() => String::formatted()Andreas Kling
2021-04-20Shell: Auto-completion shouldn't suggest non-executable files for the ↵Gunnar Beutner
program name
2021-04-19Shell: Don't whine about tcsetpgrp() failingAli Mohammad Pur
We intentionally skimp out on checking isatty() before them to cut down on syscalls, so we should also accept the errors and just let them be. Closes #6471.
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-31Shell: Replace '#if SH_DEBUG` with dbgln_if() and if constexprAnotherTest
2021-03-22Shell: Add support for indexing into variablesAnotherTest
Now a variable may have an optional slice (only _one_ slice), which can also use negative indices to index from the end. This works on both lists and strings. The contents of the slice have the same semantics as brace expansions. For example: ```sh $ x=(1 2 3 4 5 6) $ echo $x[1..3] # select indices 1, 2, 3 2 3 4 $ echo $x[3,4,1,0] # select indices 3, 4, 1, 0 (in that order) 4 5 2 1 $ x="Well Hello Friends!" $ echo $x[5..9] Hello ```
2021-03-16Shell: Avoid unnecessarily taking control of the standard streamsAnotherTest
As of a0506cb39e9b1cf67c454a2ccc9473b8cbcd5cd0, this is no longer needed to write to stdout. Fixes #5776.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-08Shell: Don't blindly dereference the result of Parser::parse()AnotherTest
It _may_ return nullptr if there's nothing to return. Fixes #5691.
2021-03-07Shell: Add support for 'immediate' expressions as variable substitutionsAnotherTest
This commit adds a few basic variable substitution operations: - length Find the length of a string or a list - length_across Find the lengths of things inside a list - remove_{suffix,prefix} Remove a suffix or a prefix from all the passed values - regex_replace Replace all matches of a given regex with a given template - split Split the given string with the given delimiter (or to its code points if the delimiter is empty) - concat_lists concatenates any given lists into one Closes #4316 (the ancient version of this same feature)
2021-03-07Shell: Do not parse history events in scriptsAnotherTest
That makes no sense!
2021-03-07Shell: Add functions to the PATH cache when rebuilding the cacheAnotherTest
Otherwise functions would be highlighted as missing.
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-02-28Shell: Remove WAITID_ONCE workaroundAndrew Kaster
This hashmap is no longer necessary, and the shell works just fine without it now. Remove the conditionally compiled code.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-23AK+Userland: Extend the compiletime format string check to other functionsAnotherTest
Thanks to @trflynn89 for the neat implicit consteval ctor trick! This allows us to basically slap `CheckedFormatString` on any formatting function, and have its format argument checked at compiletime. Note that there is a validator bug where it doesn't parse inner replaced fields like `{:~>{}}` correctly (what should be 'left align with next argument as size' is parsed as `{:~>{` following a literal closing brace), so the compiletime checks are disabled on these temporarily by forcing them to be StringViews. This commit also removes the now unused `AK::StringLiteral` type (which was introduced for use with NTTP strings).
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-23Shell: Run the command's next chain even when it's emptyAnotherTest
2021-01-23Shell: Block on the existing event loop instead of pushing a new oneAnotherTest
This patch makes `Shell::block_on_job()` pump the event loop while the job it's waiting for hasn't finished. As this no longer pushes new event loops, it has the effect of flattening the stack as well. Fixes #4976.
2021-01-19Shell: Don't spam perror() on kill_job()AnotherTest
That function is allowed to be given a dead job, so don't bother with perror()
2021-01-19Shell: Make 'if' expressions return the unevaluated value of blocksAnotherTest
This makes it possible to actually put them in a sequence and cast them to commands.
2021-01-19Shell: Actually return the exit code of the file when running a fileAnotherTest
2021-01-16Shell: use exit code 127 on command not foundNick Vella
2021-01-15Shell: Add (basic) support for history event designatorsAnotherTest
Closes #4888
2021-01-12Shell: Use lstat instead of access to check if glob target existsAnotherTest
Fixes #4905
2021-01-12Shell: Move to Userland/Shell/Andreas Kling