Commit Graph

19949 Commits

Author SHA1 Message Date
Johannes Altmanninger
6d18f57e96 Make ! a builtin too, fixing "! -h"
UnLike other aliases (":.["), ! is special in the grammar but in the
few cases like "! -h" where we parse it as decorated statement they
are equals. Add it to the built in list, so the help argument works.

It can still be overridden, so this should not break anything.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
373bb56441 Treat '!' as super-command (it's not reserved!)
Other sigil-aliases ('[' and '_') are reserved words that cannot be
redefined as function. Only '!' is not.

Whereas several users define "function !!", I
found only one public occurrence of "function !":
5c7f87ed07/fish/functions/!.fish

Note that "function !" only works if invoked as "!", "! -h" or
"! --help" or "foo | !".  In most other cases we parse it as negation.

We should probably make it a reserved word to reduce confusion.
If we do that, we should also add it to __fish_print_help, to make
"! -h" work.

For now let's rearrange the code so we can recognize "!" as
super-command. This fixes completion-based autosuggestions on "! ".
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
e678fb8578 Fix autosuggestions on quoted subcommand keyword
The commandline "and fis" rightly gets command autosuggestions whereas
"'and' fis" wrongly gets file autosuggestions.  The former works via
a hack. Extend it to quoted keywords.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
80a6ece45b Make newline after "else" optional
This makes it consistent with "else if", and with other shells.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
f5b2928cbb Refactor subcommand keyword detection
This file has bitrotted; for example commit bc66921ac9 (Optimize
keyword detection, 2019-04-03) removed use of SKIP_KEYWORDS but
confusingly it's still around (even after 0118eafee1 (Remove unused
functions, members (and a variable), 2022-04-09).

Also some keywords appear in multiple lists; the separate lists are
not really used today; there is a comment stating they may be useful
in future.

It would be great to add an optimization back but either way we should
present the set of reserved words in source code as a contiguous list,
to make it easy for humans to see all relevant information.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
c7adb572d0 Address clippy lints 2025-01-15 10:53:09 +01:00
Johannes Altmanninger
de6c4f85bc Don't put every enum-like AST nodes in a box
StatementVariant needs an indirection because for example NotStatement
may contain another whole statement (error[E0072]: recursive type
has infinite size).

This is dealt with by putting each StatementVariant in a Box.
This Box was also used by the AST walk implementation to implement
tagged dispatched for all variant AST nodes (see "visit_union_field").
Because of this, all other variant AST are boxed the same way, even
though they may not by cyclic themselves.

Reduce confusion by boxing only around the nodes that are actually
recursive types, and use a different tag for static dispatch.
This means that simple nodes like most normal commands and arguments
need one fewer allocation.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
9fd1fd366c Remove stale todo comment
This has been fixed.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
24a32d5202 Fix format string for internal parser error 2025-01-15 10:53:09 +01:00
Johannes Altmanninger
3695c349c6 Note "Restore autosuggestion after corrected typo" in changelog
Seems easy enough to explain, and somewhat noticeable. Let's see if
it causes problems.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
40f5aac764 Fix forward-token hiccup at operators
For better or worse, backward-token completely skips over operators
like > & |.
forward-token is (accidentally?) inconsistent with that. Fix that.

Skipping over those tokens might be wrong weird.  Maybe not for
redirections since they are tighly coupled to their target.  Maybe we
can improve this in future.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
674b7b6f92 Reject commandline --search-field --tokens*
As of today, it makes no sense to tokenize the search field.
We already reject arguments like --current-process.
Extend that to the --tokens family.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
6f480d1d85 Also trim trailing newlines when adding to history
When pasting and executing a full line, the trailing newline character
will be included in history.

I usually manually delete the newline before executing, but sometimes
I forget. When I recall my (typically single-line) commands, it's
surprising that the cursor is on the blank second line.

The newline doesn't seem useful. Let's remove it automagically.
I wonder if anyone will be thrown off by this smart behavior.

In future, we can make this space trimming configurable, similar to
fish_should_add_to_history.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
081c3282b7 Refresh TTY timestamps also in some rare cases
As mentioned in
https://github.com/fish-shell/fish-shell/pull/11045#discussion_r1915994998,
we need to refresh TTY timestamps to avoid timing-based issues.

