Commit graph

16243 commits

Author SHA1 Message Date
Fabian Boehm
e726627993 Upgrade widechar_width to Unicode 15 2022-09-26 17:17:17 +02:00
Fabian Boehm
011af34d62 fish_vi_cursor: Use xterm sequence for iterm
This has been supported since 2012, allows blinking cursors and works
in tmux.

Fixes #9172
Fixes #3741
2022-09-26 17:06:14 +02:00
Fabian Boehm
42602ba4fc
completions/ffmpeg: Add missing parenthesis
Going by the other `string match`, this appears to just be missing a ")".

Fixes #8514
2022-09-26 15:11:58 +02:00
Ryuhei Yoshida
51177ef0ae Fix completions/tox 2022-09-26 09:45:54 +02:00
NextAlone
4b9c7fa534
Add usbip completions
Closes #9237
2022-09-25 15:30:34 -05:00
Mahmoud Al-Qudsi
5d64b56127 Remove needless usage of maybe_t
builtin_function() never returns `none()`; this must have been leftover from a
previous version of the code.
2022-09-25 14:40:49 -05:00
Mahmoud Al-Qudsi
ff00d3ca08 fixup! Fix stomping of last_option_requires_param
Fix accidental misuse of maybe_t boolean operator instead of maybe_t payload.
2022-09-25 13:33:33 -05:00
Mahmoud Al-Qudsi
3ebfba7f5b Test return builtin doesn't map negative numbers to zero
Prior to 1811a2d, the return value for negative return codes was UB and I'd
witnessed both expected cases like -256 mapping to a $status of 0 and unexpected
cases like a return value of -1 mapping to a $status of 0. As such, this doesn't
test just one fixed return value but the entire range from negative multiples of
256 all the way down (rather, up!) to -1.
2022-09-25 12:37:10 -05:00
Mahmoud Al-Qudsi
1811a2d725 Prevent undefined behavior by intercepting return -1
While we hardcode the return values for the rest of our builtins, the `return`
builtin bubbles up whatever the user returned in their fish script, allowing
invalid return values such as negative numbers to make it into our C++ side of
things.

In creating a `proc_status_t` from the return code of a builtin, we invoke
W_EXITCODE() which is a macro that shifts left the return code by some amount,
and left-shifting a negative integer is undefined behavior.

Aside from causing us to land in UB territory, it also can cause some negative
return values to map to a "successful" exit code of 0, which was probably not
the fish script author's intention.

This patch also adds error logging to help catch any inadvertent additions of
cases where a builtin returns a negative value (should one forget that unix
return codes are always positive) and an assertion protecting against UB.
2022-09-25 12:33:40 -05:00
Fabian Boehm
ccca5b553f Disable VQUIT for shell modes
This allows binding ctrl+\ by default.

Fixes #9234
2022-09-25 13:27:01 +02:00
Fabian Boehm
0ede48e024 benchmarks: Do hyperfine first
Helps with warmup
2022-09-25 13:27:01 +02:00
ridiculousfish
07c09bdee2 Tutorial: Merge the footnotes on aliases and abbreviations together
@mqudsi's feedback from #9226
2022-09-24 15:15:33 -07:00
ridiculousfish
39f3f75f5b Correct abbreviations typo and doc link 2022-09-24 15:14:31 -07:00
Luca Trevisani
064699cade Add reference to abbreviations 2022-09-24 15:10:11 -07:00
ridiculousfish
692a2fc135 Sphinx: disable hyphenation
Hyphenation in our documentation is aggressive, even to the point of caus-
ing options themselves to be broken across lines. This makes the document-
ation hard to read, especially when you have an option like `string colle-
ct` which gets a weird hyphen.

Remove the hyphenation from the CSS.
2022-09-24 12:36:39 -07:00
Fabian Boehm
f4797a0133 benchmarks: Use --no-config
It's existed since 3.3.0, so now seems to be an acceptable time to add
it.

