summaryrefslogtreecommitdiff
path: root/Userland/Shell
AgeCommit message (Collapse)Author
2022-07-12Everywhere: Replace single-char StringView op. arguments with charssin-ack
This prevents us from needing a sv suffix, and potentially reduces the need to run generic code for a single character (as contains, starts_with, ends_with etc. for a char will be just a length and equality check). No functional changes.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Everywhere: Explicitly specify the size in StringView constructorssin-ack
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
2022-07-12Userland: Convert command line arguments to String/StringViewsin-ack
StringView was used where possible. Some utilities still use libc functions which expect null-terminated strings, so String objects were used there instead.
2022-07-08Userland: Add `/usr/local/sbin` to `PATH` by defaultTim Schumacher
`e2fsprogs` adds its tools there.
2022-07-04Shell: Immediately resolve value when setting a variableAli Mohammad Pur
The lazy resolution mechanism made it so that the variables were linked together, causing unexpected behaviour: true x=$? # expected: x=0 false echo $x # expected: 0, actual: 1
2022-06-24Shell: Ignore SIGCHLD after a few unsuccessful attempts at handling itAli Mohammad Pur
As noted by the comment, a stray SIGCHLD can make the shell go into an infinite loop, pretend the signal doesn't exist after trying 10 times in 5ms.
2022-05-21LibCodeComprehension: Re-organize code comprehension related codeItamar
This moves all code comprehension-related code to a new library, LibCodeComprehension. This also moves some types related to code comprehension tasks (such as autocomplete, find declaration) out of LibGUI and into LibCodeComprehension.
2022-04-21Shell: Highlight commands with a hyperlink to open their help pagesForLoveOfCats
2022-04-18Shell: Make program-based completion with no actual token possibleAli Mohammad Pur
31ca48e made this default to paths, but now that we have a few sensible ways to complete things, let's make those work too. For instance, prior to this `kill <tab>` would've suggested paths, but now it will suggest processes.
2022-04-18LibLine: Make it possible to avoid autocompletion if requestedAli Mohammad Pur
Setting 'allow_commit_without_listing' to false will now make LibLine show the suggestion before actually committing to it; this is useful for completions that will replace all the user input, where mistakes can go unnoticed without some visual cue.
2022-04-18LibLine: Respect the provided completion static offsetAli Mohammad Pur
Now that we can resolve these correctly and they're per-suggestion, we can finally use them for their intended purpose of letting suggestions overwrite stuff in the buffer.
2022-04-18Shell: Allow completions to request further action from the shellAli Mohammad Pur
The shell now expects a JSON object of the form {"kind":<kind>,...} per line in the standard output of the completion process, where 'kind' is one of: - "plain": Just a plain suggestion. - "program": Prompts the shell to complete a program name starting with the given "name". - "proxy": Prompts the shell to act as if a completion for "argv" was requested. - "path": Prompts the shell to complete a path given the "base" and "part" (same as completing part in cwd=base).
2022-04-18Shell: Add support for regex match patternsAli Mohammad Pur
We previously allowed globs as match pattern, but for more complex matching needs, it's nice to have regular expressions. And as the existing "name a part of the match" concept maps nicely to named capture groups, we can simply reuse the same code and make groups with names available in the match body.
2022-04-15Shell: Complete for current path when the text is emptyDamien Firmenich
For example, when typing `cd <tab>`, the shell will show a list of files in the current directory. This behavior is similar to typing `cd ./<tab>`. It makes it easier to `cd` into directories without having to list them first.
2022-04-11Shell: Read script arguments as Strings instead of char*sSam Atkins
This saves work in places that previously had to create a `Vector<String>` anyway, or repeatedly cast the char* to a String. Plus, Strings are nicer than char*. :^)
2022-04-09LibGfx: Move other font-related files to LibGfx/Font/Simon Wanner
2022-04-03Shell: Use default execpromises parameter to `pledge(..)`Brian Gianforcaro
2022-04-03Shell: Refresh PATH cache after running shellrc filesHumberto Alves
This fixes the highlight of runnable commands, whenever PATH variable is changed in one of the shellrc files.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-29Shell: Add a shell option for autocompleting via the program itselfAli Mohammad Pur
This feature needs a bit more work, so let's disable it by default. Note that the shell will still use _complete_foo if it is defined regardless of this setting.
2022-03-27Shell: Keep the stdio and rpath pledges for execute_process()Ali Mohammad Pur
If the command fails, we'd like to still be capable of printing out diagnostics, so restore stdio and rpath. Fixes #13281.
2022-03-26Shell: Limit the access of processes spawned for autocompletionAli Mohammad Pur
This commit limits the autocomplete processes to effectively have readonly access to the fs, and only enough pledges to get the dynamic loader working.
2022-03-26Shell+LibCore: Provide argument help strings as display triviaAli Mohammad Pur
2022-03-26Shell: Add an ArgsParser-based argument parser builtinAli Mohammad Pur
Afterall, why _shouldn't_ Shell functions have nice interfaces? also helps with autocompletion :^)
2022-03-26Shell: Implement program-aware autocompletionAli Mohammad Pur
A program can either respond to `--complete -- some args to complete` directly, or add a `_complete_<program name>` invokable (i.e. shell function, or just a plain binary in PATH) that completes the given command and lists the completions on stdout. Should such a completion fail or yield no results, we'll fall back to the previous completion algorithm.
2022-03-26Shell: Add the 'join' and 'filter_glob' immediate functionsAli Mohammad Pur
'split' was missing its other half, and to avoid globbing the filesystem, let's keep the globbing to shell-internal state.
2022-03-24Shell: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-11Shell: Stop parsing options after the script nameTim Schumacher
2022-03-06Shell: Be more smart with pasted stuffAli Mohammad Pur
Shell can now use LibLine's `on_paste` hook to more intelligently escape pasted data, with the following heuristics: - If the current command is invalid, just pile the pasted string on top - If the cursor is *after* a command node, escape the pasted data, whichever way yields a smaller encoding - If the cursor is at the start of or in the middle of a command name, paste the data as-is, assuming that the user wants to paste code - If the cursor is otherwise in some argument, escape the pasted data according to which kind of string the cursor is in the middle of (double-quoted, single-quoted or a simple bareword)
2022-03-06Shell: Implement leftmost_trivial_literal() for Sequence nodesAli Mohammad Pur
2022-03-06Shell: Allow completing StringLiterals as pathsAli Mohammad Pur
This auto-escapes the token as well :^)
2022-03-06LibLine+Userland: Make suggestion offsets per-suggestionAli Mohammad Pur
This allows the user to modify different parts of the input with different suggestions.
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.