Commit Graph

3988 Commits

Author SHA1 Message Date
Johannes Altmanninger
e40eba3585 Treat text following quoted command substitution as quoted
Commit ec3d3a481 (Support "$(cmd)" command substitution without line
splitting, 2021-07-02) started treating an input string like
"a$()b" as if it were "a"$()"b". Yet, we do not actually insert the
virtual quotes. Instead we just adapted the definition of when quotes
are closed - hence the changes to quote_end().

parse_util_locate_cmdsubst_range() is aware
of the changes to quote_end() but some of its
callers like parse_util_detect_errors_in_argument() and
highlighter_t::color_as_argument() are not.  They split strings at
command substitution boundaries without handling the special quoting
rules. (Only the expansion logic did it right.)

Fix this by handling the special quoting rules inside
parse_util_locate_cmdsubst_range(). This is a bit hacky since it
makes it harder for callers to process some substrings in between
command substitutions, but that's okay because current callers only
care about what's inside the command substitutions.

Fixes #8394
2021-10-30 18:02:10 +02:00
Fabian Homborg
5c6c405b9e Cache if tracing is enabled
Like the comment said: That var lookup was kind of expensive.

So we simply use variable dispatch like we do for countless other things.
2021-10-28 19:39:30 +02:00
ridiculousfish
e89bd95d58 Mild refactoring of wait handles 2021-10-28 10:37:43 -07:00
Fabian Homborg
357f49c781 Revert "Use unescape_string_in_place"
This reverts commit 2ef8a9c1af.

This doesn't work everywhere, not sure why.
2021-10-28 18:09:25 +02:00
Fabian Homborg
292c9d5381 Force uselocale if glibc is in use
For some reason on a current glibc 2.33, the configure check fails.
The man page says we'd have to define XOPEN_SOURCE>=700, but I don't
want to do that since it changes a bunch of other things, and it
didn't work in my tests.

So we just force it, since we know it works (since glibc 2.3).

This is a performance difference of ~20% for printf, so it's a
reasonably big deal.
2021-10-28 17:54:35 +02:00
Fabian Homborg
2ef8a9c1af Use unescape_string_in_place
We already get a copy, so we might as well just use it.
2021-10-28 17:32:52 +02:00
Fabian Homborg
31d6abb177 Don't fire variable set event before entering a for-loop
Since #4376, for-loops would set the loop variable outside, so it
stays valid.

They did this by doing the equivalent of

```fish
set -l foo $foo
for foo in 1 2 3
```

And that first imaginary `set -l` would also fire a set-event.

Since there's no use for it and the variable isn't actually set, we
remove it.

Fixes #8384.
2021-10-28 16:32:58 +02:00
Aaron Gyes
575decc35b also not a thread id: nullptr 2021-10-28 02:14:29 -07:00
Aaron Gyes
362319d25f Cleanup on aisle haphazard-everywhere 2021-10-28 01:47:49 -07:00
ridiculousfish
3848a68e5c Fix a misspeeling 2021-10-27 14:16:32 -07:00
Fabian Homborg
6941c94c4a
cd: Set var via the string
This was meant to trigger the wcstring_list_t overload by constructing one with `{norm_dir}`. Older gcc can't figure out what to do.

So instead we use the wcstring overload for now.
2021-10-27 10:20:14 +02:00
Fabian Homborg
f1fe6a5e94 Update widechar_width to Unicode 14
Generated with f438dbf6c4648ec94e154d2e475a3052370ea218
2021-10-26 18:26:25 +02:00
Fabian Homborg
76f3564e2a Remove now unused out_events parameter 2021-10-26 17:38:40 +02:00
Fabian Homborg
0c3c3eaa99 Reuse the variable event for for-loops
This used to construct a vector, which was then passed down and filled
with a new event_t each go around the loop. That's useless - we fire
one event here, and it's simply the variable event.

This reduces the overhead of a for-loop by ~10%:

```fish
for i in (seq 100000)
    true
end
```

runs in about 90% of the time now.
2021-10-26 17:38:35 +02:00
Fabian Homborg
452675d458 Use set_vars_and_fire where possible
This just did the same thing manually.
2021-10-26 17:33:36 +02:00
Fabian Homborg
da201ee8ac Let parser::set_var_and_fire fire the event directly
The vector here gives us *nothing*
2021-10-26 17:33:27 +02:00
Fabian Homborg
d9f094db1a Check if the for variable is invalid before trying to set it 2021-10-26 16:59:03 +02:00
ridiculousfish
e84dad5432 Rationalize null handling in disown_job
disown_job had some extraneous null checks that could not happen in
practice. Simplify this code.
2021-10-25 16:13:00 -07:00
ridiculousfish
ec244c3975 Add tests for dynamically invoked break and continue 2021-10-25 12:43:30 -07:00
ridiculousfish
cb79548c49 Revert "break/continue: Stop checking if it's in a loop again"
This reverts commit 61cd05efb0.

