Commit Graph

2352 Commits

Author SHA1 Message Date
Per Bothner
4c0a119557 Disable cursor_down optimization, but fix to check c_oflag, but c_iflag.
The old commit #3f820f0 "Disable ONLCR mapping of NL output to CR-NL"
incorrectly used c_iflag instead of c_oflag, and I copied that error
in my patch.  Fixed that. However, there seems to be other problems
trying to use "\x1B[A", which I have not tried to debug, so comment that out.

(However, #3f820f0 seems to mostly work if we fix it to use c_oflag.)
2019-05-08 17:22:44 +02:00
Per Bothner
50db10a422 Alternate fix for cursor_down bound to "\n" and ONLCR set.
See GitHub issue #4505 "Terminal mode confusion"
and commit #3f820f0 "Disable ONLCR mapping of NL output to CR-NL".
2019-05-08 17:22:44 +02:00
Fabian Homborg
e20c08d04e argparse: Fix validation for short-only-flags
This read something like `o=!_validate_int`, and the flag modifier
reading kept the pointer after the `!`, so it created a long flag
called `_validate_int`, which meant it would not only error out form

```fish
argparse 'i=!_validate_int' 'o=!_validate_int' -- $argv
```

with "Long flag '_validate_int' already defined", but also set
$_flag_validate_int.

Fixes #5864.
2019-05-06 17:24:42 +02:00
Fabian Homborg
5bf21f2928 Penalize files ending in ~ in suggestions
Fixes #985.
2019-05-06 17:07:29 +02: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
15c50703ce fish_indent: Allow semicolons for and and or
As mentioned in #2900, something like

```fish
test -n "$var"; and set -l foo $var
```

is sufficiently idiomatic that it should be allowable.

Also fixes some additional weirdness with semicolons.
2019-05-05 12:51:49 +02: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
Fabian Homborg
90d64194c5 functions: Replace crummy forced tab with spaces
Still forced indentation, but at least the kind we recommend via
fish_indent.

Fixes #1472.
2019-05-05 12:07:38 +02:00
Fabian Homborg
3bea947bb5 fish_indent: Ignore consecutive semicolons
This removes semicolons at the end of the line and collapses
consecutive ones, while replacing meaningful semicolons with newlines.

I.e.

```fish
echo;
```

becomes

```fish
echo
```

but

```fish
echo; echo
```

becomes

```fish
echo
echo
```

Fixes #5859.
2019-05-05 12:07:38 +02:00
ridiculousfish
1e171140d5 Make the input_common lookahead main-thread only 2019-05-04 20:58:36 -07:00
ridiculousfish
9018a7d5ee Rename input_initialized to s_input_initialized and make it relaxed atomic 2019-05-04 20:58:35 -07:00
ridiculousfish
e10838d5d6 Make job_control_mode a static variable with accessors 2019-05-04 20:58:35 -07:00
ridiculousfish
9fb98baba6 Thread the parser into process_clean_after_marking 2019-05-04 20:58:35 -07:00
ridiculousfish
32d1b3d7cb Simplify looping in readb 2019-05-04 20:58:35 -07:00
ridiculousfish
edab366d3a Eliminate the "input callback queue"
This was a sort of side channel that was only used to propagate redraws
after universal variable changes. We can eliminate it and handle these
more directly.
2019-05-04 20:58:35 -07:00
ridiculousfish
56fd6f696b Improve thread safety in input.cpp 2019-05-04 20:58:35 -07:00
ridiculousfish
36998eee55 Make more miscellaneous globals thread safe 2019-05-04 20:58:35 -07:00
ridiculousfish
e2c66a8131 Make termsize thread safe 2019-05-04 20:58:35 -07:00
ridiculousfish
0de1611bf1 Migrate builtin_complete recursion_level into parser_t::libdata 2019-05-04 20:58:35 -07:00
ridiculousfish
2ce827343e Universal variables to become a latch variable 2019-05-04 20:58:35 -07:00
ridiculousfish
b0a695e9fa Migrate the global exec_count into the parser 2019-05-04 20:58:35 -07:00
ridiculousfish
fe68287cb0 Make miscellaneous variables thread-safe 2019-05-04 20:58:35 -07:00
ridiculousfish
6e143bf50f Eliminate history_collection_t
This was a pretty useless type.
2019-05-04 20:58:35 -07:00
ridiculousfish
3d63a68dd0 Make builtin_random thread safe 2019-05-04 20:58:35 -07: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
9dc1fd50c9 Introduce global_safety.h
This is a set of types that enable characterizing the proper way to access
global variables.
2019-05-04 20:53:32 -07:00
ridiculousfish
ec522e5978 Migrate s_main_thread_request_queue to owning_lock 2019-05-04 20:42:56 -07:00
ridiculousfish
1e57424011 Thread a parser into function_exists
Since this may autoload, it needs a parser with which to autoload.
2019-05-04 20:20:52 -07:00
ridiculousfish
bffacd2fbf Thread a parser into expansion
Expansion may perform command substitution, which needs to know the parser
to use.
2019-05-04 19:30:00 -07:00
ridiculousfish
4ce485525e Correct duplicate completion detection
Stop assuming that completions with the same hash are equal.
2019-05-04 18:35:22 -07:00
ridiculousfish
923a7ca0f0 Thread the parser into complete()
Eliminates uses of principal_parser
2019-05-04 18:17:18 -07:00
ridiculousfish
63bdc949ab Make completion request flags an enum_set 2019-05-04 17:55:57 -07:00
ridiculousfish
acd33cbabb Remove an unnecessary fetch of the principal parser 2019-05-04 16:56:38 -07:00
ridiculousfish
fbd4ff027a Initialize a field that was previously uninitialized
Caught by UBSan
2019-05-04 16:47:27 -07:00
ridiculousfish
c0c7b0f86f Make tsan detection gcc compatible 2019-05-04 16:13:55 -07:00
ridiculousfish
ec45f31ad1 Make debug_level an atomic
Fixes a tsan warning
2019-05-04 15:28:44 -07:00
ridiculousfish
0dd9f64bd9 Make topic monitor compatible with tsan
tsan does funny things to signals, preventing signals from being delivered
in a blocking read. Switch the topic monitor to non-blocking reads under
tsan.
2019-05-04 13:06:06 -07:00
Fabian Homborg
e91eb85949 argparse: Fix -- regression
I was a tad overzealous there with not appending the remaining
arguments.

Weird that we didn't test it, though.

Fixes #5857.
2019-05-03 16:20:40 +02:00
ridiculousfish
649d3ac101 Simplify reporting of invalid config paths
Do this at a well defined point, instead of randomly the first time they're
queried.
2019-05-01 17:51:51 -07:00
ridiculousfish
72e43a514b Correct the warning for invalid directories
This was inadvertently broken.
2019-05-01 17:47:50 -07:00
ridiculousfish
55e3270ac4 Remove erase_list from process_clean_after_marking
We don't need to maintain an erase_list in this function any more.
Simply remove jobs that are completed.
2019-05-01 16:32:14 -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
43d668bdc8 Continue to refactor internal loop of process_clean_after_marking
Factor our logic around when to print a message.
2019-05-01 16:32:14 -07:00
ridiculousfish
b5d3fadf44 Factor out the individual process handling in process_clean_after_marking
Helps break up this monolith.
2019-05-01 16:32:14 -07:00
ridiculousfish
b8170ec1ce Clarify return value of job_reap and process_clean_after_marking 2019-05-01 16:32:14 -07:00
ridiculousfish
9700800ecf Factor disowned job removal into its own function
This helps break up process_clean_after_marking.
2019-05-01 16:31:21 -07:00
ridiculousfish
c05e72749a Rename PENDING_REMOVAL to DISOWN_REQUESTED
A commend implied that PENDING_REMOVAL was broader than it was. In practice
only disown() sets this flag. Rename the flag for clarity.
2019-05-01 15:37:53 -07:00
David Adam
665ae3787a Switch to runtime check for /proc/self/stat
Removes a compile-time check that may have affected cross-compilation.

Work on #1067.
2019-04-30 16:23:28 +08:00
Fabian Homborg
43929ced90 src/builtin_argparse: Work around wgetopt crash
If on the last argument, and it was an unrecognized option, we can't
call `wgetopt_long()` again, or it'll crash.
2019-04-29 16:55:55 +02:00
Fabian Homborg
8c9359fdd4 src/builtin_argparse: Add --ignore-unknown flag
This keeps all unknown options in $argv, so

```fish
argparse -i a/alpha -- -a banana -o val -w
```

results in $_flag_a set to banana, and $argv set to `-o val -w`.

This allows users to use multiple argparse passes, or to simply avoid
specifying all options e.g. in completions - `systemctl` has 46 of
them, most not having any effect on the completions.

Fixes #5367.
2019-04-29 15:57:56 +02:00
ridiculousfish
d8ac051f89 Move selection_direction_t to pager.h and make it a class enum 2019-04-28 14:06:03 -07:00
ridiculousfish
2507162f80 Revert "Add a test for autoload_t"
This reverts commit 51c62d6cc6.

Back out the test while I attempt to fix it
2019-04-27 20:14:06 -07:00
ridiculousfish
51c62d6cc6 Add a test for autoload_t 2019-04-27 16:16:48 -07:00
ridiculousfish
4ff50eba41 Remove autoload_t, rename autoloader_t to autoload_t
Now that there are no more clients of autoload_t, delete it and
rename autoloader_t to autoload_t. Also clean up the headers.
2019-04-27 15:47:08 -07:00
ridiculousfish
68a28106b2 Reimplement completion autoloading via autoloader_t
This switches the completion autoloading machinery to autoloader_t.
2019-04-27 15:37:24 -07:00
ridiculousfish
960266fe24 Reimplement the function store and autoloading
This cleans up how functions are stored and autoloaded. It eliminates the
recursive lock. Instead there is a single normal owning_lock that protects
the entirety of the function data. Autoloading is re-implemented via the
new autoloader_t.
2019-04-27 15:30:11 -07:00
ridiculousfish
3950dab9ff Add autoloader_t
autoloader_t will be the reimplementation of autoloading. Crucically it no
longer manages any locking or loading itself; instead all locking and loading
is performed by clients. This makes it easier to test and helps limit its
responsibilities.
2019-04-27 15:26:18 -07:00
ridiculousfish
b7ad6b5bdc Add autoload_file_cache_t
This will provide the "backing store" for autoloading.
2019-04-27 15:09:24 -07:00
ridiculousfish
6ec7c50ace Stop removing functions and completions in autoload
autoloading has a "feature" where functions are removed in an LRU-fashion.
But there's hardly any benefit in removing autoloaded functions. Just stop
doing it.
2019-04-27 14:49:05 -07:00
ridiculousfish
7b44b5ef15 Titlecase LRU template parameters 2019-04-27 12:07:16 -07:00
ridiculousfish
f297543ca1 Make owning_lock's template parameter titlecase instead of uppercase 2019-04-27 12:04:36 -07:00
Fabian Homborg
af0e08e9f1 argparse: Use the current function name by default
This makes the `--name` option usually unnecessary.

See #5835.
2019-04-27 15:55:49 +02:00
ridiculousfish
9bc5d60eaf Clean up enum_set.h header
Include a missing array header, and switch to idiomatic include guards.
2019-04-26 16:08:19 -07:00
Fabian Homborg
009ecfd7e6 src/tokenizer: Add ":@" to the list of non-path-component chars
This makes kill-path-component stop there.

Fixes #5841.
2019-04-26 19:16:21 +02:00
David Gowers
38cadc9d4f Variables as commands are in fact supported, eval docs should not claim otherwise. (#5819)
Provide an example that somewhat justifies eval's existence in light of this change.

Also correct similar misinformation found in a comment.
2019-04-26 15:30:13 +02:00
Fabian Homborg
22ce8c23c6 builtin_complete: Allow complete -C something
This is a long-standing issue with how `complete --do-complete` does
its argument parsing: It takes an optional argument, so it has to be
attached to the token like `complete --do-complete=foo` or (worse)
`complete -Cfoo`.

But since `complete` doesn't take any bare arguments otherwise (it
would error with "too many arguments" if you did `complete -C foo`) we
can just take one free argument as the argument to `--do-complete`.

It's more of a command than an option anyway, since it entirely
changes what the `complete` call _does_.
2019-04-26 15:02:29 +02:00
ridiculousfish
cd86c0ee88 Remove the COMPLETE_SEP define
It was unused.
2019-04-25 14:23:37 -07:00
ridiculousfish
96bc8a14ca Promote completion_mode_t to a real type
Eliminate big #defines like NO_COMMON.
2019-04-25 14:21:06 -07:00
ridiculousfish
d962668aa0 Remove PATH and COMMAND defines
Also clean up a bit of builtin_complete
2019-04-25 13:26:43 -07:00
ridiculousfish
496529b20a Remove EXPAND prefix from expand_flags and lowercase them 2019-04-25 11:34:49 -07:00
ridiculousfish
d8ab6290e8 Switch expand_flags_t to enum_set 2019-04-25 11:23:03 -07:00
ridiculousfish
dcaac58f45 Rename expand_error_t to expand_result_t and make it class enum
Also lowercase it all.
2019-04-25 10:47:28 -07:00
ridiculousfish
b54c44f2f6 Migrate expansion stages to a new type expander_t
This avoids having to pass around so many parameters during expansion.
2019-04-25 10:47:28 -07:00
Aaron Gyes
f309ae05b6 is_visual_escape_seq: whittle down the escape sequences attempted
Some of these we do not need to worry about actually being used
in a prompt.
2019-04-20 17:03:27 -07:00
ridiculousfish
fe75a3a650 Migrate autoload file checks to file_id_t 2019-04-19 18:47:07 -07:00
ridiculousfish
6dd2766a15 Remove file_access_attempt_t::stale
It was unused.
2019-04-19 18:26:29 -07:00
Per Bothner
2edfab685a Some comment fixes and renaming of is_iterm2_escape_seq. (#5827)
* Some comment fixes and renaming of is_iterm2_escape_seq.

The comment for is_iterm2_escape_seq incorrectly says "CSI followed by ]".
This is wrong, because CSI is ESC followed by [ (or the seldom-used 0x9b).
The procedure  actually matches Operating System Command (OSC) escape codes.
Since there is nothing iterm2-specific about OSC, is_osc_escape_seq
would be a better name.

Also s_desired_append_char documents a non-existent parameter.

* Update broken iterm2 url in comment.
2019-04-19 09:29:35 -07:00
Mahmoud Al-Qudsi
8ca2641857 Revert overzealous !parent_job is_visible() condition
This was added in 04a96f6 but not strictly required to fix #5803
(verified), with the intention of hiding invisible background jobs
(created by invoking a function within a pipeline) from the user, but
that also broke intentionally created jobs from displaying as well.

I'm thinking it can't be done without keeping track of caller context vs
job context.

Closes #5824.
2019-04-17 22:47:41 -05:00
ridiculousfish
a173c079d5 expand_abbreviation to always accept an environment_t
Now that snapshotting is fixed, we don't need to get the principal
environment stack any more.
2019-04-16 22:45:58 -07:00
ridiculousfish
2e119813e1 get_abbreviations to accept an environment_t
Now that we don't have dorky snapshotting, thread an dnvironment_t through
get_abbreviations. Removes a usage of env_stack_t::principal().
2019-04-16 22:27:01 -07:00
Aaron Gyes
7e514d2aa5 expand_abbreviation(): escape when looking up abbreviation vars
This was doing exactly the opposite: unescaping and not hitting
the encoded _fish_abbr_X variables when looking up.

Fixes #5573
2019-04-16 21:33:09 -07:00
ridiculousfish
6b52b0994c Attempt to fix the travis build 2019-04-14 17:43:02 -07:00
ridiculousfish
2fac0f0b39 Correctly lock around umask
umask can only be set, never just queried. Thus we need to lock around
calls to it.

Also guess the value; if we guess right we don't need to reset it.
2019-04-14 16:08:29 -07:00
ridiculousfish
020d4a2848 Adopt env_scoped_t::snapshot() and remove env_var_snapshot_t
Remove the env_var_snapshot_t class and switch everything to the new snapshot
function of env_scoped_t.

Fixes #5658. Fixes #5571.
2019-04-14 15:50:38 -07:00
ridiculousfish
64584a6624 Add a snapshot function to env_scoped_t
Allow creating lightweight read-only copies of a scoped environment.
2019-04-14 15:50:30 -07:00
ridiculousfish
0ca3ae7c7e Rejigger var_stack_t's ctors
Prepare var_stack_t to support snapshotting.
2019-04-14 15:50:24 -07:00
ridiculousfish
69655ef5c1 Reorganize env.cpp
Group functions together more logically
2019-04-14 15:50:19 -07:00
ridiculousfish
1d464da698 Introduce env_scoped_t
env_scoped_t lives between environment_t and env_stack_t.
It represents the read-only logic of env_stack_t and will be used to back
the new environment snapshot implementation.
2019-04-14 15:50:12 -07:00
ridiculousfish
46fd47a0da Organize some code slightly better in env.h 2019-04-14 15:50:06 -07:00
Mahmoud Al-Qudsi
05f52924c1 Fix bad tests
These tests used raw, unescaped parentheses to perform `test` logical
grouping, but the test failures weren't caught because the parser
evaluation errors were not being propagated (fixed in bdbd173e).
2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
b2a1da602f Fix error propagation in parser_t::eval
It was unconditionally returning `parse_execution_success`. This was
causing certain parser errors to incorrectly return after evaluation
with `$status` equal to `0`, as reported after `eval`, `source`, or
sub-`fish` execution.
2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
8e4010b263 Make eval override previous status
Closes #5692 (again).
2019-04-13 17:28:10 -05:00
Mahmoud Al-Qudsi
4530a41004 Fix return code after execution of empty function 2019-04-13 17:21:13 -05:00
ridiculousfish
cc9386fca9 Clean up some headers in env and env_dispatch.cpp 2019-04-13 14:39:20 -07:00
ridiculousfish
2537fe0f9e Put back a missing lock in env_stack_t::set_internal
Setting a variable could race with getting it.

The lockin^g here needs a serious overhaul.
2019-04-13 12:40:58 -07:00
ridiculousfish
2f1e572756 Minor cleanup of env_node_t
Mark some fields const that don't need to change. Trying to get ready to
improve locking here.
2019-04-13 12:40:58 -07:00
ridiculousfish
372291ad02 Collapse a weirdly structured clause in env.cpp 2019-04-13 12:40:57 -07:00
ridiculousfish
a597b0e6e1 Remove get_proc_had_barrier
Prior to this change, fish used a global flag to decide if we should check
for changes to universal variables. This flag was then checked at arbitrary
locations, potentially triggering variable updates and event handlers for
those updates; this was very hard to reason about.

Switch to triggering a universal variable update at a fixed location,
after running an external command.  The common case is that the variable
file has not changed, which we can identify with just a stat() call, so
this is pretty cheap.
2019-04-13 12:40:57 -07:00
ridiculousfish
341799194e Factor out fetching electric variables into a separate function
This factors env_stack_t::get() a little better
2019-04-13 12:40:57 -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
13c5f93d63 Revert "Optimize function calls by reducing inherit vars heap allocations and copies"
This reverts commit cdce8511a1.

This change was unsafe. The prior version (now restored) took the lock and
then copied the data. By returning a reference, the caller holds a
reference to data outside of the lock.

This function isn't worth optimizing. Hardly any functions use this
facility, and for those that do, they typically just capture one or two
variables.
2019-04-13 12:03:02 -07:00
Mahmoud Al-Qudsi
cdce8511a1 Optimize function calls by reducing inherit vars heap allocations and copies
* Convert `function_get_inherit_vars()` to return a reference to the
  (possibly) existing map, rather than a copy;
* Preallocate and reuse a static (read-only) map for the (very) common
  case of no inherited vars;
* Pass references to the inherit vars map around thereafter, never
  triggering the map copy (or even move) constructor.

NB: If it turns out the reference is unsafe, we can switch the inherit vars
to be a shared_ptr and return that instead.
2019-04-13 11:26:10 -05:00
David Adam
56125f73e4 env: trigger locale updates if LOCPATH changes
Closes #5815.
2019-04-13 21:58:54 +08:00
ridiculousfish
47b9907113 Remove an unused variable 2019-04-12 23:03:28 -07:00
ridiculousfish
4e1fdaf5a7 Use move semantics in builtin_eval
Saves some allocations
2019-04-12 23:02:45 -07:00
ridiculousfish
c95e1b83c7 Minor cleanup of eval builtin
Fix some copy and paste errors, remove some dead variables and code,
make the return a bit more structured.
2019-04-12 22:42:27 -07:00
Fabian Homborg
a8030c020b src/fish_indent.cpp: Fix return-value warning 2019-04-12 15:38:38 +02:00
Mahmoud Al-Qudsi
e0e0fe9dd3 Re-implement eval as a regular builtin
I did not realize builtins could safely call into the parser and inject
jobs during execution. This is much cleaner than hacking around the
required shape of a plain_statement.
2019-04-12 07:04:15 -05:00
Aaron Gyes
1834e962d2 Correct carat position for unexpected } in brace expansion
before:

$ echo {}}-
fish: Unexpected '}' for unopened brace expansion

$ ./fish -c 'echo {}}}}'
fish: Unexpected '}' for unopened brace expansion
echo {}}}}
^