(also adjust some repetitions a bit so they don't take too long)
2022-09-24 13:36:24 +02:00
Fabian Boehm
1204cf5eb6 docs/read: Improve examples a bit 2022-09-24 10:56:43 +02:00
Fabian Boehm
38b24c2325 docs: Use :doc: role when linking to commands
This makes it so we link to the very top of the document instead of a
special anchor we manually include.

So clicking e.g. :doc:`string <cmds/string>` will link you to
cmds/string.html instead of cmds/string.html#cmd-string.

I would love to have a way to say "this document from the root of the
document path", but that doesn't appear to work, I tried
`/cmds/string`.

So we'll just have to use cmds/string in normal documents and plain
`string` from other commands.
2022-09-24 10:56:43 +02:00
ridiculousfish
bc4e7c3fea 'C_' function to use g_empty_string
Use the global empty string instead of having its own.
2022-09-23 14:32:20 -07:00
Mahmoud Al-Qudsi
1f41ce9446 Change localized_desc() to return a reference
Bubble up the reference returned by `C_()`.

This is a prerequisite for a bigger change I'm working on.
2022-09-23 14:01:02 -05:00
Mahmoud Al-Qudsi
1f91056539 Always return a const wcstring reference from _C()
This was always the case if HAVE_TEXT wasn't defined, but if it was then we were
coercing the result of `_C()` to a `const wchar_t *` pointer, because we were
returning the address of a constant zero-length wchar_t pointer. This reserves a
local static `wcstring` variable that we can return as the "no text" sentinel
and bubbles back the `wcstring` reference rather than decomposing it into a
pointer.

This is a prerequisite for a bigger change I'm working on.
2022-09-23 14:00:42 -05:00
Mahmoud Al-Qudsi
67c0a1db85 Reduce size of complete_entry_opt_t
It's gone from 136 bytes to a 128 bytes by rearranging the items in order of
decreasing alignment requirements. While this reduces the memory consumption
slightly (by around 6%) for each completion we have in-memory, that translates
to only around ~8KiB of savings for a command with 1000 possible completions,
which is nice but ultimately not that big of a deal.

The bigger benefit is that a single `complete_entry_t` might now fit in a cache
line, hopefully making the process of testing completions for matches more
cache friendly (and maybe even faster).
2022-09-23 12:09:26 -05:00
Mahmoud Al-Qudsi
0e9371cf24 complete_entry_opt_t: Rename list member condition to conditions
We used both a singular "condition" and a plural "condition" with the latter
referring to a list of the former. Clean that up.
2022-09-23 12:03:02 -05:00
Mahmoud Al-Qudsi
e9908d7d41 Clean up more mktemp usage residue
...for improved cross-platform support.

Following up on the work in c90ac7b. There was one more test that had mktemp in
the littlecheck "shebang" and this also removes a now-unnecessary `env` prefix.
2022-09-23 11:05:58 -05:00
Fabian Boehm
17426d4741 docs: Write an example for interactive read 2022-09-23 16:25:35 +02:00
Fabian Boehm
b88b257726 Stringify apt completions again
Commit 09685c3682 tried making the apt
completions faster by doing two things:

1. Introduce a limiting "head"
2. Re-replace our "string" usage with tr

Unfortunately, in doing so it introduced a few issues:

1. The "tr" had a dangling "+" so it cut apart package
   descriptions that contained a "+".
   This caused e.g. "a C++ library" to generate another completion
   candidate, "library".
2. In reusing "tr" it probably reintroduced #8575,
   as tr is not 8-bit-clean.
3. It filtered too early, on the raw apt-cache output,
   which caused it to fill up with long descriptions.
   So e.g. for "texlive" it would only generate 10 completions,
   where it should have matched 54 packages.

Because most of the speedup is in the "head" stopping early, we
instead go back to the old string way, but introduce a limiting "head"
after the "sed" (which will have removed everything but the package
name line and the first line of the description)

In my tests this is about ~10% slower than doing head early and using
tr, but it's more correct.

Admittedly I haven't been able to reproduce the 35s scenario that
09685 talks about, but the most likely cause of that is *apt-cache*
being slow - I don't see how string can be that much slower on another
system - and so it will most likely also be fixed by doing head here.

Future possibilities here include:

1. Using "apt-cache search --names-only", which gives a much nicer
format (but only for non-installed packages - the search strings are
apparently ANDed?)
2. Switching to `string split`, possibly using NUL and using `string
split0`?
3. Introducing a `string --null-in` switch so we can get by with one
`string`
4. (multi-threaded execution so the `string`s run in parallel)
2022-09-23 15:37:40 +02:00
Mahmoud Al-Qudsi
c90ac7bf7f Fix tests on macOS 10.10
All usages of `mktemp` must go through the (fish-only) `mktemp` test function
that abstracts over the differences across multiple platforms/flavors.

Tests can be easily run individually via `ninja -C build test_xxx` and there
isn't a good reason to randomly manually override $HOME and $XDG_CONFIG_HOME for
a test here and a test there.

If it's absolutely necessary, littlecheck.py should be extended to support a
`%temp` variable initialized to a temporary directory and that can be used
instead of calling out to the platform-provided `mktemp` via a subshell.
2022-09-22 17:39:28 -05:00
Fabian Boehm
604fa867ac CHANGELOG 2022-09-22 22:50:33 +02:00
Fabian Boehm
e69be38235 string: Reduce write() calls
The impact here depends on the command and how much output it
produces.

It's possible to get up to 1.5x - `string upper` being a good example,
or a no-op `string match '*'`.

But the more the command actually needs to do, the less of an effect
this has.
2022-09-22 22:41:35 +02:00
Fabian Boehm
7bc4c9674b builtins: Reduce streams.out.append/push_back calls
This basically immediately issues a "write()" if it's to a pipe or the
terminal.

That means we can reduce syscalls and improve performance, even by
doing something like

```c++
streams.out.append(somewcstring + L"\n");
```

instead of

```c++
streams.out.append(somewcstring);
streams.out.push_back(L'\n');
```

Some benchmarks of the

```fish
for i in (string repeat -n 2000 \n)
    $thing
end
```

variety:

1. `set` (printing variables) sped up 1.75x
2. `builtin -n` 1.60x
3. `jobs` 1.25x (with 3 jobs)
4. `functions` 1.20x
5. `math 1 + 1` 1.1x
6. `pwd` 1.1x

Piping yields similar results, there is no real difference when
outputting to a command substitution.
2022-09-22 22:41:35 +02:00
Fabian Boehm
c5b5dd7563 printf: Buffer output
This writes the output once per argument instead of once per format or
escaped char.

An egregious case:

```fish
printf (string repeat -n 200 \\x7f)%s\n (string repeat -n 2000 aaa\n)
```

Has been sped up by ~20x by reducing write() calls from 40000 to 200.

Even a simple

```fish
printf %s\n (string repeat -n 2000 aaa\n)
```

should now be ~1.2x faster by issuing 2000 instead of 4000 write
calls (the `\n` was written separately!).
2022-09-22 22:41:35 +02:00
Fabian Boehm
64927677c8 complete: Write each completion at once for --do-complete
This at least halves the number of "write()" calls we do if it goes to
a pipe or the terminal, or reduces them by 75% if there is a
description.

This makes

```fish
complete -c foo -xa "(seq 50000)"
complete -C"foo "
```

faster by 1.33x.
2022-09-22 22:41:35 +02:00
Mahmoud Al-Qudsi
42e177dc1b Fix build on macOS 10.10 Yosemite 2022-09-22 14:00:58 -05:00
Mahmoud Al-Qudsi
09685c3682 Make apt completions useable once again
`apt-cache` is just so incredibly slow that filtering against the final results
just doesn't cut it. Attempting to match against 'ac.*' (already taking
advantage of changing short search terms into prefix-only matches) would take
35 seconds, all of bottlenecked before the filtering step. This change uses more
of a heuristic to filter `apt-cache` results directly (before additional
filtering) to speed things up.

