Commit graph

161 commits

Author SHA1 Message Date
AnotherTest
889a8e7d0f LibLine: Handle interrupts again
This commit makes LibLine handle interrupts (as reported via
interrupted() and resized()) again.
There is a little catch with the shell:
```
$     ls |
pipe> <C-c> (prompt stays here until a key is pressed)
```
2020-06-01 19:52:20 +02:00
AnotherTest
8c05e78b6c Shell: Treat ^D as builtin_exit when not in a continuation 2020-05-30 23:01:36 +02:00
AnotherTest
77039e5354 Shell: Correctly complete paths in redirections
This commit allows the Shell to complete paths in redirections.
A closing quote is added if the path is an unclosed quote.
```
$ foo > "foob<tab>
$ foo > "foobar"
```
2020-05-30 00:36:51 +02:00
AnotherTest
abfcd7b1b8 Shell: Save the history when quitting via the exit builtin 2020-05-27 11:13:02 +02:00
AnotherTest
ce61cad933 Shell: Never assign equal job ids to two different jobs
Since the last job need not have an ID of size()-1, we need to find the
max job id and give that+1 out
2020-05-27 11:13:02 +02:00
AnotherTest
d582c03233 Shell: Provide some information to inspectors 2020-05-27 11:13:02 +02:00
AnotherTest
d5e9213683 Shell: Avoid messing with sigaction while waiting for a child 2020-05-27 11:13:02 +02:00
AnotherTest
70a213a6ec LibLine: Use Core::EventLoop for outer read loop
This commit changes LibLine's internal structure to work in an event
loop, and as a result, also switches it to being a Core::Object.
2020-05-27 11:13:02 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Sergey Bugaev
4139838a93 Userland et al: Pledge sigaction when needed
* In some cases, we can first call sigaction()/signal(), then *not* pledge
  sigaction.
* In other cases, we pledge sigaction at first, call sigaction()/signal()
  second, then pledge again, this time without sigaction.
* In yet other cases, we keep the sigaction pledge. I suppose these could all be
  migrated to drop it or not pledge it at all, if somebody is interested in
  doing that.
2020-05-26 14:35:10 +02:00
AnotherTest
42114c5784 Shell: Refuse to be suspended with ^Z
Suspending the shell while interacting with it is pretty weird, so let's
just disallow this behaviour.
2020-05-25 21:36:51 +02:00
AnotherTest
bc9013f706 LibLine: Change get_line to return a Result<String, Error>
This fixes a bunch of FIXME's in LibLine.
Also handles the case where read() would read zero bytes in vt_dsr() and
effectively block forever by erroring out.