now:
$ echo {}}}}}}1-
fish: Unexpected '}' for unopened brace expansion
echo {}}}}}}
       ^
2019-04-11 17:18:53 -07:00
Aaron Gyes
75db3b4ff4 fix incorrectly aligned carat in command expansion errors and more
- fix the carat position expanding e.g. `command $,`
- improve the error reporting for not-allowed command subtitutions
  by figuring out where the expansion failed instead of using
  SOURCE_LOCATION_UNKNOWN
- allow nullptr for parse_util_licate_brackets_range() out_string
  argument if we don't need it to do any work.

Fixes #5812
2019-04-11 14:44:46 -07:00
Mahmoud Al-Qudsi
4539a9db15 Drop unused include in src/exec.cpp
It was added in 2544c622841fd8b7317109f12fe4eb55c5ea1d0a,
and caught by @faho.
2019-04-11 13:01:29 -05:00
Mahmoud Al-Qudsi
4d54147e7e Merge branch 'eval_parser'
Implements `eval` in cpp rather than as a fish function.
2019-04-11 10:41:33 -05:00
Mahmoud Al-Qudsi
2fe2169065 Make eval a decorator
`eval` has always been implemented as a function, which was always a bit
of a hack that caused some issues such as triggering the creation of a
new scope. This turns `eval` into a decorator.