A variety of different limits from 100 to 5000 were timed and their result sets
compared to see what ended up artificially limiting valid completions vs what
took too long to be considered functional/usable and this is where we ended up.
2022-09-22 13:43:38 -05:00
Fabian Boehm
6a93d58797 wildcard: Use wreaddir_resolving if directories are needed
This uses wreaddir_resolving, which tries to use the dirent d_type
field if it exists. In that way, it can skip the `stat` to determine
if the given file is a directory.

This allows `cd` completions to skip stat in most cases:

```fish
strace -Ce newfstatat fish --no-config -c 'complete -C"cd /tmp/completion_test/"' >/dev/null
```

prints before:
```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100,00    0,002627           2      1033         4 newfstatat
```

after:

```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100,00    0,000054           1        31         3 newfstatat
```

for a directory with 1000 subdirectories.

(just `fish --no-config -c exit` does 26 newfstatat)

This should improve the situation with slow filesystems like fuse or
network fsen.

In case we have no d_type, we use `stat`, which would yield about the
same results.

The worst case is that we need directories *and* descriptions or the
"executable" flag (which we don't currently check for cd, if I read
this right?).
2022-09-21 19:49:17 +02:00
Fabian Boehm
a277f9aa93 WSL: Only skip ".dll" files for *executable* completions
This was overzealous and didn't allow anything named ".dll" in any
file completions.

