Commit Graph

18743 Commits

Author SHA1 Message Date
Fabian Boehm
eb2ccc4ea9 Reword CHANGELOG a bit
Try to keep the "backwards-incompatible" section reasonably short so
people can get a quick overview of what they need to handle.

So we split the "bind" part into two.
2024-04-21 16:49:29 +02:00
Nguyen Huu Kim
891b0a74fd Update helm completions ignore stderr 2024-04-21 14:39:49 +02:00
Nguyen Huu Kim
2e61ce5540 Replace minikube completions with autogenerated script 2024-04-21 14:39:49 +02:00
Nguyen Huu Kim
00f661d8e8 add devspace completions 2024-04-21 14:39:49 +02:00
Fabian Boehm
3584ffcb52 CHANGELOG 2024-04-21 14:35:13 +02:00
Fabian Boehm
20243132fb Add <? input redirection
This tries to open the given file to use as stdin, and if it fails,
for any reason, it uses /dev/null instead.

This is useful in cases where we would otherwise do either of these:

```fish
test -r /path/to/file
and string match foo < /path/to/file

cat /path/to/file 2>/dev/null | string match foo
```

This both makes it nicer and shorter, *and* helps with TOCTTOU - what if the file is removed/changed after the check?

The reason for reading /dev/null instead of a closed fd is that a closed fd will often cause an error.

In case opening /dev/null fails, it still skips the command.
That's really a last resort for when the operating system
has turned out to be a platypus and not a unix.

Fixes #4865

(cherry picked from commit df8b9b7095)
2024-04-21 14:35:13 +02:00
Johannes Altmanninger
b3444ea128 Work around ctrl-c in VSCode killing wl-copy and clearing clipboard
wl-copy is a daemon process that serves its stdin to any wl-paste processes.
On Wayland, we launch it from fish_clipboard_copy.  It then lives in the
same process group as fish (see `ps -o pid,pgid,comm`).

For some reason pressing ctrl-c inside the VSCode integrated terminal with
fish as the default shell kills the wl-copy process, thus clearing the
clipboard. On other terminals it works fine.

This is also reproducible by running "echo foo | wl-copy" ctrl-v ctrl-c ctrl-v
(the second ctrl-v does not paste because wl-copy was killed).

Work around this for now by running wl-copy asynchronously, and disowning it.
This seems to fix it though I really don't know why. Alternatively we could
"setsid" but that's technically not available on BSD.

For some reason this works in Bash. We should strace it to figure out why.
2024-04-21 14:34:41 +02:00
Fabian Boehm
2c17d34971
Deprecate builtin test's one- and zero-argument modes (#10365)
This introduces a feature flag, "test-require-arg", that removes builtin test's zero and one argument special modes.

That means:

- `test -n` returns false
- `test -z` returns true
- `test -x` with any other option errors out with "missing argument"
- `test foo` errors out as expecting an option

`test -n` returning true is a frequent source of confusion, and so we are breaking with posix in this regard.

As always the flag defaults to off and can be turned on. In future it will default to on and then eventually be made read-only.

There is a new FLOG category "deprecated-test", run `fish -d deprecated-test` and it will show any test call that would change in future.
2024-04-21 14:25:54 +02:00
Fabian Boehm
18a0b44f0f docs: More on new keys 2024-04-20 17:05:46 +02:00
Johannes Altmanninger
c921c124ef docs: use canonical key names in :kbd: tags
This seems a bit better because it's what bind uses.  To makes sure that
something like :kbd:`ctrl-x` looks good in HTML, remove the border from the
kbd style.  Else both "ctrl" and "x" get small boxes which looks weird.
2024-04-20 15:36:29 +02:00
Johannes Altmanninger
c9793711dc Remove stale mention of plus key name 2024-04-20 15:36:29 +02:00
Johannes Altmanninger
414d9a1eb1 Reference more non-fish shell builtins that have relevant differences
When writing scripts for other shells, it can be confusing and annoying
that our `man` function shadows other manual pages, for example `exec(1p)`
from [Linux man-pages]. I almost never want to see the fish variant for such
contended cases (which obviuosly don't include fish-specific commands like
`string`, only widely-known shell builtins).

