Commit graph

12878 commits

Author SHA1 Message Date
Fabian Homborg
900a3c4049 complete: Remove removed options from the docs
These have been removed for ages, the complete docs are too verbose as
it is.
2020-09-09 20:23:15 +02:00
Fabian Homborg
903b7888d3 complete: Make -c optional
Currently, completions have to be specified like

```fish
complete -c foo -l opt
```

while

```fish
complete foo -l opt
```

just complains about there being too many arguments.

That's kinda useless, so we just assume if there is one left-over
argument that it's meant to be the command.

Theoretically we could also use *all* the arguments as commands to
complete, but that seems unlikely to be what the user wants.

(I don't think multi-command completions really happen)
2020-09-09 20:23:08 +02:00
Fabian Homborg
a8e237f0f9 Let complete show completions for one command if just given -c
Currently only `complete` will list completions, and it will list all
of them.

That's a bit ridiculous, especially since `complete -c foo` just does nothing.

So just make `complete -c foo` list all the completions for `foo`.
2020-09-09 18:37:39 +02:00
Fabian Homborg
34be1b458a Add fish_command_not_found handler for pacman
Since version 5 (IIRC), pacman has a file database.

This is useful for people who don't have pkgfile, but we still prefer
that because it's much faster - pacman takes a full *second* on my system.
2020-09-09 17:44:25 +02:00
Johannes Altmanninger
de9874e4de Remove some useless casts
I think the warnings from -Wuseless-cast are mostly platform-specific but
I hope these are correct.
2020-09-08 22:44:03 +02:00
Johannes Altmanninger
fbaa5d193d Declare functions in headers or use internal linkage (static)
Found with gcc's -Wmissing-declarations which gives warnings like

	../src/tinyexpr.cpp:61:5: warning: no previous declaration for ‘int get_arity(int)’ [-Wmissing-declarations]
	   61 | int get_arity(const int type) {

The same warnings show up for builtin functions like builtin_bg because they
currently don't include their own headers. I left that.
Also reformat the touched files.
2020-09-08 22:44:03 +02:00
Johannes Altmanninger
7a4fece445 Give reader control of all edits to a command line
So we can do something on every edit, for example repaint the pager (#7318).
This patch fixes pager refiltering and repainting when pressing Control+U
after typing something in the search field.

Implement this by moving the convenience functions from editable_line_t to
the reader, so we have fewer places where we need to refilter.  Essentially we
only have two cases: insertions at the cursor are handled by insert_string(),
and all others go through push_edit().  This should also make it clearer
where we update undo_history.may_coalesce.

This commit was on the history-search-edit-needle branch, so it should
work fine.  I hope it does play well with some recent changes.

In 6d339df61 (Factor repainting decions from readline commands better
in the reader), insert_string() was simplified a lot, mirror that.

The tests for editable_line_t are not that useful anymore since the caller has
to decide whether to coalesce insertions, but I guess they don't hurt either.
We should have more tests for some interactive scenarios like undo and the
pager filtering.
2020-09-08 22:00:48 +02:00
Mahmoud Al-Qudsi
90433f6ea3 Minimize AST node vector reallocations
Closes #7201
2020-09-08 11:55:10 -05:00
oui-ui
0f674435a3 correct description of -a param regarding _(\w*)
removed the word "not" to resolve an (unintended) negation of negation.
2020-09-08 18:02:50 +02:00
Fabian Homborg
f67673de71 Repaint on pager search
This was broken in 6d339df612, when we removed
the normal repainting logic.

The pager *search* however needs to trigger a refilter, and therefore
needs to trigger after every insert/removal.

Fixes #7318
2020-09-08 15:01:22 +02:00
Mahmoud Al-Qudsi
f88106ef96 [travis] Remove root sudo YAML property
Travis has been complaining that the root `sudo` key is deprecated and
no longer has any effect.
2020-09-07 20:59:42 -05:00
Mahmoud Al-Qudsi
be1604fe31 fixup! Add str2wcs optimization for ascii-only inputs
Fix aligned read past end of buffer.
2020-09-07 20:39:49 -05:00
Mahmoud Al-Qudsi
84c72f2817 Add str2wcs optimization for ascii-only inputs
This avoids the heavy hit of __gconv_transform_utf8_internal.

In the worst case, after `is_ascii` returns the string is guaranteed to
be in the CPU cache (assuming realistic input sizes). In the best (and
hopefully extremely common) case, the conversion table lookups are
completely avoided.

In terms of real world gains, simply calling `history` is anywhere from
2x to 3x faster for large history files composed of mostly ascii
content under glibc 2.31 on AMD64.
2020-09-07 19:38:06 -05:00
Mahmoud Al-Qudsi
1365379518 Optimize away a str2wcs_internal check
str2wcs_internal is one of worst hot paths in the codebase, and this
particular check can be optimized away for non-macOS hosts at compile
time.
2020-09-07 18:05:18 -05:00
Mahmoud Al-Qudsi
bf31333622 [ffmpeg] Prevent -codec from matching -codec:[vas]
This was preventing the narrowing of matching completions.

[ci skip]
2020-09-07 16:52:47 -05:00
Mahmoud Al-Qudsi
2a4289dcd1 [ffmpeg] Fix variable name in __fish_ffmpeg_complete_regex
[ci skip]
2020-09-07 16:52:47 -05:00
Joost-Wim Boekesteijn
0cec12c6c0 ffprobe completions: show_stream -> show_streams
This should be `show_streams` instead of `show_stream` according to:

31b6b6685e:/doc/ffprobe.texi#l218
2020-09-07 18:52:08 +02:00
Fabian Homborg
576ce5f9f5 Remove __fish_command_not_found_handler
This could lead to an infinite loop (well, stack overflow) because
fish_command_not_found would also be defined to call
__fish_command_not_found_handler.

Since this is for

- missing command errors
- when downgrading

we can just remove it.
2020-09-06 13:50:38 +02:00
Fabian Homborg
58d549e058 CHANGELOG fish_command_not_found
[ci skip]
2020-09-06 11:18:31 +02:00
Fabian Homborg
0131974378 Use OpenSUSE command-not-found via $PATH
We check the full $PATH, so it's not guaranteed that it is in /usr/bin.
2020-09-06 11:15:54 +02:00
Fabian Homborg
fbe56a84c7 tests: Export $TERM
I think this might be causing problems on Github CI.
2020-09-06 11:15:54 +02:00
Fabian Homborg
340de73172 Call "fish_command_not_found" if a command wasn't found
Previously, when a command wasn't found, fish would emit the
"fish_command_not_found" *event*.

This was annoying as it was hard to override (the code ended up
checking for a function called `__fish_command_not_found_handler`
anyway!), the setup was ugly,
and it's useless - there is no use case for multiple command-not-found handlers.

Instead, let's just call a function `fish_command_not_found` if it
exists, or print the default message otherwise.

The event is completely removed, but because a missing event is not an error
(MEISNAE in C++-speak) this isn't an issue.

Note that, for backwards-compatibility, we still keep the default
handler function around even tho the new one is hard-coded in C++.

Also, if we detect a previous handler, the new handler just calls it.

This way, the backwards-compatible way to install a custom handler is:

```fish
function __fish_command_not_found_handler --on-event fish_command_not_found
    # do a little dance, make a little love, get down tonight
end
```

and the new hotness is

```fish
function fish_command_not_found
    # do the thing
end
```

Fixes #7293.
2020-09-06 11:15:54 +02:00
ridiculousfish
d1dab22691 Ensure we don't leak half of a pipe
It was possible though unlikely for make_autoclose_pipes to close only
one side of pipe, if it fails to find a new fd. This would result in an
fd leak. Ensure that doesn't happen.
2020-09-05 13:24:26 -07:00
ridiculousfish
1cef87d790 Use anon semaphores only on Linux
On BSDs, anonymous semaphores are implemented using a file descriptor
which is not marked CLOEXEC, so it gets leaked into child processes.
Use ordinary pipes instead of semaphores everywhere except Linux.

Fixes #7304
2020-09-05 13:04:22 -07:00
ridiculousfish
acb33682a9 Remove some errant 'file' from redirection comment
See #7301
2020-09-05 11:28:43 -07:00
ridiculousfish
abadab5176 Revert "Fix examples in tokenizer comment for redirection"
This reverts commit 66f81a2b4c.
2020-09-05 11:27:48 -07:00
Nathan Lanza
66f81a2b4c Fix examples in tokenizer comment for redirection
Four of these examples were incorrect and didn't perform the stated
behavior in neither bash nor fish. Fix them here.
2020-09-05 11:27:30 -07:00
Aurelio Jargas
d4fe110f23 docs/isatty: Mention default value for FILE DESCRIPTOR
As seen in share/functions/isatty.fish (note the empty string):

    switch "$argv"
        case stdin ''
            set fd 0
2020-09-05 15:54:48 +02:00
Johannes Altmanninger
55bc6a27c6 Make prompts forward compatible with fish 3.1.2 by passing locally exported variable
Commit 5d135d555 (prompts: fix pipestatus for jobs prefixed with "not")
introduced a backwards compatibility hack about adding an optional argument
to __fish_print_pipestatus. This hack would break downgrading to fish 3.1.2
if the user copied the new prompt to their config - they would get a backtrace
on every prompt which is arguably worse than the patch's minor improvement.

This does away with the error trace - old fish just won't show the fancy
new pipestatus on `not true`.

Implemented by passing the last $status as the poor man's kwarg, which works
since 3.1.0 (9b86d5dd1 Export all local exported variables in a new scope).

The prompts don't work with fish 3.0.0 or older; downgrading does not seem
too important in general but I think this patch is an okay simplification.
2020-09-05 09:58:55 +02:00
Johannes Altmanninger
89724f9366 prompts: guard against missing fish_is_root_user
Prevents error spew when running one of these prompt on fish 3.1.2.
2020-09-05 09:48:47 +02:00
Mahmoud Al-Qudsi
4331face4a [vips] Add vips completions
Just a skeleton completion file, but the list of available
actions/completions is at least dynamically generated (there's a lot of
them, they are impossible to remember, and they depend on build
options).

[ci skip]
2020-09-04 21:40:27 -05:00
ridiculousfish
457f95fe52 Mark s_cancellation_signal a relaxed atomic
Thread sanitizer is salty about this even though it's
volatile sig_atomic_t. Make it atomic too.
2020-09-04 16:10:22 -07:00
ridiculousfish
3f3531c819 Ensure we preserve errno in signal handlers 2020-09-04 15:32:29 -07:00
Mahmoud Al-Qudsi
fe6fb23f43 [ffmpeg] Add -f formats completions
[ci skip]
2020-09-04 13:43:26 -05:00
Charles Gould
6fd68d553d Stop initializing fish_color_match, it is no longer used 2020-09-04 19:46:38 +02:00
Charles Gould
5e5b9d75e6 docs: Fix background color for interactive examples
For the few weird code blocks where default highlighting does not work,
we must add the 'highlight' class manually to get matching backgrounds.
This reuses the background color defined in pygments.css.
2020-09-04 19:46:38 +02:00
V
fc13dd362c
Colourise diff(1) output, if supported (#7308) 2020-09-04 18:43:09 +02:00
Fabian Homborg
4817f97823 tests: Print some more info in the job_summary test for debugging
This one fails a bunch on CI and I have no idea why.
2020-09-04 17:53:17 +02:00
Fabian Homborg
04562300e8 Pexpect: Return the match object instead of the result
The result is just the *index* of the pattern that matched. But since
we never pass a *list* it's just always 0.

spawn.match is the MatchObject that produced the match, so it can be
used to post-process the matched output, e.g.

```python
m = expect_re('\d+')
m.group() # is now the matched number
```
2020-09-04 17:53:17 +02:00
David Adam
8f5a84cdc7 CHANGELOG: work on 3.2.0
[ci skip]
2020-09-04 23:16:39 +08:00
Fabian Homborg
55f1cc56da Remove errant fish_wcwidth call
This was added in c9bcb52fe9 for no discernable reason.
2020-09-04 17:12:22 +02:00
Fabian Homborg
1041e59c5b fixup! Do actually use the correct command
Sorry!
2020-09-04 16:59:08 +02:00
Fabian Homborg
0ae37ac83a Add alias completions
Fixes #7305
2020-09-04 16:58:41 +02:00
Fabian Homborg
bfb5b28d0f Let command, jobs and type take --query instead of --quiet
Now command, jobs, type, abbr, builtin, functions and set take `-q` to
query for existence, but the long option is inconsistent.

The first three use `--quiet`, the latter use `--query`. Add `--query`
to the first three, but keep `--quiet` around.

Fixes #7276.
2020-09-04 16:55:09 +02:00
Fabian Homborg
6ca2dbecfb Remove duplicated test
Fixes #7307.
2020-09-04 16:30:13 +02:00
Fabian Homborg
3fcf4e1b20 tests: Shorten a sleep
This waited for a full second just to call `wait`.

Instead let's use 300ms, saving a full 700ms per test run.
2020-09-04 16:29:53 +02:00
Mahmoud Al-Qudsi
91b2edd51d [apt] Add --no-install-recommends
[ci skip]
2020-09-03 21:47:21 -05:00
Mahmoud Al-Qudsi
326fd8d750 [cargo] Add dynamic --package completions
[ci skip]
2020-09-03 13:41:37 -05:00
ridiculousfish
3062994645 Implement cancel groups
This concerns how "internal job groups" know to stop executing when an
external command receives a "cancel signal" (SIGINT or SIGQUIT). For
example:

    while true
        sleep 1
    end

The intent is that if any 'sleep' exits from a cancel signal, then so would
the while loop. This is why you can hit control-C to end the loop even
if the SIGINT is delivered to sleep and not fish.

Here the 'while' loop is considered an "internal job group" (no separate
pgid, bash would not fork) while each 'sleep' is a separate external
command with its own job group, pgroup, etc. Prior to this change, after
running each 'sleep', parse_execution_context_t would check to see if its
exit status was a cancel signal, and if so, stash it into an int that the
cancel checker would check. But this became unwieldy: now there were three
sources of cancellation signals (that int, the job group, and fish itself).

Introduce the notion of a "cancellation group" which is a set of job
groups that should cancel together. Even though the while loop and sleep
are in different job groups, they are in the same cancellation group. When
any job gets a SIGINT or SIGQUIT, it marks that signal in its cancellation
group, which prevents running new jobs in that group.

This reduces the number of signals to check from 3 to 2; eventually we can
teach cancellation groups how to check fish's own signals and then it will
just be 1.
2020-09-03 11:01:27 -07:00
ridiculousfish
760b6e76cc Rename populate_group_for_job to resolve_group_for_job
Factor it to allows the function to not modify the job.
2020-09-03 10:50:17 -07:00