Commit Graph

128 Commits

Author SHA1 Message Date
ridiculousfish
6705a2efc6 Migrate a bunch of code out of common.h
Put it into wcstringutil, path, or a new file null_terminated_array.
2020-01-15 13:16:43 -08:00
Johannes Altmanninger
9f48fc6285 Fix status when function/block evaluation is cancelled
It looks like the last status already contains the signal that cancelled
execution.

Also make `fish -c something` always return the last exit status of
"something", instead of hardcoded 127 if exited or signalled.

Fixes #6444
2019-12-23 17:38:19 +01:00
Mathieu Duponchelle
15c1b3ed4b Place fish in its own process group when launched with -i
Fixes #5909
2019-12-23 10:32:37 +01:00
ridiculousfish
c19407ab0f Default parser_t::eval()'s block type to top
This is the parameter value at every call site except one. Just make it the
default.
2019-12-22 16:27:03 -08:00
ridiculousfish
a59f35a378 Make block_type_t an enum class 2019-12-22 15:37:14 -08:00
ridiculousfish
09f8e05b80 Clean up the return type of parser_t::eval
parser_t::eval indicates whether there was a parse error. It can be
easily confused with the status of the execution. Use a real type to
make it more clear.
2019-12-17 16:16:43 -08:00
Rosen Penev
586ac3dfa7 [clang-tidy] Convert loops to range based
Found with modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
1055ff321c [clang-tidy] Replace NULL with nullptr
Found with modernize-use-nullptr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
0dfa7421f3 [clang-tidy] Convert C casts to C++ ones
Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
7f62e30731 [clang-tidy] Replace size comparisons with empty
Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
ridiculousfish
03a289c9ef Add an aliases benchmark 2019-11-23 11:53:49 -08:00
ridiculousfish
82eca4bc86 Run clang-format on all files
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
ridiculousfish
f7e2e7d26b Don't generate exit events for jobs created from within event handlers
Add a new job property from_event_handler, and do not create exit events for
such jobs. This prevents easy accidental infinite recursion.
2019-06-26 17:30:51 -07:00
yogendra
6bed255a52 Fix Issue 5910 2019-06-14 08:56:42 -07:00
ridiculousfish
ff55249447 Make events per-parser
This makes the following changes:

1. Events in background threads are executed in those threads, instead of
being silently dropped

2. Blocked events are now per-parser instead of global

3. Events are posted in builtin_set instead of within the environment stack

The last one means that we no longer support event handlers for implicit
sets like (example) argv. Instead only the `set` builtin (and also `cd`)
post variable-change events.

Events from universal variable changes are still not fully rationalized.
2019-06-03 02:48:35 -07:00
ridiculousfish
63a16befd4 Introduce the fish log, a replacement for debug()
This adds a new mechanism for logging, intended to replace debug().

The entry points are FLOG and FLOGF. FLOG can be used to log a sequence of
arguments, FLOGF is for printf-style formatted strings.

Each call to FLOG and FLOGF requires a category. If logging for a category
is not enabled, there is no effect (and arguments are not evaluated).

Categories may be enabled on the command line via the -d option.
2019-05-27 17:24:52 -07:00
ridiculousfish
d5f2d472d0 Thread a parser into reader
Eliminates uses of principal_parser
2019-05-26 18:51:47 -07:00
ridiculousfish
e91d68266c Eliminate reader_current_filename
Store this in the parser libdata instead.
2019-05-22 13:51:27 -07:00
ridiculousfish
c44dae2d73 Migrate certain runtime flags to atomics hidden behind functions 2019-05-18 18:50:28 -07:00
ridiculousfish
4fcb9d1fed Hide no_exec behind a function 2019-05-18 18:50:28 -07:00
Fabian Homborg
e22422c073 Don't do fish_setlocale that early
This just sets some special characters that we use in the reader, so
it only needs to be done before the reader is set up.

Which, as it stands, is in env_init().
2019-05-13 16:09:37 +02:00
ridiculousfish
1719d6f136 Make $status and $pipestatus per-parser
Another step towards allowing multiple parsers to execute in parallel.
2019-05-12 14:00:44 -07:00
ridiculousfish
ee250aba82 Factor some environment setting into set_scoped_internal
Breaks up a monolith function.
2019-05-11 17:13:34 -07:00
ridiculousfish
8a8b2513b5 Eliminate the global jobs() function
All job lists are attached to a parser now.
2019-05-05 11:33:08 -07:00
Fabian Homborg
c2970f9618 Reformat all files
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.

If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
f66e010949 Turn a lot of common.h variables into getter functions
Improves thread safety.
2019-05-04 20:58:35 -07:00
ridiculousfish
3dfaa192da Put back process and job exit events
These were removed in f8b2e818ed under a
belief that they were unused. But they are documented and supported.
2019-05-01 16:32:14 -07:00
ridiculousfish
2c7dc98337 Revert "fcntl a little less"
This reverts commits:
e5362a4ae5.
dd9a26715d.