For the contented cases like `exec`, the POSIX documentation is more
substantial and useful, since it describes a (sub)set of languages widely
used for scripting.

Because of this I think we should stop overriding the system's man pages.
Nowadays we offer `exec -h` as intuitive way to show the documentation for
the fish-specific command (note that `help` is not a good replacement because
it uses a web browser).

Looking through the contended commands, it seems like for most of them,
the fish version is not substantially different from the system version.
A notable exception is `read` but I don't think it's a very important one.

So I think we should can sacrifice a bit of the native fish-scripting
experience in exchange for playing nicer with other shells. I think the
latter is more important because scripting is not our focus, the way I see it.
So maybe put our manpath at the end.

In lieu of that, let's at least have `exec.rst` reference the system variant.

[Linux man-pages]: https://www.kernel.org/doc/man-pages/

Closes #10376
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
af5afe20c2 Enable Sphinx man_show_urls config
URLs are not rendered in our man pages.  Let's tell Sphinx to include links
in the output until https://github.com/sphinx-doc/sphinx/pull/12108 is widely
available.
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
dea13c86a9 Document the ! (not) and . (source) aliases more 2024-04-20 13:34:08 +02:00
Johannes Altmanninger
e97a4fab71 Escape : and = in file completions
This is similar to f7dac82ed (Escape separators (colon and equals) to improve
completion, 2019-08-23) except we only escape : and = if they are the result of
file completions.  This way we avoid issues with custom completions like dd.
This also means that it won't work for things like __fish_complete_suffix
[*] but that can be fixed later, once we can serialize the DONT_ESCAPE flag.

By moving the escaping step earlier, this causes some unit test changes
which should not result in actual behavior change.

See also #6099

