Commit Graph

777 Commits

Author SHA1 Message Date
Johannes Altmanninger
fb99edae92 Stop using comma from command substitution in brace expansion
Fixes #5048
2024-04-26 18:15:47 +02:00
Fabian Boehm
7ec715ba8b tests: Fix noshebang test
This was silently skipped because of a broken REQUIRES line

(it would be great if our test runner could surface skipped tests)
2024-04-25 21:52:56 +02:00
Fabian Boehm
691acfc28d tests: Disable some slow tests under ASAN
These take over two minutes under ASAN (like ~40 seconds without, so
they aren't quick to begin with), and don't really give any additional
insight.

So we skip them to save time
2024-04-25 21:52:13 +02:00
Fabian Boehm
ac8b1db899 tests: More timeout 2024-04-25 21:36:31 +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
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
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
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
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
Johannes Altmanninger
0c5deacedc Add test for updating the commandline state on background job exit
This is the regression test for 8386088b3 (Update commandline state changes
eagerly as well, 2024-04-11).
2024-04-13 18:24:53 +02:00
Johannes Altmanninger
29dc307111 Insert some completions with quotes instead of backslashes
File names that have lots of spaces look quite ugly when inserted as
completions because every space will have a backslash.

Add an initial heuristic to decide when to use quotes instead of
backslash escapes.

Quote when
1. it's not an autosuggestion
2. we replace the token or insert a fresh one
3. we will add a space at the end

In future we could relax some of these requirements.

Requirement 2 means we don't quote when appending to an existing token.
Need to find a natural behavior here.

Re 3, if the completion adds no space, users will probably want to add more
characters, which looks a bit weird if the token has a trailing quote.
We could relax this requirement for directory completions, so «ls so»
completes to «ls 'some dir with spaces'/».

Closes #5433
2024-04-13 15:34:21 +02:00
Johannes Altmanninger
8d88b4d358 Support quoted escaping also when ' or \ is present
Also, if there are more single quotes than double quotes and dollars, use
double quotes for quoting.
2024-04-13 15:33:05 +02:00
Johannes Altmanninger
4f536d6a9b Update commandline state snapshot lazily
I think commit 8386088b3 (Update commandline state changes eagerly as well,
2024-04-11) broke the alt-s binding.

This is because we update the commandline state snapshot (which is consumed
by builtin commandline and others) only at key points.  This seems like a
dubious optimization.  With the new streamlined bind execution semantics,
this doesn't really work anymore; any shell command can run any number of
commands like "commandline -i foo" which should synchronize.

Do the simple thing of calculating the snapshot whenever needed.
2024-04-13 14:36:11 +02:00
Johannes Altmanninger
1e858eae35 tests: filter control sequences only when interactive
This demonstrates that we only write control sequences when interactive.
2024-04-12 12:28:22 +02:00
Johannes Altmanninger
e934e1b009 Test that bind output can recreate the same bindings 2024-04-09 00:22:41 +02:00
Johannes Altmanninger
f61ef2c63d Display raw escape sequences the old way again
If a binding was input starting with "\e", it's usually a raw control sequence.
Today we display the canonical version like:

    bind --preset alt-\[,1,\;,5,C foo

even if the input is

    bind --preset \e\[1\;5C foo

Make it look like the input again.  This looks more familiar and less
surprising (especially since we canonicalize CSI to "alt-[").

Except that we use the \x01 representation instead of \ca because the
"control" part can be confusing. We're inside an escape sequence so it seems
highly unlikely that an ASCII control character actually comes from the user
holding the control key.

The downside is that this hides the canonical version; it might be surprising
that a raw-escape-sequence binding can be erased using the new syntax and
vice versa.
2024-04-09 00:07:27 +02:00
Johannes Altmanninger
b04dee358e Don't translate \n to enter
Apparently it's never entere because we turn off ICRNL.

I'm not sure why it says "no binding found".
2024-04-02 17:59:40 +02:00
Johannes Altmanninger
8bf8b10f68 Extended & human-friendly keys
See the changelog additions for user-visible changes.

Since we enable/disable terminal protocols whenever we pass terminal ownership,
tests can no longer run in parallel on the same terminal.

For the same reason, readline shortcuts in the gdb REPL will not work anymore.
As a remedy, use gdbserver, or lobby for CSI u support in libreadline.

Add sleep to some tests, otherwise they fall (both in CI and locally).

There are two weird failures on FreeBSD remaining, disable them for now
https://github.com/fish-shell/fish-shell/pull/10359/checks?check_run_id=23330096362

Design and implementation borrows heavily from Kakoune.

In future, we should try to implement more of the kitty progressive
enhancements.

Closes #10359
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
bb7704efe8 Fix potentially flaky tmux-history-search test
We need to give fish time to render I think.
2024-04-02 14:35:16 +02:00
Mahmoud Al-Qudsi
41eaf2f8dc
Merge pull request #10398 from mqudsi/forward-char-passive
Add `forward-char-passive` and `backward-char-passive`
2024-03-30 22:29:46 -05:00
Johannes Altmanninger
a29cc8f169 Fix regression when selection start is deleted
Ranges with start > end are invalid; we crash with "slice index starts at
10 but ends at 0".
2024-03-30 09:56:48 +01:00
Mahmoud Al-Qudsi
1adbec2d37 Add backward-char-passive 2024-03-29 14:23:51 -05:00
Mahmoud Al-Qudsi
3980e46d3a Add test for forward-char-passive 2024-03-28 00:46:41 -05:00
Johannes Altmanninger
94477f3029 Fix commandline -C regression handling negative offsets 2024-03-10 09:46:16 +01:00
Fabian Boehm
947883c842 commandline: Fix setting cursor
Fixes #10358
2024-03-10 09:27:56 +01:00
Fabian Boehm
d7adf8ef87 fixup! status again
Dangit I should double-check these
2024-03-04 17:10:13 +01:00
Fabian Boehm
1f43bbb449 fixup! fix status 2024-03-04 16:54:32 +01:00
Fabian Boehm
031dbb33b1 commandline: Borrow libdata later
builtin_print_help will end up borrowing it as mutable.

Fixes #10342
2024-03-04 16:53:51 +01:00
ridiculousfish
4396051449 Fix the history pager deletion test on macOS
It appears that the shift-delete key escape sequence is not being generated
because there's no mapping for it in screen-256color, causing the test to fail.
Switch to using f1 for the test.
2024-03-03 14:11:13 -08:00
Fabian Boehm
f93a3e9e9b fish_indent: Collapse successive newlines
This makes it so code like

```fish
echo foo

echo bar
```

is collapsed into

```fish
echo foo

echo bar
```

One empty line is allowed, more is overkill.

We could also allow more than one for e.g. function endings.
2024-02-27 16:25:01 +01:00
Fabian Boehm
9a2729d298 Fix builtin read crash with negative nchars
Also make it simpler by just passing it along as a usize
2024-02-19 18:48:21 +01:00
Johannes Altmanninger
b687ef036b Fix regression of C-e always accepting autosuggestion 2024-02-17 01:34:32 +01:00
Johannes Altmanninger
8c91d1421a Add some sleeps to fix the tmux-history-search test 2024-02-17 01:33:29 +01:00
Fabian Boehm
983af732dd Add test for history pager crash 2024-02-16 18:43:16 +01:00
Johannes Altmanninger
4cb766324b Fix regression in forward-single-char
This crashes if the autosuggesion is exhausted.  C++ used

    autosuggestion.text.substr(pos, 1)

which throws if pos is OOB but not if pos + 1 is.
2024-02-14 10:52:38 +01:00
Himadri Bhattacharjee
4e6e897781
string repeat: allow omission of -n (#10282) 2024-02-11 12:19:02 +01:00
Johannes Altmanninger
0c5a616113 Show autosuggestion again after undoing deletion
Commit e5b34d5cd (Suppress autosuggesting during backspacing like browsers do,
2012-02-06) disabled autosuggestion when backspacing.  Autosuggestions are
re-enabled whenever we insert anything in the command line.  Undo uses a
different code path to insert into the command line, which does not re-enable
autosuggestion.

Fix that.

Also re-enable autosuggestion when undo erases from the command line.
This seems like the simplest approach. It's not clear if there's a better
behavior; browsers don't agree on one in any case.
2024-02-07 00:07:47 +01:00
Johannes Altmanninger
dc75367343 builtins set: fix regressions querying undefined indices
This inadvertently regressed in 77aeb6a2a (Port execution, 2023-10-08).

Reference: 77aeb6a2a8 (commitcomment-137509238)
2024-02-07 00:07:47 +01:00
Fabian Boehm
8d71eef1da
Add feature flag to turn off %self (#10262)
This is the last remnant of the old percent expansion.

It has the downsides of it, in that it is annoying to combine with
anything:

```fish
echo %self/foo
```

prints "%self/foo", not fish's pid.

We have introduced $fish_pid in 3.0, which is much easier to use -
just like a variable, because it is one.

If you need backwards-compatibility for < 3.0, you can use the
following shim:

```fish
set -q fish_pid
or set -g fish_pid %self
```

So we introduce a feature-flag called "remove-percent-self" to turn it
off.

"%self" will simply not be special, e.g. `echo %self` will print
"%self".
2024-02-06 22:13:16 +01:00
Fabian Boehm
bdfbdaafcc
Forbid subcommand keywords in variables-as-commands (#10249)
This stops you from doing e.g.

```fish
set pager command less
echo foo | $pager
```

Currently, it would run the command *builtin*, which can only do
`--search` and similar, and would most likely end up printing its own
help.

That means it very very likely won't work, and the code is misguided -
it is trying to defeat function resolution in a way that won't do what
the author wants it to.

The alternative would be to make the command *builtin* execute the
command, *but*

1. That would require rearchitecting and rewriting a bunch of it and
the parser
2. It would be a large footgun, in that `set EDITOR command foo` will
only ever work inside fish, but $EDITOR is also used outside.

I don't want to add a feature that we would immediately have to discourage.
2024-02-06 22:12:55 +01:00
Samuel Collins
508ea59dcd
fix builtin help ignoring redirects (#10276)
* fix builtin help ignoring redirects

* test builtin help redirects
2024-02-02 17:53:50 -06:00
Johannes Altmanninger
54bc196918 Only use fuzzy option completion if there is a leading -
Commit b768b9d3f (Use fuzzy subsequence completion for options names as well,
2024-01-27) allowed completing "oa" to "--foobar", which is a false positive,
especially because it hides other valid completions of non-option arguments.
Let's at least require a leading dash again before completing option names.
2024-01-30 09:09:45 +01:00
Fabian Boehm
3914bbe538 Remove use of env -u in tests
Not available on NetBSD.

We can get by without.
2024-01-27 18:47:38 +01:00
Johannes Altmanninger
b768b9d3f5 Use fuzzy subsequence completion for options names as well
Version 2.1.0 introduced subsequence matching for completions but as the
changelog entry mentions, "This feature [...] is not yet implemented for
options (like ``--foobar``)".  Add it. Seems like a strict improvement,
pretty much.
2024-01-27 17:57:48 +01:00
Johannes Altmanninger
29f35d6cdf completion: adopt commandline -x replacing deprecated -o
This gives us more accurate completions because completion scripts get
expanded paths
2024-01-27 09:28:06 +01:00
Johannes Altmanninger
368017905e builtin commandline: -x for expanded tokens, supplanting -o
Issue #10194 reports Cobra completions do

    set -l args (commandline -opc)
    eval $args[1] __complete $args[2..] (commandline -ct | string escape)

The intent behind "eval" is to expand variables and tildes in "$args".
Fair enough. Several of our own completions do the same, see the next commit.

The problem with "commandline -o" + "eval" is that the former already
removes quotes that are  relevant for "eval". This becomes a problem if $args
contains quoted () or {}, for example this command will wrongly execute a
command substituion:

    git --work-tree='(launch-missiles)' <TAB>

It is possible to escape the string the tokens before running eval, but
then there will be no expansion of variables etc.  The problem is that
"commandline -o" only unescapes tokens so they end up in a weird state
somewhere in-between what the user typed and the expanded version.

Remove the need for "eval" by introducing "commandline -x" which expands
things like variables and braces. This enables custom completion scripts to
be aware of shell variables without eval, see the added test for completions
to "make -C $var/some/dir ".

This means that essentially all third party scripts should migrate from
"commandline -o" to "commandline -x". For example

    set -l tokens
    if commandline -x >/dev/null 2>&1
        set tokens (commandline -xpc)
    else
        set tokens (commandline -opc)
    end

Since this is mainly used for completions, the expansion skips command
substitutions.  They are passed through as-is (instead of cancelling or
expanding to nothing) to make custom completion scripts work reasonably well
in the common case. Of course there are cases where we would want to expand
command substitutions here, so I'm not sure.
2024-01-27 09:28:06 +01:00
Johannes Altmanninger
1b9e5258b5 Fix regression when erasing word in search field
This fixes a crash introduced in the reader port.

The tmux tests are not great but at least easy to write.
2024-01-27 03:46:26 +01:00
Fabian Boehm
bfc17079be qmark-noglob: Set group back
These are the version the flag was *introduced*, so they should stay
the same over the lifetime of the flag.
2024-01-25 18:26:48 +01:00