It is true that we detect break and continue errors statically, but they can
still be invoked dynamically, example:

    set sneaky break
    $sneaky # dynamically breaks from the loop

or just `eval break`.

A followup commit will add tests for this.
2021-10-25 12:42:53 -07:00
Fabian Homborg
61cd05efb0 break/continue: Stop checking if it's in a loop again
This is already checked in the parse_util_detect_errors (and might
actually be done in the ast - that's where we check "end")
2021-10-25 18:57:10 +02:00
Fabian Homborg
18bb5f1f7e builtin_count: Remove superfluous L'' prefix
(not sure if this broke anything anywhere, but since we're comparing
an actual char* we should use '' without the L)
2021-10-25 18:40:43 +02:00
ridiculousfish
a6a1879481 Remove reader_get_history
It was unused.
2021-10-24 14:17:33 -07:00
Aaron Gyes
a7e62a538e Revert "Swap file size and file type description position in pager"
This reverts commit d8722a3ddf.

I underestimated the value of having the file sizes easier to
eyeball and compair. Back to the drawing board.
2021-10-23 22:17:09 -07:00
Aaron Gyes
d8722a3ddf Swap file size and file type description position in pager
File sizes are are always of variable length, while we there
are just a few different typrs of files. Since we right align,
this makes things look more lined up.

…ocal/bin/afsctool                (Executable, 74.0kB)
…ocal/bin/clang-format        (Executable link, 1.9MB)
…ocal/bin/clone_checker             (Executable, 33kB)
…ocal/bin/cryptest.exe              (Executable, 11MB)
…ocal/bin/cscc                      (Executable, 22kB)
…ocal/bin/cscout                   (Executable, 902kB)
…ocal/bin/csmake                    (Executable, 22kB)
…ocal/bin/cswc                     (Executable, 5.7kB)
…ocal/bin/dirb                      (Executable, 90kB)
…ocal/bin/ethminer-m1              (Executable, 4.8MB)
…ocal/bin/fork                (Executable link, 206kB)

vs

…ocal/bin/afsctool                (74.0kB, Executable)
…ocal/bin/clang-format        (1.9MB, Executable link)
…ocal/bin/clone_checker             (33kB, Executable)
…ocal/bin/cryptest.exe              (11MB, Executable)
…ocal/bin/cscc                      (22kB, Executable)
…ocal/bin/cscout                   (902kB, Executable)
…ocal/bin/csmake                    (22kB, Executable)
…ocal/bin/cswc                     (5.7kB, Executable)
…ocal/bin/dirb                      (90kB, Executable)
…ocal/bin/ethminer-m1              (4.8MB, Executable)
…ocal/bin/fork                (206kB, Executable link)
…ocal/bin/fish                     (2.4MB, Executable)
2021-10-23 15:37:43 -07:00
ridiculousfish
2ed0105692 Use std::move to populate a processes's args
This could save quite a few string copies.
2021-10-23 10:35:05 -07:00
ridiculousfish
4a6d622733 Continue to refactor functions
Now that we have immutable props, we can remove a bunch of 'helper'
functions.
2021-10-23 10:12:52 -07:00
ridiculousfish
7d7b930b08 Rename function_get_properties to function_get_props
We're calling it a lot so let's make it shorter.
2021-10-23 10:12:52 -07:00
ridiculousfish
089da2314d Eliminate function_info_t
function_info_t was the "mutable bits" of a function, like its
description. But we have eliminated all of those, so we can eliminate
the class.

No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
1c5208cf5c Migrate a function's description into its immutable properties
No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
17d9ae16be Migrate the function's is_autoload field into its immutable properties
Continuing to simplify functions. No functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
12134c19d9 Migrate the function's definition file into its immutable properties
This never changes once initialized, so we can make it immutable. No
functional change here.
2021-10-23 10:12:52 -07:00
ridiculousfish
d904cc4964 Stop passing null function properties in testing
This allows us to assert that our functions are not null.
2021-10-23 10:12:52 -07:00
ridiculousfish
59b63f3aab Use vec_append when expanding a command into arguments
This saves some lines and some allocations.
2021-10-23 10:10:26 -07:00
ridiculousfish
a634e78633 Remove an extra use of process_type_for_command
This just duplicated a previous call above.
2021-10-23 10:07:24 -07:00
Fabian Homborg
144778dc28 Complete: Fix long-form of "-r" in complete output
This was never `--requires-param`, AFAICT.
2021-10-20 21:05:17 +02:00
Fabian Homborg
b15dc2b2e8 argparse: Prevent duplicate error trailer
This was already printed by builtin_missing_argument/unknown_option.

Since we need more control (because we add our own errors in other
places), teach builtin_unknown_option to suppress the trailer, like
missing_argument already could.

And then use it.

Fixes #8368.
2021-10-19 17:43:54 +02:00
Fabian Homborg
43c58df873 Test option highlighting in command substitutions 2021-10-19 17:30:45 +02:00
Fabian Homborg
9700a75f38 fish_tests: Make a fancy caret for highlighting errors
Now looks like

```
Error: Wrong color in test at index 8-11 in text (expected 0x6, actual 0x2):
command echo abc foo &
        ^^^^
```

instead of repeating the error for every character that is wrong.
2021-10-19 17:27:35 +02:00
Fabian Homborg
711796ad13 Highlight options differently
This introduces a new variable, $fish_color_option, that can be used
to highlight options differently.

Options are tokens starting with `-`, but only up to (and including!)
the first `--`.

Fixes #8292.
2021-10-19 17:20:21 +02:00
Erik Serrander
049104e8df Adds sub-command clear-session to history command.
Issue #5791
This clears all history for the current session. Documentation and
autocompletion for the new subcommand is added.
2021-10-17 19:27:46 -07:00
ridiculousfish
f0d4fd85b1 Use __GLIBC_PREREQ instead of parsing gnu_get_libc_version
__GLIBC_PREREQ is the preferred way to conditionally enable features
based on glibc versions. Use it to avoid expensive parsing and
locale sensitivity. See #8204
2021-10-15 21:12:26 -07:00
Fabian Homborg
ec8844d834 Drop tests with resetting match start inside lookaround
This seems to be of little use

Fixes #8353
2021-10-14 18:18:51 +02:00
Fabian Homborg
c54b8dca33 Read glibc's version in a locale-independent way
We want to enable posix_spawn only for glibc >= 2.24, so we check
gnu_get_libc_version() at runtime. This returns a string with the
version number.

Because it's a version number it's spelt with a "." and never a ",",
but we interpret it as a float. This is iffy to begin with, but simple
enough. Only when the locale uses a ",", things break - it'll read it
as "2" and fail the check, which absolutely *tanks* performance on WSL1.

I'm unsure if this gives the proper runtime glibc version - it might,
whereas __GLIBC_MINOR__ and such definitely would not.

So fix the immediate problem by at least using a c locale - this is
already masked by 8dc3982408, but better
safe than sorry.
2021-10-14 17:02:50 +02:00
Fabian Homborg
7850a10c45 Stop some wcs2stringing
These are paths that barely change, narrowing them *twice* per file
load makes absolutely no sense.
2021-10-14 17:02:50 +02:00
Fabian Homborg
8dc3982408
Always use LC_NUMERIC=C internally (#8204)
In most cases, like math, we want C-semantics for floating point
numbers. In particular "." needs to be the decimal separator.

Instead, we pay the price in printf, which is currently the sole place
to output in locale-specific numbers and attempt to read them and
C-style ones.
2021-10-13 21:09:40 +02:00
Aaron Gyes
172601299f builtin _ is now a reserved keyword
Similar to `test`, `_` is so likely to at least slow down if not
break all things catastrophically that it ought not be allowed as a
function name. Fixes #8342
2021-10-11 00:27:44 -07:00
Fabian Homborg
6af3896217 wcsfilecmp: Stop actually computing the numbers
This just compares two longs as strings on the go.

We can simply

1. ignore leading zeroes - they have no influence on the value
2. compare the digits char-by-char
3. keep the comparison for the first differing digit
4. if one number is longer than the other, that is larger
5. if the numbers have the same length, the one larger in the first
differing digit is larger

This makes this comparison quite a bit faster, which makes globs in
directories with numbered files up to 20% faster.

Note that, for historical reasons, this still ignores whitespace right
after the numbers!
2021-10-07 17:57:52 +02:00
Aaron Gyes
8259bf7c7e Remove hack for Terminal.app that did not support 256 colors
We didn't support that version of macOS even before we bumped to
10.10.
2021-10-06 19:36:18 -07:00
Mahmoud Al-Qudsi
fe63c8ad32 Shadow/override iswdigit instead of changing it at individual call sites
1ab81ab90d removed one usage of iswdigit()
but there are others; more importantly, the knowledge that iswdigit() is
slow isn't preserved anywhere apart from the git history, so there's
nothing to prevent its use from creeping back into the codebase.

Another alternative is to blacklist iswdigit() (shadow it with a
function of the same name that throws a static_assert) but if we're
going to shadow it anyway, might as well make it useful.
2021-10-04 18:44:16 -05:00