Commit graph

19776 commits

Author SHA1 Message Date
Johannes Altmanninger
abaeb4af2a scrollback-push to sanitize cursor position
I believe it's possible that the cursor position reported by the
terminal does not match fish's cursor.  In that case, overflow. Fix
that since we should not trust the terminal.

Also rename a confusingly named variable.

Mouse-click handling has a similar issue, fix that too.

FWIW, tmux always reports cursor position zero (\x1b[1;1R) when
querying from fish (but not when querying with printf).
Will investigate that next, see the linked issue.

Fixes #10992
2025-01-03 07:55:50 +01:00
David Adam
670541eec8 fish_jj_prompt: don't error if jj not installed 2025-01-03 12:38:14 +08:00
Johannes Altmanninger
0debddc9e5 Add a simple fish_jj_prompt
jj is often colocated with Git so the Git prompt also works, but
jj is always in a detached HEAD state, which is atypical for Git.
The jj prompt improves things by showing the revision ID which is
usually more useful than the commit ID.

This prompt is mostly adapted from the defaults for "jj log -r @".

Showing conflicting/empty commits seems useful.
Also perhaps bookmarks and tags, not sure.

The main problem with this prompt is that due to --ignore-working-copy,
the information may be stale.  That will be rectified after every jj
command, so hopefully this doesn't cause issues.
2025-01-03 00:03:58 +01:00
Erick Howard
837c32f150 Move getrusage wrapper in timer.rs to shared nix wrapper module
Closes #10988
2025-01-02 23:40:41 +01:00
Alexei Mikhailov
9b26fff278 completions/exercism: use generate script
Exercism ships with it's own completions and a generation script, so let's use
that one instead.
2025-01-02 21:57:17 +08:00
Klaus Hipp
2b46d97c68 Update code completions 2025-01-02 14:11:24 +08:00
David Adam
65ced4e2bb Cargo.lock: update downstream dependencies 2025-01-02 13:20:15 +08:00
David Adam
3710142d1d Cargo.lock: update errno 2025-01-02 13:18:54 +08:00
David Adam
0c9c5e3a34 Cargo.toml/lock: upgrade serial_test
Slims the dependency tree down a bit; no breaking changes affect fish.
2025-01-02 13:09:54 +08:00
David Adam
53912777af Cargo.lock: upgrade cc 2025-01-02 12:38:50 +08:00
David Adam
70bd49f612 drop confstr implementation
Added in libc 0.2.163.

The constants for _CS_PATH are not implemented for some of the BSDs yet
(rust-lang/cmake#3612), so we need to keep our linking of this via the C
compiler for now.
2025-01-02 11:06:29 +08:00
David Adam
6714818e5d Cargo.toml: update libc 2025-01-02 10:44:23 +08:00
Peter Ammon
7e9b35be48
Fix a clippy 2025-01-01 17:42:25 -08:00
Peter Ammon
7af9844de0
highlight: make PathFlags an ordinary struct
No need for fancy bitflags.
2025-01-01 17:42:14 -08:00
tranzystorekk
3129c9e939 environment_impl: drop usage of lazy_static 2025-01-01 12:23:24 -08:00
Erick Howard
967c4b2272
Code cleanup in src/bin/fish.rs to make it more idiomatic (#10975)
Code cleanup in `src/bin/fish.rs` to make it more idiomatic
2025-01-01 12:17:48 -06:00
Johannes Altmanninger
1c4e5cadf2 Autosuggestions in multi-line command lines
If I run

	$ command A
	$ command B
	$ command C

and find myself wanting to re-run the same sequence of commands
multiple times, I like to join them into a single command:

	$ command A &&
	    command B &&
	    command C

When composing this mega-commandline, history search can recall the
first one; the others I usually inserted with a combination of ctrl-k,
ctrl-x or the ctrl-r (since 232483d89a (History pager to only operate
on the line at cursor, 2024-03-22), which is motivated by exactly
this use case).

It's irritating that autosuggestions are missing, so try adding them.

Today, only single-line commands from history are suggested. In
future, we should perhaps also suggest any line from a multi-line
command from history.
2025-01-01 17:22:50 +01:00
Johannes Altmanninger
532abaddae Invalidate stale autosuggestions eagerly
If I type something that invalidates the autosuggestion, the
autosuggestion is still kept around in memory. This is used if
1. there is no valid autosuggestion for the new commandline
2. the user types something like "backspace backspace a"
   that both makes the cached autosuggestion valid again, and does
   not trigger autosuggestion suppression (hence backspace alone is
   not anough)

The fact that an autosuggestion might not match the current command
line makes it more difficult to implement autosuggestions on multiline
command lines.

For now let's invalidate autosuggestions eagerly, to enable the
next commit.  This heuristic invalidates too much but I don't think
that matters. We'll simply recompute the autosuggestion in those few
cases which.
2025-01-01 17:22:50 +01:00
Johannes Altmanninger
7049352e61 Extract function for potentially case-insensitive prefix check 2025-01-01 17:22:50 +01:00
Fabian Boehm
a4f4ae76cb staticbuilds: Run tests 2025-01-01 16:45:56 +01:00
Fabian Boehm
c3de539d46 test_driver: Error out if $FISHDIR isn't given
This avoids confusion when you forget to set it and run it on the
wrong fish.
2025-01-01 16:45:43 +01:00
Fabian Boehm
7bb38355e8 test_driver: Some more errors 2025-01-01 16:45:43 +01:00
Fabian Boehm
5520ee3c65 Document 2025-01-01 16:45:43 +01:00
Fabian Boehm
e66f6878b5 Make tests usable with path with spaces
This is somewhat subtle:

The #RUN line in a littlecheck file will be run by a posix shell,
which means the substitutions will also be mangled by it.

Now, we *have* shell-quoted them, but unfortunately what we need is to
quote them for inside a pre-existing layer of quotes, e.g.

    # RUN: fish -C 'set -g fish %fish'

here, %fish can't be replaced with `'path with spaces/fish'`, because
that ends up as

    # RUN: fish -C 'set -g fish 'path with spaces/fish''

which is just broken.

So instead, we pass it as a variable to that fish:

    # RUN: fish=%fish fish...

In addition, we need to not mangle the arguments in our test_driver.

For that, because we insist on posix shell, which has only one array,
and we source a file, we *need* to stop having that file use
arguments.

Which is okay - test_env.sh could previously be used to start a test,
and now it no longer can because that is test_*driver*.sh's job.

For the interactive tests, it's slightly different:

pexpect.spawn(foo) is sensitive to shell metacharacters like space.

So we shell-quote it.

But if you pass any args to pexpect.spawn, it no longer uses a shell,
and so we cannot shell-quote it.

There could be a better way to fix this?
2025-01-01 16:45:43 +01:00
Fabian Boehm
e9b9ee8d63 Fix docs if binary dir has a space
For some reason this is double-quoted if we quote this.
2025-01-01 16:45:43 +01:00
Fabian Boehm
17d57b70d0 littlecheck: Update to shell-quote replacements
Commit bb07435e3e4cbd34fcb667ec927353d176a0b2e8
2025-01-01 16:45:43 +01:00
Fabian Boehm
cb3d004a5a tests: Run filter-ctrl with %fish explicitly 2025-01-01 16:45:43 +01:00
Fabian Boehm
5e10d75a19 Tests: Don't cd to the tests directory!
We:

1. Set up a nice TMPDIR for our tests to use
2. Immediately `cd` to the directory containing the test runner.

So instead we don't do (2), and stay in the temp directory, and
explicitly use all the things from the test runner directory.

I am fairly certain that cmake papered over this by adding a second
layer of temp dir.
2025-01-01 16:45:43 +01:00
Fabian Boehm
050fe09af1 Compile fish_test_helper in the test driver 2025-01-01 16:45:43 +01:00
Fabian Boehm
b531cc8b43 tests: Specifically #require fish_test_helper when needed 2025-01-01 16:45:43 +01:00
Fabian Boehm
63e705a778 Let tests find fish and associated binaries via $FISHDIR
The default is still "../test/root/bin/", but we now pass this
through,
so you *can* run

`FISHDIR=$PWD ../tests/test_driver.sh $PWD/../tests/test.fish`
2025-01-01 16:45:43 +01:00
Fabian Boehm
1df8de06c1 Move littlecheck/pexpect to tests
This removes the need for a bunch of setup, and makes it easier to
make the tests agnostic to our test root setup.
2025-01-01 16:45:43 +01:00
Erick Howard
943adf4dd0 Avoid traversing wait handle list if searching by PID 2025-01-01 16:40:53 +01:00
Erick Howard
53dc7772eb Remove unnecessary clone when opening File for debug output 2025-01-01 16:34:40 +01:00
Hong Xu
64ed47bf4e
Update .editorconfig to use "unset" instead of "off" (#10972)
This is inline with the [EditorConfig spec](https://spec.editorconfig.org/). The [EditorConfig Wiki](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length) was outdated and misleading, but have updated now.
2024-12-31 15:04:37 -06:00
Fabian Boehm
6848e70e87 Disable two tests on NetBSD
One doesn't compile, the other's just borked for weird reasons
possibly related to tmux and $LINES?

With this, the test suite passes on NetBSD.
2024-12-31 13:04:28 +01:00
Fabian Boehm
d5efef1cc5 __fish_complete_subcommand: Just complete -C for a given commandline
Fixes #10980.

This would, if a commandline was given, still revert to checking
the *real* commandline if it was empty.

Unfortunately, in those cases, it could have found a command and tried
to complete it.

If a commandline is given, that is what needs to be completed.

(note this means this is basically useless in completions that use it
like `sudo` and could just be replaced with `complete -C"$commandline"`)
2024-12-30 21:01:21 +01:00
Fabian Boehm
e715c3e3ff help: Add special error for $BROWSER/$fish_help_browser being wrong 2024-12-30 21:01:21 +01:00
Johannes Altmanninger
13763fa318 Fix assertion error in when scrollback-push is enqueued from script
As soon as we start processing a scrollback-push readline command, we
pause execution of all other readline commands until scrollback-push
retires.  This means that we never get into a situation with two
active scrollback-push commands -- unless we are executing readline
commands via a script running "commandline -f":
since the first part of scrollback-push handling returns immediately,
the script will proceed before scrollback-push retires.

A second scrollback-push fails an assertion.  Work around that for now.
In future, scrollback-push should block when invoked by such a script,
just like it does when invoked from bindings.
2024-12-30 14:20:05 +01:00
Johannes Altmanninger
8910390602 Work around broken macOS CI seemingly missing parm_index in terminfo
Commit 83b0294fc9 (ctrl-l to scroll content instead of erasing screen,
2024-12-21) broke tests like tests/checks/tmux-autosuggestion.fish
on macOS CI.

I didn't get to the bottom of this but it's probably because terminfo
is broken on that CI system.

A (related?) failure mode can be observed using

	TERM=linux-m ssh my-mac tmux

ctrl-l moves the cursor but fails to scroll the text.

The only reason for using terminfo here was to be consistent with
the rest of the code base.  Let's use a hardcoded value instead;
I don't see why any terminal would deviate from xterm here.

This fixes macOS CI and the TERM=linux-m "misconfiguration".

It is possible that we should be using a different escape sequence
here; I'm not sure.
2024-12-30 14:20:05 +01:00
Johannes Altmanninger
b6c2a4c5db Remove trivial splice() call 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
a88de9d345 Remove unused data from autosuggestion cache 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
e8801d2ced Minor refactoring to reuse autosuggestion contructor 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
1d620356f8 Deduplicate command line update step when accepting autosuggestions 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8bb6597b9b Deduplicate layout computation logic 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8ae12973df Try to simplify commandline change hooks 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
459fc3c887 Fix failing history pager search replacing all lines
History pager search operates only on the current line, so a failing
search should only replace the current line with the search string.
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
a719f9d537 Minor refactoring in handle_execute
A failing ctrl-r search term is inserted back into the command line.
This should go through the same code path as other editions.
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
da0a93b24b Minor optimization in pager_selection_changed 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8bb442f135 Minor cleanup in push_edit 2024-12-30 10:50:38 +01:00