This allows us to now add the cd completion fast path for WSL
2022-09-21 19:49:17 +02:00
Fabian Boehm
8b9a051b93 wreaddir_resolving: Don't add "/" for empty paths
This could end up trying to `stat()` a file in /, like "/glassdoor",
if the dir_path was empty.
2022-09-21 19:49:17 +02:00
Fabian Boehm
88e578a9ed Remove superfluous CHECK lines
Oops
2022-09-21 18:37:38 +02:00
Fabian Boehm
3dded49b9b tests/checks/test: Attempt to fix on old Ubuntu
For unknown reasons, the i686 launchpad builders fail on this date,
but apparently not the others.

Let's just remove it, we've tested dates older than the epoch, this is
slightly redundant.
2022-09-21 18:20:05 +02:00
Fabian Boehm
af3a5b86d8 Call __fish_config_interactive also for interactive read
Not doing this results in our emergency keybindings being set up for
`read`.

Fixes #9227
2022-09-21 17:02:25 +02:00
ridiculousfish
ceafb65882 Compile with large-file support (LFS)
This adds preprocessor defines for _LARGEFILE_SOURCE and
_FILE_OFFSET_BITS=64 and a few others, fixing a bug that was reported on
gitter. This prevents issues when running fish on 32 bit systems that
have filesystems with 64 bit inodes.
2022-09-20 22:51:44 -07:00
Mahmoud Al-Qudsi
429534496a fixup! Fix stomping of last_option_requires_param 2022-09-20 22:37:17 -05:00
Mahmoud Al-Qudsi
ed67f2d221 Drop a now-incorrect check test from checks/git.fish
As discussed in #9221, a bug in the autocomplete that was fixed in 66391922
caused completions to be incorrectly suppressed. The dropped test/check was
inadvertently relying on the buggy behavior and expected a git invocation to
generate no completions but there are, in fact, completions now that the bug has
been resolved.

cc @faho: I'm not sure if you want to replace this with a different check that
actually doesn't yield any completions or if you're happy with it just being
dropped.
2022-09-20 21:56:54 -05:00
Mahmoud Al-Qudsi
663919228b Fix stomping of last_option_requires_param
This flag determines whether or not more shortopt switches will be offered up as
potential completions (vs only the payload for the last-parsed shortopt switch).

Previously, it was being stomped before it was determined whether or not two
`complete` rules with different `result_mode.requires_param` values were
actually resolved against the current command line or not, and the last
evaluated completion rule would win out.

There are two changes here:
* `last_option_requires_param` is only assigned if all associated conditions for
  a potential completion are also met, and
* If already assigned by a conflicting rule (which can only be user/developer
  error), `last_option_requires_param` is allowed to change from true to false
  but not the other way around (i.e. in case of a conflict, generate both
  payloads and other shortopt completions)

The first change is immediately noticeable and affects many of our own
completions, see the discussion in #9221 for an example regarding `git` where
`-c` has any of about a million different possible meanings depending on which
completion preconditions have been met. The second change should only happen if
a dev/user mistakenly enters a `complete -c ...` rule for the same shortopt more
than once, both with conditions matching, sometimes requiring an argument and
not sometimes not. It should be a rare occurence.
2022-09-20 21:49:30 -05:00
ridiculousfish
379ad245e4 cmake: defeat bogus missing-field-initializers warning on g++ 4.8
g++ 4.8 emits a bogus warning on code like foo{}. Add a compiler flag
-Wno-missing-field-initializers if that warning is detected, because it
is annoying.
2022-09-20 14:41:22 -07:00
ridiculousfish
e7de342259 Remove a variable name in a defaulted function
This fixes a g++ 4.8 warning.
2022-09-20 14:41:22 -07:00
ridiculousfish
81c29d8891 clang-format and minor cleanup of tinyexpr.cpp
Clarifies some code and fixes some g++ 4.8 warnings.
2022-09-20 14:41:22 -07:00
Luca Trevisani
86138db9f5 Fix Control+C key binding description 2022-09-20 23:21:16 +02:00
ridiculousfish
5f4583b52d Revert "Re-implement macro to constexpr transition"
This reverts commit 3d8f98c395.

In addition to the issues mentioned on the GitHub page for this commit,
it also broke the CentOS 7 build.

Note one can locally test the CentOS 7 build via:

    ./docker/docker_run_tests.sh ./docker/centos7.Dockerfile
2022-09-20 11:58:37 -07:00
Fabian Boehm
4ffcbe3526 tests/path: Allow a little slack
This was 86400 on some systems but 82800 on mine. I think that's a
timezone thing?
2022-09-20 16:17:32 +02:00