These commits were incorrect because they stomped other flags, such as
O_NONBLOCK.
2019-04-13 12:27:05 -07:00
ridiculousfish
b6555a0dc4 Add print-rusage-self to fish
This adds an option --print-rusage-self to the fish executable. When set,
this option prints some getrusage stats to the console in a human-readable
way. This will be used by upcoming benchmarking support.
2019-04-10 14:33:45 -07:00
Aaron Gyes
dd9a26715d fcntl a little less
Setting O_CLOEXEC on closed file descriptors and getting E_BADF
should be faster than actually checking if an fd is open first.
2019-04-08 11:23:00 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
ridiculousfish
1a4bb50cd5 Combine status and pipestatus into statuses_t
In most places where we set one, we want to set both. Make this less
error-prone by combining them into a single type statuses_t.
2019-02-26 20:07:37 -08:00
ridiculousfish
4b292c777d Clean up and clarify reader_exit() 2019-02-24 13:24:03 -08:00
ridiculousfish
780b53ba73 Convert event_type_t to an enum class 2019-02-23 13:17:28 -08:00
Aaron Gyes
634e97a85e Remove unnecessary _NSGetExecutablePath declaration
We do this in common.cpp now, and are including dyld.h anyhow.
2019-02-10 16:47:05 -08:00
ridiculousfish
d3fa58d621 Cleanup common.h
Remove a bunch of headers, simplify lots of code, migrate it into .cpp files.

Debug build time improves by ~3 seconds on my Mac.
2019-02-03 18:22:38 -08:00
ridiculousfish
22d05dc18b Try once more to fix the Travis build 2019-02-02 17:45:21 -08:00
ridiculousfish
6ba0d4c88a Revert io_bufferfill_t stack
This reverts commit 88dc484858 onwards.
2019-02-02 17:53:40 -08:00
Fabian Homborg
38b4d47560 Initialize empty_ios emptier
This placates the compiler.

The compiler is pleased.
2019-02-03 00:14:03 +01:00
ridiculousfish
3b1709180f Instantize env_get 2019-01-10 20:07:53 -08:00
ridiculousfish
c1dd284b3e Instantize env_set
Switch env_set to an instance method on environmnet_t.
2019-01-10 20:05:45 -08:00
ridiculousfish
895c2c4af0 Minor cleanup of parser interface 2019-01-10 20:29:10 -08:00
Stephen M. Coakley
d776a366fa Pass final Fish exit status to fish_exit event
For fish_exit to be a suitable replacement for --on-process-exit, we need to be able to provide scripts with access to the shell's final exit code.
2019-01-05 21:27:13 +01:00
Aaron Gyes
fe67cc4f6e Revert "Show how fish was executed, using argv[0] for program_name"
This reverts commit 1cb8b2a87b.

argv[0] has the full path in it for a user when he executes it
out of $PATH. This is really annoying in the title which uses $_.
2018-11-28 06:08:24 -08:00
Aaron Gyes
dd582abcc5 Revert "argv: don't reassign parameters"
This reverts commit ba455c81b4.
2018-11-28 06:07:58 -08:00
Aaron Gyes
ba455c81b4 argv: don't reassign parameters
OCLINT was ignoring this, but we can just not do the bad thing.
Declare argc and argv const. These are in the stack, they can
be modified, but we won't.

Fix a typo
2018-11-27 13:27:21 -08:00
Aaron Gyes
1cb8b2a87b Show how fish was executed, using argv[0] for program_name
... rather than hard code it to "fish". This affects
what is found in $_ and improves the errors:

For example, if fish was ran with ./fish, instead of
something like:

  fish: Expected 3 surprises, only got 2 surprises

we'll see:

 ./fish: Expected 3 surprises, only got 2 surprises

like most other shell utilities. It's just a tiny bit
of detail that can avoid confusion.
2018-11-27 11:57:09 -08:00
Aaron Gyes
9e7034c903 fish.cpp: Dirs relative to CMAKE_SOURCE_DIR, don't assume 'fish'
This was causing problems if "fish" wasn't in exec_path, like
if the binary had been renamed.

I also noticed that even with 'fish' not renamed, only paths.data
was made relative to my source tree. paths.sysconf, paths.doc, and
paths.bin were all relative to /usr/local.
2018-11-25 14:37:12 -08:00
Mahmoud Al-Qudsi
379f44fabe Add a --private option to launch fish in private mode
In private mode, access to previous history is blocked and new history
does not persist and is only available for the duration of the current
session.

This mode can be used when it is not desirable for commandline history
to leak into a session, e.g. via autocomplete or when it is desirable to
test the behavior of fish in the absence of history items without
permanently clearing the history.

I'm sure there are a lot more features that can be incorporated into
private mode, such as restricting access to certain user-specific
configuration files, etc.

This addresses a lot of the concerns raised in #1363 (which was later
changed to track mosh-specific problems). See also #102.
2018-10-24 19:33:48 +02:00