Fixes #2370
2020-05-25 21:36:51 +02:00
AnotherTest
b4ca563637 Shell: Warn the user about active jobs on exit
And make sure that the user means to exit and kill current jobs before exiting.
2020-05-25 00:08:32 +02:00
AnotherTest
c23c354779 Shell: Parse and correctly evaluate 'command &' and 'command &&'
This commit adds the InBackground and ShortCircuitOnFailure attributes
to commands, which respectively cause the command to be run in the
background, and abort the command chain with exit status != 0.
2020-05-25 00:08:32 +02:00
AnotherTest
143be7234f Shell: Kill existing jobs when exiting 2020-05-25 00:08:32 +02:00
AnotherTest
0d39418b0b Shell: Add the `disown' shell builtin 2020-05-25 00:08:32 +02:00
AnotherTest
2b3e9c28b2 Shell: Take whitespace into account when suggesting tokens
Prior to this, we did not care if there was any whitespace after the
last token in the prompt, and this caused a regression:
```
> lsp <tab>
> lsp ci
```
2020-05-23 01:31:41 +02:00
AnotherTest
0751592a18 LibLine: Correctly track the completion start and end
To achieve this, the API was tweaked a bit to allow for easier tracking
of completions.
This API change is non-disruptive to any application that does not use
anchored styles.
2020-05-21 10:52:11 +02:00
AnotherTest
5358608a94 Shell: Attach links to completed paths
```
ls ./Ter<tab>
```
gets you a link to ./Terminal.ini, right in the prompt.
2020-05-21 01:37:19 +02:00
AnotherTest
7fba21aefc LibLine: Unify completion hooks and adapt its users
LibLine should ultimately not care about what a "token" means in the
context of its user, so force the user to split the buffer itself.
This also allows the users to pick up contextual clues as well, since
they have to lex the line themselves.

This commit pacthes Shell and the JS repl to better handle completions,
so certain wrong behaviours are now corrected as well:
- JS repl can now complete "Object . getOw<tab>"
- Shell can now complete "echo | ca<tab>" and paths inside strings
2020-05-20 13:41:37 +02:00
AnotherTest
3bc3f36cfe LibLine: Handle unicode correctly
This commit also fixes a problem with us throwing out data that was
inserted while a command was running.
2020-05-18 11:31:43 +02:00
AnotherTest
1469d20e63 Shell: Treat builtin names as programs and suggest them 2020-05-17 12:54:31 +02:00
Andreas Kling
656d1e1318 Shell: Print the full name of missing interpreters
We were missing two characters at the end due to a mix-up when skipping
over the first two characters ("#!")
2020-05-17 12:33:28 +02:00
AnotherTest
a398898c12 Shell: Switch to using Core::EventLoop
This commit refactors Shell to a Core::Object and switches its looping
to Core::EventLoop.
2020-05-17 11:58:08 +02:00
AnotherTest
172df68666 Shell: Patch most of the builtins to use Core::ArgsParser
The remaining one is 'pushd', which seems to have relatively complex
logic with regards to its arguments.
2020-05-17 11:58:08 +02:00
AnotherTest
e630d83633 Shell: Add job control capabilities
This patchset adds the `jobs`, `fg` and `bg` builtins.
2020-05-17 11:58:08 +02:00
Linus Groh
b11c7ad2ba Shell: Properly handle parser syntax errors
In the case of a syntax error the shell parser prints an error message
to stderr and returns an empty Vector<Command> - in that case we
shouldn't try to determine whether or not we can continue parsing but
abort immediately - is_complete() expects that *something* was parsed
successfully.

Fixes #2251.
2020-05-16 20:57:33 +02:00
Shannon Booth
154a6e69a4 Shell: Use DirIterator::SkipParentAndBaseDir 2020-05-16 10:09:00 +02:00
AnotherTest
6fcdfe1169 Shell: Correct program stop behaviour
Prior to this, we would only wait for program exit; the shell should
stop waiting once the program has been stopped.
Fixes #2230
2020-05-15 14:44:57 +02:00
Sergey Bugaev
7aad44b825 Shell: Print correct errno when execvp() fails
Amusingly enough, this was caused by yet another bug.
2020-05-15 11:43:58 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
AnotherTest
6cd4d136a0 Shell: Break out of continuation when ^C is pressed
This fixes the little issue with Shell not allowing cancellation of
commands once they were in continuation mode
```
$ ls '
$ # No matter what we do here, we cannot escape 'ls'
```
2020-05-13 15:07:44 +02:00
Andreas Kling
c50672a19d Shell: Hyperlink output from "pwd" and "dirs" built-ins :^) 2020-05-10 16:24:59 +02:00
AnotherTest
6b674db855 Shell: Support basic syntax highlighting 2020-05-10 10:23:05 +02:00
AnotherTest
1d0d0e9d00 Shell: Parse comments 2020-05-10 10:23:05 +02:00
AnotherTest
a862c230b1 Shell: Include some metadata in parsed tokens and ask for continuation
This patchset adds some metadata to Parser::parse() which allows the
Shell to ask for the rest of a command, if it is not complete.
A command is considered complete if it has no trailing pipe, or
unterminated string.
2020-05-10 10:23:05 +02:00
Andrew Kaster
3cae4cee81 Shell: Check for invalid #! in commands 2020-05-04 09:39:05 +02:00
AnotherTest
0fb4a808ef Shell: Provide the correct invariant length to the line editor 2020-04-30 10:47:22 +02:00
AnotherTest
a80ddf584f Shell+LibLine: Handle escaped characters correctly
This patchset fixes incorrect handling of escaped tokens (`a\ b`) in
Shell autocompletion and LibLine.
The users of LibLine can now choose between two token splitting modes,
either taking into account escapes, or ignoring them.
2020-04-30 09:07:38 +02:00
AnotherTest
fb63b84c78 Shell: Correctly parse quoted filenames in redirection
This commit fixes the (incorrect) behaviour of treating quotes as part
of the redirection filename.

Fixes #1857 :^)
2020-04-30 08:51:54 +02:00
Stephan Unverwerth
13c122b8b2 Shell: use access() syscall to check if files are executable by user 2020-04-27 11:13:59 +02:00
Luke Payne
f191b84b50 Kernel: Added the ability to set the hostname via new syscall
Userland/hostname: Now takes parameter to set the hostname
LibC/unistd: Added sethostname function
2020-04-26 12:59:09 +02:00
Andreas Kling
a19690170f LibCore: Make Core::File::open() return a Result<NNRP<File>, String>
It was impractical to return a RefPtr<File> since that left us no way
to extract the error string. This is usually needed for the UI, so the
old static open() got basically no use.
2020-04-21 16:19:18 +02:00
AnotherTest
0e5191de49 Shell: Correct suggestion of directories 2020-04-19 19:39:50 +02:00
AnotherTest
cb3cf589ed LibLine: Allow suggestions to have trailing trivia strings
These strings would be applied when inserted into the buffer, but are
not shown as part of the suggestion.

This commit also patches up Userland/js and Shell to use this
functionality
2020-04-19 17:21:55 +02:00
Linus Groh
2623bd711b Shell: Don't return early if command is in PATH and a directory 2020-04-19 17:17:17 +02:00
Linus Groh
fc09767872 Shell: Explicitly check if command is a directory
This is a bit nicer than getting "Exec format error" after trying to
execvp() a directory.
2020-04-19 15:37:07 +02:00
Stephan Unverwerth
f0fd85dc1b Shell: Suggest local executables and directories
...when no matching executable could be found in $PATH
2020-04-13 23:21:28 +02:00
AnotherTest
c112f53357 Shell: Complete .hidden files if token starts with a dot 2020-04-13 00:49:24 +02:00
AnotherTest
d3e735f279 Shell: Avoid spamming debug output with suggestions 2020-04-13 00:49:24 +02:00