Commit Graph

19860 Commits

Author SHA1 Message Date
Fabian Boehm
6126237bc4 Remove awkward assert
We should really stop asserting for things that at worst don't show an
autosuggestion.

Fixes #11055
2025-01-16 13:03:11 +01:00
Johannes Altmanninger
0cc7ee5511 Fix regression causing crash on unconsumed }
Fixes #11052
2025-01-16 04:40:21 +01:00
David Adam
dd2b9943a7 make_tarball: generate debug binaries
The extended build time isn't worth it for an executable which is run once then thrown away.
2025-01-15 23:29:42 +08:00
David Adam
d6e001ac7e fix tests for 24abbb6de7 2025-01-15 23:28:08 +08:00
David Adam
24abbb6de7 feature_flags: update target release for 3.8 flags to 4.0 2025-01-15 22:11:28 +08:00
Johannes Altmanninger
1bf2b43d30 Allow { } for command grouping, like begin / end
For compound commands we already have begin/end but

> it is long, which it is not convenient for the command line
> it is different than {} which shell users have been using for >50 years

The difference from {} can break muscle memory and add extra steps
when I'm trying to write simple commands that work in any shell.

Fix that by embracing the traditional style too.

---

Since { and } have always been special syntax in fish, we can also
allow

	{ }
	{ echo }

which I find intuitive even without having used a shell that supports
this (like zsh. The downside is that this doesn't work in some other
shells.  The upside is in aesthetics and convenience (this is for
interactive use). Not completely sure about this.

---

This implementation adds a hack to the tokenizer: '{' is usually a
brace expansion. Make it compound command when in command position
(not something the tokenizer would normally know). We need to disable
this when parsing a freestanding argument lists (in "complete somecmd
-a "{true,false}").  It's not really clear what "read -t" should do.
For now, keep the existing behavior (don't parse compound statements).

Add another hack to increase backwards compatibility: parse something
like "{ foo }" as brace statement only if it has a space after
the opening brace.  This style is less likely to be used for brace
expansion. Perhaps we can change this in future (I'll make a PR).

Use separate terminal token types for braces; we could make the
left brace an ordinary string token but since string tokens undergo
unescaping during expansion etc., every such place would need to know
whether it's dealing with a command or an argument.  Certainly possible
but it seems simpler (especially for tab-completions) to strip braces
in the parser.  We could change this.

---

In future we could allow the following alternative syntax (which is
invalid today).

	if true {
	}
	if true; {
	}

Closes #10895
Closes #10898
2025-01-15 11:18:46 +01:00
Johannes Altmanninger
349f62cd7c Sort enum-like AST nodes 2025-01-15 10:54:50 +01:00
Johannes Altmanninger
10dd8a8e73 Add range to closing-unopened brace error
The error on "echo }" is needlessly inconsistent with "echo )" and
"echo (}" etc; fix that I guess.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
3a6e87744b Minor formatting fixes 2025-01-15 10:54:18 +01:00
Johannes Altmanninger
67ccbdae96 Refine errors on "begin; case"
This will also give better errors for unbalanced braces (which are
sigils for begin/end), see a following commit.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
debfdf0a39 Fix inconsistent error message on quoted keyword
Commit bdfbdaafcc (Forbid subcommand keywords in variables-as-commands
(#10249), 2024-02-06) banned "set x command; $x foo" because the
parser will not recognize "$x" as decorator.
That means that we would execute only the builtin stub,
which usually exist only for the --help argument.

This scenario does not apply for keywords that are quoted or contain
line continuations. We should not treat «"command"» differently
from «command».  Fix this inconsistency to reduce confusion.
2025-01-15 10:54:18 +01:00
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