Commit graph

19747 commits

Author SHA1 Message Date
Johannes Altmanninger
dda4371679 Stop sending CSI 5n when querying for kitty keyboard support
After we query kitty keyboard protocol support,
we send CSI 5n, to also receive a response if
the protocol is not supported.

However we don't bother to wait for the response, so this extra
message is not really useful (only to get better logs).  Remove it.
2025-01-06 05:51:38 +01:00
Johannes Altmanninger
10f1f21a4f Don't send kitty kbd protocol probe until ECHO is disabled
With tmux 3.0 (from 2019) inside SSH, the CSI 5n response is echoed.
I guess with all other terminals we were just lucky.  Move it to
right after where we disable ECHO I guess.

In general, asynchronous requests create a lot of potential for error,
we should try to get away from them.
2025-01-06 05:51:38 +01:00
Johannes Altmanninger
109ef88831 Add menu and printscreen keys
These aren't typically used in the terminal but they are present on
many keyboards.

Also reorganize the named key constants a bit.  Between F500 and
ENCODE_DIRECT_BASE (F600) we have space for 256 named keys.
2025-01-06 05:43:22 +01:00
Lzu Tao
f9b79926f1 Add more convenient key bindings for VI mode
To make it more familiar to vi/vim users.

In all mode, ctrl-k is bind to kill-line.

In Vi visual mode:
* press v or i turn into normal or insert mode respectively.
* press I turn to insert mode and move the cursor to beginning of line.
* because fish doesn't have upcase/locase-selection, and most people reach for
  g-U rather than g-u, g-U binds to togglecase-selection temporarily.
2025-01-05 23:00:21 +08:00
David Adam
6c3150aa05 docs/interactive: update key bindings added for 4.0 2025-01-05 22:27:00 +08:00
Johannes Altmanninger
07dd088d76 Bind ctrl-l to clear-screen again for now
Testing has revealed some problems on BSD and Windows terminals and
the Linux Console, let's revert to the old implementation until these
are fixed.  Leaving the changelog entry for now since it shouldn't
take long.

See #11003
2025-01-05 08:20:53 +01:00
Johannes Altmanninger
93e0a33d41 Log human-readable values also for not-yet-decoded bytes 2025-01-05 03:37:31 +01:00
Stefan Boca
dcddffd222
refactor: misc cleanup (#10998)
* refactor EnvVar: Arc<Box<[WString]>> -> Arc<[WString]>

* remove unnecessary `&mut` from EnvVar methods

* clippy: use eq_ignore_ascii_case instead of manual comparison

see https://rust-lang.github.io/rust-clippy/master/index.html#manual_ignore_case_cmp

* clippy: use `is_some_and` and `is_ok_and` instead of `map_or`

see https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or

* clippy: use `assert!()` instead of `assert_eq!()` with booleans
2025-01-04 19:49:44 -06:00
cornmander
d842a6560e
Add completions for Google Cloud commands. (#11005)
The `gcloud` and `gsutil` Google Cloud commands use argcomplete, so integrating them is easy with the `__fish_argcomplete_complete` function.
2025-01-04 19:45:05 -06:00
Mahmoud Al-Qudsi
b4e8cc8b79 Use explicit Timeout enum instead of magic constants
The FdReadableSet api was always intended to be converted to use Duration
instead of usec/msec once the ffi was removed. This lets us be explicit about
forever/infinite timeouts and removes the (small) chance of a collision between
u64::MAX and INFINITE.

I tried this out with `type Timeout = Option<Duration>` (only without the alias)
but was unhappy with easy it is to accidentally use `None` when you meant a
timeout of zero.
2025-01-04 18:40:36 -06:00
Mahmoud Al-Qudsi
83eb25d45f Mark function as test-only 2025-01-04 17:29:09 -06:00
Lzu Tao
7eb254f2ba Add completion for gem-fetch 2025-01-04 21:26:03 +08:00
idealseal
2e12a2b6c4 feat(comp): Update completions for resolvectl 2025-01-04 20:42:31 +08:00
idealseal
a780e4da15 feat(comp): Update completion for md5sum 2025-01-04 20:39:33 +08:00
Thayne McCombs
33dd823f45 fix[completions]: Add set-timeout to bootctl 2025-01-04 20:15:53 +08:00
Johannes Altmanninger
e11e62674f Fix bad layout computation with right prompt
Commit 1c4e5cadf2 (Autosuggestions in multi-line
command lines, 2024-12-15) accidentally passed an empty
"commandline_before_suggestion" to compute_layout() when there is
no autosuggestion.

Closes #10996
2025-01-04 00:54:06 +01:00
Johannes Altmanninger
e49dde87cc Probe for kitty keyboard protocol support
We unconditionally request kitty keyboard protocol's progressive
enhancements.

It seems that a lot of terminals fail to parse CSI commands that
contain '=' such as \x1b[=5u.

1. [Midnight Commander](0ea77d2ec7)
2. Prompt 3 App (private bug tracker)
3. JetBrains IDEs https://youtrack.jetbrains.com/issue/IJPL-166234
4. Termux https://github.com/termux/termux-app/issues/4338
5. Amazon Linux Web Console https://github.com/amazonlinux/amazon-linux-2023/issues/871

It is difficult to fix the four remaining ones in a
timely manner, so let's query for support as described in
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#detection-of-support-for-this-protocol
This uses CSI 5 n (device status report), which is the older brother
of CSI 6 n (cursor position report) we use as of recently.

Query asynchronously and enable progressive enhancements as soon
as we get a response. In theory this allow `cat malicious-file.txt`
leading us to believe the protocol is supported.

See #10994
2025-01-03 23:20:19 +01:00
Fabian Boehm
edfdf210c4 Remove unnecessary use of errno 2025-01-03 19:34:57 +01:00
Johannes Altmanninger
996fec87f4 Demote logs about unexpected cursor position
As reported in
https://github.com/fish-shell/fish-shell/issues/10992#issuecomment-2568954940,
the user may reset the terminal and run scrollback-push without
repainting in between.  This means that the terminal will report
the cursor position y=0 x=0 which doesn't match what fish renders.
Fortunately, y=0 is a safe fallback value for the scrollback-push
use case.

While at it, fix an off-by-one error in a log.
2025-01-03 12:57:00 +01:00
Johannes Altmanninger
870a8f77a0 completions/scp: replace version detection
Version detection seems unreliable (see
https://github.com/fish-shell/fish-shell/issues/10445#issuecomment-2566232705
) so let's test for the actual feature.  On modern versions,"scp -O"
means "Use  the legacy SCP protocol for file transfers instead",
so presence of this feature indicates we are good.
2025-01-03 12:57:00 +01:00
Johannes Altmanninger
d823444c6e Apply autosuggestions from completions also if cursor is not at EOL
Before 1c4e5cadf2 (Autosuggestions in multi-line command lines,
2024-12-15), the completion code path in the autosuggestion performer
used to do something weird: it used to request completions for the
entire command line (with the implied cursor at end) but try to apply
the same completion at the actual cursor.

That commit changed this to request completions only up to the cursor
position, which could in theory make us produce valid completions even
if the cursor is not at end of the line.  However, that doesn't really
work since autosuggestions can only be rendered at the end of the line.
And the worst of it, that commit tries to compute

	line_at_cursor(&full_line, search_string_range.end)

which crashes as out-of-bounds if the completion needs to replace the token
(like a case-correcting completion does).

Let's apply completions to the end, matching how autosuggestions work
in general.
2025-01-03 12:56:04 +01:00
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