For some context see

	git log --grep='[Rr]efresh.* TTY'

Make things more consistent again. I don't know if all of these are
absolutely necessary, hoping to find out later (and consolidate this
logic in outputter).
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
2e025cfd76 Sort match statement 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
4e29dba1d5 Minimize logic 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
c4b4e90031 Fix file completions for builtin fish_indent 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
c12f853db2 Reformat share/{completions,functions} 2025-01-15 10:50:04 +01:00
kerty
f139d8ebed Improve mouse support
Some checks failed
make test / ubuntu (push) Has been cancelled
make test / ubuntu-32bit-static-pcre2 (push) Has been cancelled
make test / ubuntu-asan (push) Has been cancelled
make test / macos (push) Has been cancelled
Rust checks / rustfmt (push) Has been cancelled
Rust checks / clippy (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
2025-01-15 00:52:15 +01:00
kerty
a0e687965e Fix unsaved screen modification 2025-01-15 00:52:15 +01:00
kerty
644c3a87e3 Refactor mtime_stdout and mtime_stderr into mtime_stdout_stderr 2025-01-15 00:52:15 +01:00
kerty
153300f6d1 Fix incorrect line count calculation 2025-01-15 00:52:15 +01:00
Fabian Boehm
2508cc9de6 Disable some more tests under CI
tmux-commandline can fail with

```
prompt 4>     commandline -i "echo $(printf %0"$COLUMNS"d)"
```

And I just can't even.

job_summary is annoyingly tight.

Also count cancel_event as a *skip*, not success.
2025-01-14 20:31:48 +01:00
Fabian Boehm
28233b0711 Make new ctrl-c behavior "clear-commandline"
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
And leave the old behavior under the name "cancel-commandline".

This renames "cancel-commandline-traditional" back to
"cancel-commandline", so the old name triggers the old behavior.

Fixes #10935
2025-01-14 20:01:56 +01:00
Fabian Boehm
021b18335c cmake/Tests: Default to half the cores
Saturating all cores easily leads to timeouts.

The system might be doing something else, and it only leaves at most
one core per-test.

E.g. this will cause 90% of runs to fail on a raspberry pi 4.

Note that we set CTEST_PARALLEL_LEVEL on our CI machines anyway, so
this will not affect them.
2025-01-14 17:55:09 +01:00
Fabian Boehm
23f218eb8e pexpects/bind_mode_events: Increase a timeout 2025-01-14 17:55:09 +01:00
Fabian Boehm
d32257c2d5 pexpects/wait: wait on the same line as the background jobs
The issue here is we start some short `sleep`s in the background, wait
for a prompt, and only *then* wait for jobs, and *then* check for the
job end output.

That means if the prompt takes too long, we'll read the job end
messages with the `expect_prompt`.

Instead of increasing the timeouts, just wait on the same line and
remove that prompt.
2025-01-14 16:19:07 +01:00
Fabian Boehm
37a1611b54 tests/pexpects/history: Remove a weird match
Bit of a shot in the dark, I've seen this fail and there's no real
need to match the prompt *and* the command you just ran.

(plus wc -l | string trim is unnecessary when we have count)
2025-01-14 10:57:22 +01:00
Johannes Altmanninger
24e216ae82 Fix regression causing missing autosuggestions after (
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Commit 4f3d6427ce (Fix regression causing crash in "commandline -j",
2025-01-12) wasn't quite right; it mishandles the edge case where
the current process has no token, fix that.
2025-01-13 22:22:42 +01:00
Johannes Altmanninger
c77c35152d Work around old Zellij by parsing unsolicited DECRQM
Zellij 0.41.2 has a bug where it responds to

	 printf '\x1b[?2026$p'; cat -v

with '^[[2026;2$y' (DECRQM) instead of '^[[?2026;2$y' (DECRPM).

This is fixed by https://github.com/zellij-org/zellij/pull/3884

We fail to parse it, leading to an extra y added to the input queue.
Since it seems easy to work around for us, let's do that, I guess.
2025-01-13 21:58:21 +01:00
Fabian Boehm
cbbf95ee55 tests: Increase another timeout
Some checks are pending
make test / macos (push) Waiting to run
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Failed on Cirrus Alpine.

The only explanation I can come up with here is that this took over
100ms to start `true | sleep 6`.

The alternative is that it started it and then did not regain control
in 6 seconds to kill that sleep.

Part of #11036
2025-01-13 15:17:16 +01:00
Fabian Boehm
723943fd1f fish_jj_prompt: Return false if nothing was generated
That means we go on to try git etc
2025-01-13 14:54:00 +01:00
Johannes Altmanninger
b6c249be0c Back out "Escape : and = in file completions"
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
If you don't care about file paths containing '=' or ':', you can
stop reading now.

In tokens like

	env var=/some/path
	PATH=/bin:/usr/local/b

file completion starts after the last separator (#2178).

Commit db365b5ef8 (Do not treat \: or \= as file completion anchor,
2024-04-19) allowed to override this behavior by escaping separators,
matching Bash.

Commit e97a4fab71 (Escape : and = in file completions, 2024-04-19)
adds this escaping automatically (also matching Bash).

The automatic escaping can be jarring and confusing, because separators
have basically no special meaning in the tokenizer; the escaping is
purely a hint to the completion engine, and often unnecessary.

For "/path/to/some:file", we compute completions for "file" and for
"/path/to/some:file".  Usually the former already matches nothing,
meaning that escaping isn't necessary.

e97a4fab71 refers us to f7dac82ed6 (Escape separators (colon and
equals) to improve completion, 2019-08-23) for the original motivation:

	$ ls /sys/bus/acpi/devices/d<tab>
	$ ls /sys/bus/acpi/devices/device:
	device:00/ device:0a/ …

Before automatic escaping, this scenario would suggest all files from
$PWD in addition to the expected completions shown above.

Since this seems to be mainly about the case where the suffix after
the separator is empty, 

Let's remove the automatic escaping and add a heuristic to skip suffix
completions if:
1. the suffix is empty, to specifically address the above case.
2. the whole token completes to at least one appending completion.
   This makes sure that "git log -- :!:" still gets completions.
   (Not sure about the appending requirement)

This heuristic is probably too conservative; we can relax it later
should we hit this again.

Since this reverts most of e97a4fab71, we address the code clone
pointed out in 421ce13be6 (Fix replacing completions spuriously quoting
~, 2024-12-06). Note that e97a4fab71 quietly fixed completions for
variable overrides with brackets.

	a=bracket[

But it did so in a pretty intrusive way, forcing a lot of completions
to become replacing. Let's move this logic to a more appropriate place.

---

Additionally, we could sort every whole-token completion before every
suffix-completion.  That would probably improve the situation further,
but by itself it wouldn't address the immediate issue.

Closes #11027
2025-01-13 09:50:13 +01:00
Johannes Altmanninger
0cfc95993a Swap code blocks for completing separator suffix resp. whole token
Mainly to make the next commit's diff smaller. Not much functional
change: since file completions never have the DONT_SORT flag set,
these results will be sorted, and there are no data dependencies --
unless we're overflowing the max number of completions.  But in that
case the whole-token completions seem more important anyway.
2025-01-13 09:50:13 +01:00
Johannes Altmanninger
b46417c77b Fix broken completions for "mount -ouid="
Regressed in 2e55e34544 (Reformat, 2020-11-22).
2025-01-13 09:47:34 +01:00
Johannes Altmanninger
33d92d2a1f ctrl-u to suppress autosuggestion
ctrl-w and {ctrl,alt}-backspace do the same.
2025-01-13 09:47:34 +01:00
Johannes Altmanninger
0f4e195819 fish_jj_prompt: remove change ID
This is not really helpful because it's somewhat transient; also we
can usually use the @ alias.
2025-01-13 09:47:34 +01:00
Peter Ammon
9785824794
Factor file testing out of highlighting
Some checks failed
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Lock threads / lock (push) Has been cancelled
Syntax highlighting wants to underline arguments that are files, and in other
cases do disk I/O (such as testing if a command is valid). Factor out this I/O
logic to untangle highlighting, and add some tests. No functional change
expected.
2025-01-12 15:10:11 -08:00
Johannes Altmanninger
4f3d6427ce Fix regression causing crash in "commandline -j"
Commit 3fcc6482cb (Fix parse_util_process_extent including too much
on the left, 2024-12-24) changed the process extent based on the
observation that "A\n\n\nB" comprises three tokens with ranges 0..1,
1..2 and 4..5. Prior to that commit, the second process extent was
2..5, which seems a bit weird because it includes newlines.

Weirdness aside, the real reason for changing it was this snippet in
the autosuggestion performer, where we compute the process extent
around cursor, and check if the line at process start matches the
cached search string.

        // Search history for a matching item unless this line is not a continuation line or quoted.
        if range_of_line_at_cursor(
            &command_line,
            parse_util_process_extent(&command_line, cursor_pos, None).start,
        ) == search_string_range

Given "A\n\n\nB" and cursor_pos=1 commit 3fcc6482cb changed the output
from 2..5 to 4..5. This brings problems:
1. leading spaces will not be included (which is probably
   inconsequential but still ugly).
2. the specified cursor position is not included in the given range.

We could paper over 2 by computing min(cursor_pos)
but that would leave 1.

For now let's revert and solve the autosuggestion issue in a less
brittle way.
2025-01-12 19:55:17 +01:00
Fabian Boehm
a1b7c36db5 cmake: Explicitly have tests depend on indent and key_reader
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
2025-01-12 18:05:50 +01:00
Fabian Boehm
f0eb599ff1 cmake: Remove some more dead gunk
We no longer check for in tree builds anywhere (tests set up their own
tmpdir),
and we no longer support xcode.
2025-01-12 17:52:59 +01:00
Fabian Boehm
7b30745800 cmake: Stop setting up temporary test directory
We already set up a temporary directory for each test in the
test_driver,
so let's stop doing that here.

It took a weirdly long time anyway.
2025-01-12 17:44:31 +01:00
Fabian Boehm
afb1cc21b6 Compile fish_test_helper in CMake again
That means we don't have to recompile it for every test
2025-01-12 17:40:46 +01:00
Fabian Boehm
aa77892be4 fish_indent: Read from stdin, take two
This needs to work both in builtin and command mode.

We should probably clarify how we're passing FDs around, and I suspect
we may close fds in places we don't expect.
2025-01-12 16:17:49 +01:00
David Adam
54fef433e9 Debian packaging: update dependencies
Ubuntu Focal calls the package with col "bsdmainutils", which is a
transitional package on newer version of both Debian and Ubuntu.

Closes #11037.
2025-01-12 21:19:59 +08:00
Fabian Boehm
b2fe405365 Revert "fish_indent: Correctly read from builtin stdin"
Using Arguments here breaks the `command fish_indent` case.

Probably needs to directly use a BufReader.

This reverts commit ab1b6bcea5.
2025-01-12 13:43:51 +01:00
Fabian Boehm
ab1b6bcea5 fish_indent: Correctly read from builtin stdin
This still used read_file, but we don't *really* have an fd if we're
connected to another builtin.
2025-01-12 13:15:39 +01:00
David Adam
1b0c53e30e .gitattributes: fixup e4674cd7
Some checks are pending
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Actually set the attribute on the file 🤦 and also exclude the
directory.
2025-01-12 11:32:34 +08:00
David Adam
44555de69a update .gitattributes
Reflect the current state of the codebase
2025-01-12 10:46:34 +08:00
David Adam
e4674cd7b5 .cargo/config.toml: exclude from tarball
Various commits have added bits to .cargo/config.toml. Unfortunately,
this file needs to be changed by the Linux package builds (debuild, RPM,
OBS etc) with the results of `cargo vendor`, to support building in
isolated environments.

These environments - especially Debian's dpkg-buildpackage/debuild - do
not make it easy to alter a file which already exists in the tarball in
an automatic way. dpkg-buildpackage in particular requires all changes
to be made in the form of patches.

Just exclude .cargo/config.toml from the tarballs for now. This means
that the stanzas it includes _will not apply_ to builds made from
tarballs, which includes releases and development builds made using the
OBS/Launchpad PPAs.
2025-01-12 10:34:16 +08:00