The scoping issues with eval prevented it from being usable to actually
implement other shell components in fish script, such as the problems
described in #4442, which should now no longer be the case.

Closes #4443.
2019-04-11 10:36:49 -05:00
ridiculousfish
f7817a2586 Remove env_node_t::contains_any_of
Dead code...
2019-04-10 23:18:30 -07:00
Mahmoud Al-Qudsi
0bda853dc7 Add detection of eval to the parser
While `eval` is still a function, this paves the way for changing that
in the future, and lets the proc/exec functions detect when an eval is
used to allow/disallow certain behaviors and optimizations.
2019-04-10 21:19:57 -05: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
Mahmoud Al-Qudsi
04a96f6c6e Change when PENDING_REMOVAL jobs are removed
Followup to 394623b.

Doing it in the parser meant only top-level jobs would be reaped after
being `disown`ed, as subjobs aren't directly handled by the parser.

This is also much cleaner, as now job removal is centralized in
`process_clean_after_marking()`.

Closes #5803.
2019-04-10 11:00:48 -05:00
Mahmoud Al-Qudsi
394623bf08 Prevent disown from directly removing jobs
This prevents the `disown` builtin from directly removing jobs out of
the jobs list to prevent sanity issues, as `disown` may be called within
the context of a subjob (e.g. in a function or block) in which case the
parent job might not yet be done with the reference to the child job.