[*]: The new \: and \= does not leak from "complete -C" because that command
unescapes its output  -- unless --escape is given.
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
db365b5ef8 Do not treat \: or \= as file completion anchor
Partially reapplies f7dac82ed (Escape separators (colon and equals) to
improve completion, 2019-08-23) which has been reverted.
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
a046b73ec7 Extract test logic for computing and applying completion
Also move one test so all the bracket tests are contiguous.
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
7dc0446c5c Match stdlib strip_prefix return value 2024-04-20 13:34:08 +02:00
Johannes Altmanninger
30fbd4280d Simplify match statement in escape_string_script 2024-04-20 13:34:08 +02:00
Johannes Altmanninger
334946af61 completions/complete: add --escape 2024-04-20 13:34:08 +02:00
Johannes Altmanninger
24e4fdd695 Support "bind xyz" again
This was used in Vi mode (for yiw and "*p) so rejecting it is a bit reckless.
2024-04-20 13:34:08 +02:00
Johannes Altmanninger
e571774c97 Make alt-d on empty commandline call dirh again
alt-d used to do that until evil merge[*] 213e90704 (Merge remote-tracking branch
'upstream/master' into bind_mode, 2014-01-15) which changed the order of
the \ed bindings such that the smart dirh version would be shadowed by the
simpler ones.

[*] git blame alone failed to find it because it skips merge commits.
2024-04-20 12:11:30 +02:00
Johannes Altmanninger
565eb85d8b fish_key_reader: use canonical key name for ctrl-{c,d}
The uppercase version has a different meaning now.
2024-04-20 12:11:30 +02:00
Johannes Altmanninger
5ba21cd290 Send repaint requests through the input queue again
Another consequence of a583fe723 ("commandline -f foo" to skip queue
and execute immediately, 2024-04-08) is that "commandline -f repaint"
will paint the prompt with the current value of $status which might be
set from a shell command in a the currently executing binding, instead of
waiting for the top-level status. This is wrong, at least historically. It
surfaces in bindings like alt-w which always paint a status value of [1]
when on single-lines commandlines.

Another regression is that a redundant repaint in a signal handler outputs
an extra prompt.

Fix both by making repaint commands go over the input queue again.  This way,
they are always run with a good commandline state.  There is no need to
repaint immediately because I don't think anyone has a data dependency on it
(we currently don't expose the prompt string), it's only for rendering.
2024-04-19 12:05:27 +02:00
Johannes Altmanninger
040cb04423 Escape nonprintable characters when reporting invalid key name
Part of #10450
2024-04-18 23:27:05 +02:00
Fabian Boehm
769316fd1a Add a few tests for legacy bind invocations 2024-04-18 22:27:58 +02:00
Fabian Boehm
3b6a11f881 fmt 2024-04-18 22:26:14 +02:00
Fabian Boehm
6558c0a8e5 key: Actually do engage legacy mode if first char is control
This was already in the comment.

Fixes #10450
2024-04-18 22:18:51 +02:00
Johannes Altmanninger
cad63263d2 debian/copyright: update for renamed and removed files 2024-04-18 11:24:56 +02:00
Johannes Altmanninger
bdd478bbd0 Disable focus reporting on non-tmux again for now
We sometimes leak ^[[I and ^[[O focus reporting events when run from VSCode's
"Run python file" button in the top right corner. To reproduce I installed
the ms-python extension set the VSCode default shell to fish and repeatedly
ran a script that does "time.sleep(1)". I believe VSCode synthesizes keys
and triggers a race condition.

We can probably fix this but I'm not sure when I'll get to it (given how
relatively unimportant this feature is).

So let's go back to the old behavior of only enabling focus reporting in tmux.

I believe that tmux is affected by the same VSCode issue (also on 3.7.1 I
think) but I haven't been able to get tmux to emit focus reporting sequences
yet.  Still, keep it to not regress cursor shape (#4788).  So far this is
the only motivation for focus reporting and I believe it is only relevant
for terminals that can split windows (though there are a bunch that do).

Closes #10448
2024-04-18 10:38:15 +02:00
ridiculousfish
ed8f62e723 Reimplement WGetopter::exchange() using rotate_left
A simplification informed by the new test.
2024-04-17 12:41:16 -07:00
ridiculousfish
f990d52d2b Add a test for WGetopter::exchange() 2024-04-17 12:41:12 -07:00
Verte
13230cdda0 Rewrite wgetopt.rs to Rustier syntax and naming
From https://github.com/fish-shell/fish-shell/pull/9515

Closes #9515
2024-04-17 11:26:51 -07:00
Johannes Altmanninger
2e42d80dc9 completions/scp: silence error on unexpected version
There seem to be versions of ssh (possibly not from OpenSSH) that don't
print the version number in -V, so make sure not to pass an empty string as
numeric arg to test.

Fixes #10445
2024-04-17 09:52:12 +02:00
Mahmoud Al-Qudsi
85b3dbbec0 Bump cc-rs to 1.0.94 to work around spurious warnings
Under Ubuntu 23.10 (gcc 13), older cc crate versions would complain that the
compiler could not be identified.

See https://github.com/rust-lang/cc-rs/issues/958
2024-04-16 21:33:59 -05:00
ridiculousfish
a996cafeeb Make history::remove take a &wstr instead of a WString
While it does need to store the string, we also need to use the string after
storing it, so we aren't getting any advantage from passing by value. Just pass
by reference to simplify the call sites.
2024-04-15 09:47:46 -07:00
Anurag Singh
8a8c2656f3 remove unnecessarily silenced lint in history 2024-04-15 09:43:38 -07:00
Johannes Altmanninger
9af6a64fd2 Fix bad contrast in search match highlighting
This is another problem that has been bothering me for years: as mentioned
in 1dd901e52 (Maintain cursor in history prefix search, 2024-04-12), up-arrow
search highlights search matches but the contrast is really bad, especially in
command position, because the search matches --background=brblack is combined
with whatever foreground syntax highlighting the command has.  The history
pager had a similar problem (for the selected history item) but circumented
it by disabling syntax highlighting altogether for the selected item.

fish_color_search_match's foreground component is ignored.
Let's use it instead of syntax highlighting.

This fixes the contrast on some default colorschemes but the bryellow
foreground looks weirdly like an error/warning on some terminals.  Change it
to white. This needs a hack because we don't have a canonical way to tell
if a uvar has been set by the user. Fortunately the foreground component
hasn't been used at all so far, so we're not so much changing it as much as
initializing it.
2024-04-15 09:40:21 +02:00
Johannes Altmanninger
27b1f28108 Minimize key parsing fallback logic and update changelog 2024-04-15 09:40:21 +02:00
Johannes Altmanninger
47bb56efe6 Allow mapping new-style sequences that start with escape
On Konsole with

    function my-bindings
        bind --preset --erase escape
        bind escape,i 'echo escape i'
    end
    set fish_key_bindings my-bindings

the "escape,i" binding doesn't trigger.  This is because of our special
handling of the escape key prefix.  Other multi-key bindings like "bind j,k"
wait indefinitely for the second character.  But not "escape,i"; that one
has historically had a low timeout (fish_escape_delay_ms).  The motivation
is probably that we have a "escape" binding as well that shouldn't wait
indefinitely.

We can distinguish between the case of raw escape sequence binding like "\e123"
and a binding that talks about the actual escape key like "escape,i". For the
latter we don't need the special treatment of having a low timeout, so make it
fall back to "fish_sequence_key_delay_ms" which waits indefinitely by default.
2024-04-15 09:20:44 +02:00
Johannes Altmanninger
a37629f869 fish_clipboard_copy: indent multiline commands
See also the earlier commits.

Closes #10437
2024-04-15 09:20:44 +02:00
Johannes Altmanninger
611a0572b1 builtins type/functions: indent interactively-defined functions
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes #8603
2024-04-15 08:32:31 +02:00
Johannes Altmanninger
222673f339 edit_command_buffer: send indented commandline to editor
Indented multiline commandlines look ugly in an external editor.  Also,
fish doesn't properly handle the case when the editor runs fish_indent.
Fix is by indenting when exporting the commandline and un-indenting when
importing the commandline again.

Unindent only if the file is properly indented (meaning at least by the
amount fish would use).  Another complication is that we need to offset
cursor positions by the indentation.

This approach exposes "fish_indent --only-indent" and "--only-unindent"
though I don't imagine they are useful for others so I'm not sure if this
is the right place and whether we should even document it.

One alternative is to add "commandline --indented" to handle indentation
transparently.
So  "commandline --indented" would print a indented lines,
and "commandline --indented 'if true' '    echo'" would remove the unecessary
indentation before replacing the commandline.
That would probably simplify the logic for the cursor position offset.
2024-04-15 08:32:31 +02:00
Johannes Altmanninger
47a446ae18 Teach fish_indent to only indent and unindent
To be used in the following commits.
2024-04-15 08:32:31 +02:00
Anurag Singh
7369516871 whitespace 2024-04-15 08:31:16 +02:00
Anurag Singh
c044d5e3f0 add history append subcommand 2024-04-15 08:31:16 +02:00
Adam J. Stewart
6f408211a1
Add ruff completions (#10440)
* Add ruff completions

* Automatically generate and cache
2024-04-14 13:29:10 +02:00
Johannes Altmanninger
e01fc62d69 Don't leak encoding of invalid codepoints into uvar file
When we read bytes like \xfc that don't produce a Unicode code point,
we encode them in a Unicode private use area.
This encoding should be transparent to the user.

We accidentally add it to uvar files as \uf6fc in this case.  When reading
it back, read_unquoted_escape() will fail at the "fish_reserved_codepoint(c)"
check. This check is to avoid external input being misinterpreted
as one of our in-band signalling characters like ANY_CHAR (for *).

For encoded raw bytes, this check probably doesn't really matter in terms of
security because the only thing we do with these bytes is convert them back
to raw. So we could allow unescaping them at this point, thus supporting
old uvar files.

However that seems like the wrong direction. PUA encoding should never leak.
So let's instead make sure to serialize it as \xfc instead of \f6fc going
forward.

Fixes #10313
2024-04-14 07:59:42 +02:00
Johannes Altmanninger
2329a3adb9 Extend fish_reserved_codepoint by encodings for named keys
This might prevent unexpected behavior when the terminal sends an input
character that matches one of our named keys like Enter.
2024-04-14 07:54:03 +02:00
Johannes Altmanninger
29b309dd5f shift-delete to delete current history search match
Popular operating systems support shift-delete to delete the selected item
in an autocompletion widgets.  We already support this in the history pager.
Let's do the same for up-arrow history search.

Related discussion: https://github.com/fish-shell/fish-shell/pull/9515
2024-04-13 20:23:51 +02:00