Commit Graph

123 Commits

Author SHA1 Message Date
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
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
Andreas Kling
686ade6b5a AK: Make quick_sort() a little more ergonomic
Now it actually defaults to "a < b" comparison, instead of forcing you
to provide a trivial less-than comparator. Also you can pass in any
collection type that has .begin() and .end() and we'll sort it for you.
2020-03-03 16:02:58 +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
24a5a6cd2c Shell: Remove bogus assertion 2020-03-01 17:08:49 +01:00
Andreas Kling
2695773dd2 Shell: Handle the "delete" key correctly
We were deleting the wrong character in the line buffer, oopsie!
2020-03-01 16:32:35 +01:00
Andreas Kling
22d0a6d92f AK: Remove unnecessary casts to size_t, after Vector changes
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
2020-03-01 12:58:22 +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
Shannon Booth
90f40a80f4 Shell: Make some functions const 2020-02-22 21:36:54 +01:00
Shannon Booth
859c1669f9 Shell: Add basic tilde expansion
This does not work with shell completion yet, but the basics of being
able a cd being able to expand "~" to the current user's home directory,
and "~foo" to the home directory of user "foo" is added in this commit

Work towards: #115
2020-02-22 21:36:54 +01:00
Shannon Booth
20d9c431ce Shell: Use SkipParentAndBaseDir flag in DirIterator 2020-02-15 11:40:05 +01:00
Andreas Kling
8262c1e662 Shell: Build prompt based on the PROMPT environment variable if present 2020-02-10 21:52:58 +01:00
Andreas Kling
d17e23bd27 LibCore: Remove leading C from filenames 2020-02-06 15:04:03 +01:00
Andreas Kling
2d39da5405 LibCore: Put all classes in the Core namespace and remove the leading C
I've been wanting to do this for a long time. It's time we start being
consistent about how this stuff works.

The new convention is:

- "LibFoo" is a userspace library that provides the "Foo" namespace.

That's it :^) This was pretty tedious to convert and I didn't even
start on LibGUI yet. But it's coming up next.
2020-02-02 15:15:30 +01:00
Andreas Kling
7454926765 Shell: If a command process is stopped, print the stop signal to stderr 2020-01-27 20:48:42 +01:00
Andreas Kling
c303f55b60 Shell: Don't start a new session in every new shell
The session should be started at a higher level, i.e the Terminal app.
2020-01-25 14:51:23 +01:00
Andreas Kling
ed90d39cd7 Shell: Allow empty tokens if enclosed in single or double quotes
Previously the shell parser would discard empty tokens. We now allow
them when they are enclosed in quotes (either '' or "")

This means that a command like _echo ""_ will actually pass an empty
string to /bin/echo in argv[1] now.
2020-01-25 12:16:45 +01:00
Andreas Kling
41716aebde Shell: Disable SH_DEBUG by default and tidy up command timing logging 2020-01-21 16:22:31 +01:00
Andreas Kling
6ca1a46afd Shell: Don't crash when stdout is not a TTY
Let's just pretend we have 80 columns while running non-interactively.
There are definitely nicer solutions here, and we should find them.
2020-01-19 13:52:44 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling
1b9f4c7c40 Shell: Fix broken debug logging about waiting on children 2020-01-12 10:03:06 +01:00
Andreas Kling
1934a1ec0b Shell: Use pledge() 2020-01-11 21:33:07 +01:00