Instead, a flag is set and the parser removes the job from the list only
after the entire execution chain has completed.

Closes #5720.
2019-04-09 23:29:58 -05:00
Mahmoud Al-Qudsi
f1b261388a Fix build error on old (buggy?) versions of libstdc++
Closes #5801.
2019-04-09 22:43:32 -05:00
Mahmoud Al-Qudsi
ab1519acef Fix high CPU usage in subsequent select(2) calls
The timeout was being reset to zero, so `select` was being called in a
very tight loop.

Closes #5761.
2019-04-09 21:10:30 -05:00
David Adam
c6c0c9bfdf use standard warning for invalid variable in for loop
Work on #5800.
2019-04-09 20:10:57 +08:00
ridiculousfish
e44cb235a7 Add pygments CSV output to fish_indent
This will allow pygments to highlight fish code using fish_indent.
2019-04-08 19:09:41 -07:00
ridiculousfish
3e14f96d40 Eliminate string_set_contains 2019-04-08 16:22:04 -07:00
ridiculousfish
1caf20f7c3 Migrate the read limit into env_dispatch 2019-04-08 16:22:04 -07:00
ridiculousfish
fa0a6ae096 Move locale and curses init from env to env_dispatch 2019-04-08 16:22:04 -07:00
ridiculousfish
11651dec7a Clean up env_stack_t::pop
Use the new dispatch mechanism to reduce duplication
2019-04-08 16:22:04 -07:00
ridiculousfish
a4fe3c87ae Switch certain environment callbacks from named to anonymous 2019-04-08 16:22:04 -07:00
ridiculousfish
987e41de12 Remove the op from env_dispatch
Environment dispatch passes strings like "ERASE" and "SET" but nobody
ever looks at those. Just get rid of them.
2019-04-08 16:22:04 -07:00
ridiculousfish
dc729653be Migrate pop complexity from vars_stack_t to env_stack_t
When popping a scope from the environment stack, we currently do a lot of
nonsense like looking for changed curses variables. We want to centralize
this in env_stack_t so that it can be migrated to the env_dispatch logic.
Move this logic up one level in preparation for doing that.
2019-04-08 16:22:04 -07:00
ridiculousfish
59fb5b1849 var_stack_t::pop() to return the popped node 2019-04-08 16:22:04 -07:00
ridiculousfish
0c5809a088 Minor cleanup of env_node_t 2019-04-08 16:22:04 -07:00
ridiculousfish
ab67354192 Migrate fish_use_posix_spawn into env_dispatch 2019-04-08 16:22:04 -07:00
ridiculousfish
e7de9cc371 Migrate some env initialization into env_dispatch 2019-04-08 16:22:04 -07:00
ridiculousfish
b67174b4a3 Clean up env_dispatch_table 2019-04-08 16:22:04 -07:00
ridiculousfish
b7fceddfc8 Refactor some environment code into env_dispatch.cpp
This new file is supposed to encapsulate all of the logic around
reacting to variable changes, as opposed to the environment core.
This is to help break up the env.cpp monolith.
2019-04-08 16:22:04 -07:00
Aaron Gyes
e5362a4ae5 wutil.cpp: fixup: don't involve the uninitialized parameter 2019-04-08 16:02:00 -07:00
Aaron Gyes
8eb05f8731 parse_execution.cpp: validate 'for' variable name
Fixes #5800
(that's a nice round number)
2019-04-08 11:23:00 -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
ridiculousfish
bf40f84b06 Remove an unused variable 2019-04-07 15:07:36 -07:00
ridiculousfish
f5bb8639d6 More aggressively inherit pgrps from parent jobs
Prior to this fix, a job would only inherit a pgrp from its parent if the
first command were external. There seems to be no reason for this
restriction and this causes tcsetgrp() churn, potentially cuasing SIGTTIN.
Switch to unconditionally inheriting a pgrp from parents.

This should fix most of #5765, the only remaining question is
tcsetpgrp from builtins.
2019-04-07 13:35:00 -07:00
ridiculousfish
39a9740997 Be less aggressive about reclaiming the foreground pgrp
Prior to this fix, in every call to job_continue, fish would reclaim the
foreground pgrp. This would cause other jobs in the pipeline (which may
have another pgrp) to receive SIGTTIN / SIGTTOU.

Only reclaim the foreground pgrp if it was held at the point of job_continue.

This partially addresses #5765
2019-04-07 09:20:32 -07:00
ridiculousfish
23d88e0e03 Add fish_test_helper executable
In tests we would like to arrange for an executable to invoke certain
system calls, e.g. to claim or relinquish control of the terminal. This is
annoying to do portably via e.g. perl. fish_test_helper is a little
program where we can add custom commands to make it act in certain ways.
2019-04-07 09:20:19 -07:00
Aaron Gyes
4e555aebec Remove is_whitespace and whitespace character string declarations
I don't doubt such functions and character arrays could be useful,
to keep things consistent, but they are not actually being used.
2019-04-06 02:07:56 -07:00
Fabian Homborg
2a3677b386 Stop setting term-modes early
This set the term modes to the shell-modes, including disabling
ICRNL (translating \cm to \cj) and echo.

The rationale given was that `reader_interactive_init()` would only be
called >= 250ms later, which I _highly_ doubt considering fish's total
startup time is 8ms for me.

The main idea was that this would stop programs like tmuxinator that
send shortcuts early from failing _iff_ the shortcut was \cj, which
also seems quite unusual.

This works both with `rm -i` and `read` in config.fish, because `read`
explicitly calls `reader_push`, which then initializes the shell modes.

The real fix would involve reordering our init so we set up the
modesetting first, but that's quite involved and the remaining issue
should barely happen, while it's fairly common to have issues with a
prompt in config.fish, and the workaround for the former is simpler, so let's leave it for now.

Partially reverts #2578.

Fixes #2980.
2019-04-05 12:55:13 +02:00
Aaron Gyes
be80a56ad4 expand.cpp: use wcspbrk for is_quotable 2019-04-04 17:32:39 -07:00
Aaron Gyes
b4ddd797e3 remove unused wcstring 2019-04-04 14:24:36 -07:00
Aaron Gyes
b064eaa571 use std::move in a couple spots where things were unsed after copy 2019-04-04 14:16:34 -07:00
Aaron Gyes
09e8f0fd7c rearrange structure fields
Putting larger members before smaller ones will reduce structure
sizes. bools are 1 byte. on 64bit systems I think they reduced:

wgetopt.h:46: 64 to 56 bytes
builtin_history.cpp:30: 48 to 32 bytes
builtin_status.cpp:91: 32 to 24 bytes
tinyexpr.cpp:69: 40 to 32 bytes
2019-04-04 13:47:10 -07:00
Mahmoud Al-Qudsi
bc66921ac9 Optimize keyword detection
The data stored in these containers is small enough that it is worth
creating distinct sets for each lookup.

In a microbenchmark of these changes, the single-lookup version of the
function with lookups gated on the length of input (bypassed entirely if
the input is longer than the longest key in the container) provided a
1.5x-3.5x speedup over the previous implementation.

Additionally, as the collections are static and their contents are never
modified after startup, it makes no sense to continously calculate the
location of and allocate an iterator for the `!= foo.end()` comparison;
the end iterator is now statically cached.

I'm not expecting massive speed gains out of this change, but the parser
does perform enough of these to make it worth optimizing in this way.
2019-04-03 20:53:29 -05:00
ridiculousfish
dd007c29f4 Revert "parser: try to avoid some strings being copied"
This reverts commit 7a74198aa3.

Believe it or not this commit actually increased copying. When accepting
a value you know you're going to take ownership of, just accept it by
value; then temporaries can invoke the move ctor and blah blah blah.

We really need a lightweight refcounted pass-by-value string to make this
less error prone.
2019-04-01 20:22:02 -07:00
Fabian Homborg
99dd6d7394 Let repaint-mode act like a repaint if no fish_mode_prompt exists
Otherwise I'm pretty sure we'd get complaints from people who use a
mode-indicator elsewhere in their prompts.
2019-04-01 16:04:14 +02:00
Fabian Homborg
8ff866b26b Add repaint-mode bind function
If we switch the bind mode, we add a "force-repaint" there just to
redraw the mode indicator.

That's quite wasteful and annoying, considering that sometimes the prompt can take
half a second.

So we add a "repaint-mode" function that just reexecutes the
mode-prompt and uses the cached values for the others.

Fixes #5783.
2019-04-01 15:59:39 +02:00
Fabian Homborg
da1b32f0ad
Remove option to use system wcwidth (#5777)
As it turns out it didn't work much better, and it fell behind in
support when it comes to things that wcwidth traditionally can't
express like variation selectors and hangul combining characters, but
also simply $fish_*_width.

I've had to tell a few people now to rebuild with widecharwidth after
sending them on a fool's errand to set X variable.

So keeping this option is doing our users a disservice.
2019-04-01 15:59:33 +02:00
Fabian Homborg
0d72912641
Expand abbr explicitly (#5762)
* Add "expand-abbr" bind function

This can be used to explictly allow expanding abbreviations.

* Make expanding abbr explicit

NOTE: This accepts them for space only, we currently also do it for \n
and \r.

* Remove now dead code

We no longer trigger an abbr implicitly, so we can remove the code
that does it.

* Fix comment

[ci skip]
2019-04-01 15:59:15 +02:00
Mahmoud Al-Qudsi
eb2d829bc5 Use explicit lock.exchange()
There's really no point in using std::atomic if we're not going to
actually guarantee the entire read & write process is atomic.
2019-03-31 18:17:33 -05:00
Mahmoud Al-Qudsi
b5b9406711 Use explicit atomic/CAS to prevent race conditions
They are probably equivalent on x86/64 being single-byte reads/writes,
but it never hurts to be safe.
2019-03-31 18:09:59 -05:00
Mahmoud Al-Qudsi
3c537bfa65 Optimize get_deferred_process() traversal 2019-03-31 13:20:49 -05:00
ridiculousfish
0aa0dceeb3 End coalescing repaints on check-exits
Hopeful fix for #5766
2019-03-29 20:56:23 -07:00
ridiculousfish
0b11b8cffb Revert "Optimize identification of deferred process"
This reverts commit 4aea4c09b3.

Said commit broke many tests
2019-03-28 20:22:58 -07:00
Mahmoud Al-Qudsi
4aea4c09b3 Optimize identification of deferred process 2019-03-28 22:12:50 -05:00
Mahmoud Al-Qudsi
f8b2e818ed Remove legacy generic process/job exit events 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
7f5e58ae69 Only send JOB_EXIT after the job has been actually erased 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
06adb1dc38 Store jobs to erase in separate list 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
36f3a6d7e0 Use const auto for all jobs 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
d4d5c03a03 Clean up invalid job id detection in fg builtin 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
1f59976c2c Further clean up job list manipulation 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
6fab783647 Convert job_list to a dequeue again
Now that we have cleaned up access to the job list and removed
transparent invalidation of iterators, it is safe to convert it to a
dequeue.
2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
f8e0e0ef82 Remove abstractions around job list
Directly access the job list without the intermediate job_iterator_t,
and remove functions that are ripe for abuse by modifying a local
enumeration of the same list instead of operating on the iterators
directly (e.g. proc.cpp iterates jobs, and mid-iteration calls
parser::job_remove(j) with the job (and not the iterator to the job),
causing an invisible invalidation of the pre-existing local iterators.
2019-03-28 18:55:36 -05:00
Fabian Homborg
42acbaa5af Remouve ouveroused U
Webster was right, gosh dang it!

[ci skip]
2019-03-28 12:31:52 +01:00
ridiculousfish
5441ebc91f Remove some dead code 2019-03-28 00:38:12 -07:00
Fabian Homborg
785945c861 src/builtin_test: Print backtrace on error
`test` is a common source of problems, and with the current system
they can be quite hard to find.

So we print a backtrace with line numbers and all.
2019-03-28 08:35:32 +01:00
Fabian Homborg
d8ec4685ff src/builtin_test: Remove weird leading tab from error message
This is a remainder from when we used to speak of "eval errors".
2019-03-28 08:35:32 +01:00
Fabian Homborg
7fa454666d Only append newline if stacktrace isn't empty
This printed weird things like

```fish
$ functions -x
functions: Unknown option '-x'

(Type 'help functions' for related documentation)
```

Instead, let's make it

```fish
$ functions -x
functions: Unknown option '-x'
(Type 'help functions' for related documentation)
```
2019-03-26 19:32:18 +01:00
Fabian Homborg
88d2d54276 Stop printing help summary on error
This now displays

- the error message

- a (significantly shorter) backtrace

- A call to open `help $cmd` if necessary

See #5434.
Fixes #3404.
2019-03-26 19:24:48 +01:00
Fabian Homborg
88a935d8d1 Escape arguments in stacktraces
See #5434.
2019-03-26 17:45:25 +01:00
Fabian Homborg
7095de628c Remove "called on standard input" message
This was printed basically everywhere.

The user knows what they executed on standard input.

A good example:

```fish
set c (subme 513)
```

used to print

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme'
	called on standard input
	with parameter list '513'
in command substitution
	called on standard input
```

and now it is

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme' with arguments '513'
in command substitution
```

See #5434.
2019-03-26 17:38:41 +01:00
Fabian Homborg
975023faf2 Print arguments on the same line as the function
Now:

```
cd: Unknown option '-r'
~/dev/fish-shell/share/functions/cd.fish (line 40):
    builtin cd $argv
    ^
in function 'cd' with arguments '-r'
in function 'f'
in function 'd'
in function 'b' with arguments '-1q --wurst'
in function 'a'
	called on standard input
```

See #5434.
2019-03-26 17:37:16 +01:00
Fabian Homborg
e723f02aa7 Remove empty line also for event handlers 2019-03-26 17:18:25 +01:00
Fabian Homborg
39a601927f Remove useless empty lines from stack traces
This printed things like

```
in function 'f'
        called on standard input

in function 'd'
        called on standard input

in function 'b'
        called on standard input

in function 'a'
        called on standard input

```

As a first step, it removes the empty lines so it's now

```
in function 'f'
        called on standard input
in function 'd'
        called on standard input
in function 'b'
        called on standard input
in function 'a'
        called on standard input
```

See #5434.
2019-03-26 16:47:42 +01:00
Fabian Homborg
b86200938f Always use "." for cd
Nobody doesn't want to use $PWD to cd, so if $CDPATH does not include
it that was a mistake.

Bash also appends "." here.

Fixes #4484.
2019-03-26 10:11:36 +01:00
ridiculousfish
eeec6cc2fc Remove a single use of env_stack_t::principal 2019-03-25 02:27:02 -07:00
ridiculousfish
989f992a75 Rearrange and inline some env code 2019-03-25 00:49:52 -07:00
ridiculousfish
ea3a368c50 Make env_var_t store its values via shared_ptr
This switches env_var_t to be an immutable value type, and stores its
contents via a shared_ptr. This eliminates string copying when fetching
env_var_t values.
2019-03-25 00:41:04 -07:00
ridiculousfish
5eade35257 Stop buffering deferred function processes
If a function process is deferred, allow it to be unbuffered.
This permits certain simple cases where functions are piped to external
commands to execute without buffering.

This is a somewhat-hacky stopgap measure that can't really be extended
to more general concurrent processes. However it is overall an improvement
in user experience that might help flush out some bugs too.
2019-03-24 21:23:26 -07:00
ridiculousfish
3bbee06248 Introduce the notion of a deferred process
In a job, a deferred process is the last fish internal process which pipes
to an external command. Execute the deferred process last; this will allow
for streaming its output.
2019-03-24 14:27:23 -07:00
ridiculousfish
165c82e68a Promote process_type_t to an enum class 2019-03-24 12:29:25 -07:00
ridiculousfish
96b8ac7013 Promote job_control_t to an enum class 2019-03-24 12:12:44 -07:00
ridiculousfish
71f26a6813 Remove INPUT_COMMON_BASE
We no longer store readline commands as characters, so there's no need to
reserve character space for them.
2019-03-23 23:31:37 -07:00
ridiculousfish
e7d7eff0ee Rename all readline commands to lowercase and remove R_ prefix 2019-03-23 23:31:35 -07:00
ridiculousfish
9187458d51 Continued refactoring of reader_data_t::readline 2019-03-23 23:31:34 -07:00
ridiculousfish
6ba94fd81b Factor readline command handling into new function handle_readline_command() 2019-03-23 23:31:33 -07:00
ridiculousfish
42f4d2bd86 Factor out the "read coalescing" part of reader_data_t::readline 2019-03-23 23:31:31 -07:00
ridiculousfish
7ae7865071 Factor reader_data_t::readline state into a new struct
Will help break up this monster.
2019-03-23 23:31:29 -07:00
ridiculousfish
6aba28ad3d Add missing cases to readline loop
Handle all readline commands in our switch.
2019-03-23 23:31:27 -07:00
ridiculousfish
2c56e27d37 Switch readline commands to readline_cmd_t enum class 2019-03-23 23:31:25 -07:00
ridiculousfish
0841072462 Minor cleanup of kill ring 2019-03-23 23:31:24 -07:00
ridiculousfish
b68d3b84de Switch input_function_get_code() to return maybe_t 2019-03-23 23:31:22 -07:00
ridiculousfish
c2be5e8986 Introduce char_event_type_t::readline
Baby steps towards eliminating readline actions as characters.
2019-03-23 23:31:18 -07:00
ridiculousfish
14663089c8 Finish removing R_NULL 2019-03-23 23:31:09 -07:00
ridiculousfish
28b79a2c88 Some further steps towards removing R_NULL
Introduce char_event_type_t::check_exit to represent "check for exit"
instead of R_NULL.
2019-03-23 23:31:01 -07:00