Commit Graph

111 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
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
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
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
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
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
Stephan Unverwerth
13c122b8b2 Shell: use access() syscall to check if files are executable by user 2020-04-27 11:13:59 +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
AnotherTest
2a460aa369 Shell: Do not manually write to the editor buffer when completing paths 2020-04-13 00:49:24 +02:00
AnotherTest
2fdce695d6 LibLine: Display suggestions and cycle between them
With extra color (tm)
This commit also patches the users of LibLine to properly use the new
API
2020-04-11 17:15:19 +02:00
Andreas Kling
8ab576308f LibLine: Rename LineEditor.{cpp,h} => Editor.{cpp,h} 2020-03-31 13:34:57 +02:00
Andreas Kling
6595469de1 LibLine: Rename LineEditor to Line::Editor 2020-03-31 13:34:06 +02:00
Andreas Kling
a30a3277a3 LibLine: Rename from LibLineEdit 2020-03-31 13:32:11 +02:00
AnotherTest
6f407fff32 LibLineEdit + Shell: Handle Termios internally and give a copy if asked
This moves the Termios logic inside LibLineEdit and allows users to
simply forget about the existence of termios if they so choose to :^)
2020-03-31 13:21:46 +02:00
AnotherTest
5062a7d4cd LibLinEdit + Shell: handle signals
This allows the LineEditor to get notified about signals, since we
cannot set signal handlers in a clean way within the LineEditor
instance.
2020-03-31 13:21:46 +02:00
AnotherTest
21c4c67119 Shell: Move LineEdit out and add it as a dependency
This builds up on the 'new' LibLineEdit and overrides some of its hooks
For instance, on_tab_complete_first_token
2020-03-31 13:21:46 +02:00
Andreas Kling
fb2be5c404 Shell: Shorten $HOME to '~' in shell prompts
The "\w" substitution in shell prompts now uses '~' to represent the
user's home directory (technically, whatever $HOME contains.)
2020-03-30 18:08:47 +02:00
Andreas Kling
5c37570dfc Shell: Stop making shell history files world-readable
\0 pointed out that it's pretty bad to have world-readable .history
files, especially for root's shell!
2020-03-30 12:09:26 +02:00
Shannon Booth
d0629d0a8c Shell: More general tilde expansion
Now expanding a tilde isn't hardcoded to just work for `cd`. It is instead
expanded while processing shell arguments. Autocompletion still doesn't
work, but this is definitely an improvement over the last iteration.
2020-03-22 01:15:33 +01:00
Shannon Booth
1ef3d4af69 Shell: Use starts_with() in expand_parameters
This reads a little nicer, and makes us care less about an empty String
2020-03-22 01:15:33 +01:00
Shannon Booth
d806dfe801 Shell: Use size_t for SH_DEBUG vector iteration
We missed this when switching to size_t for vector sizing as this
code is not normally compiled.
2020-03-22 01:15:33 +01:00
Shannon Booth
0de2ead0e9 Shell: Validate only one directory is given to cd 2020-03-09 19:35:36 +01:00
Shannon Booth
d0fb816ac3 Shell: Implement a "cd history" (cdh) builtin
`cdh` with no arguments dumps the last 8 cd calls in history, and
`cdh [index]` can be used to cd to re-run a specific index from that
history. `cdh` itself it a thin wrapper of the `cd` builtin.

There's definitely some improvements that can be made for this command,
but this seems like a good starting point for getting a feel for it and
ideas for changing it in the future.

It's not entirely clear whether we should be storing the resolved path -
or simply just the last argument passed to cd. For now we just use the
last path passed into cd as this seemed like the better option for now.

This means:
 * invalid paths will still be stored in history (potentially useful)
 * cdh's can be repeated for duplicate directory names
 * the history looks a little nicer on the eyes

It might make sense to use resolved paths.

Closes #397
2020-03-09 19:35:36 +01:00
Andreas Kling
8f25dbf394 Shell: Fix silly stack overflow in 'cd' builtin
Let's write in C++ and we won't have as many C problems. :^)
2020-03-07 11:02:11 +01:00
Andreas Kling
4a271430f8 Shell: Set up the PWD environment variable early
This ensures that PWD is set when running "sh -c something"
2020-03-07 00:25:30 +01:00
howar6hill
055344f346 AK: Move the wildcard-matching implementation to StringUtils
Provide wrappers in the String and StringView classes, and add some tests.
2020-03-02 10:38:08 +01:00
Andreas Kling
559a99c104 Shell: Don't pass nonsense options to waitpid()
I had these options confused with the options for waitid()
2020-02-25 16:08:44 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00