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)
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`.
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.
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.
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.
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
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.
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.
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.
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.
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
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.
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]
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.
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
```
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.
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.