Commit Graph

1802 Commits

Author SHA1 Message Date
Fabian Boehm
2dedff2200 tests/abbrs: Disable check that fails on CI
It appears we're getting the correct output, but in the wrong order,
so pexpect doesn't filter it correctly:

> \r\n\x1b]133;C;cmdline_url=echo%20bar\x07bar\r\n\x1b]133;D;0\x07\x1b[?25h⏎                                                                              \r⏎ \r\rprompt 39>\x1b[?2004h

That `\x07bar` should be the \a that marks the end of the escape
sequence, followed by the actual "bar", followed by sequences marking
the end of output...
2025-03-29 13:21:31 +01:00
Fabian Boehm
89b62a56e1 editable_line: guard against empty text
there's got to be a nicer way to do this

Fixes #11324
2025-03-26 19:23:17 +01:00
Johannes Altmanninger
360cfdb7ae completions/git: fix arg completion for third-party git commands, again
Commit 50e595503e (completions/git: fix completions for third-party git
commands, 2025-03-03) wasn't quite right, as we can see in the linked
reproduction:

	$ fish_trace=1 complete -C 'git machete add --onto '
	----> complete -C git-machete\ add\n--onto\

The recursive completion invocation contains a spurious newline, which means
that "--onto" is the command name.  The newline is produced by "string escape
-- add --onto" inside a command substitution.

Fix this by interpreting newlines as list separators, and then joining
by spaces.

Fixes #11319
2025-03-25 11:16:18 +01:00
5225225
149386a593 mention psub in the error for "Invalid redirection target"
Currently fish errors out with

```fish
fish: Invalid redirection target:
rev <(ls)
    ^~~~^
```

This isn't very helpful in telling the user what they could be doing instead:
`rev (ls | psub)`.

Closes #11287
2025-03-22 14:12:54 +01:00
James Falcon
0dbfb4ccb1 Remove directory name prefix in truncated completions
Sometimes, the dirname of a completion is much longer than the basename.

When the dirname is the same for many completions, a long common dirname
prefix makes it hard to see the interesting differences in the basenames.

Fix this by collapsing the dirname prefix to "…/".

In future, we should find a generic way to collapse completions that don't
contain slashes.

Closes #8618
Closes #11250
2025-03-21 00:53:06 +01:00
Fabian Boehm
e8bd45d760 tests: Remove the need to pass $FISH_SOURCE_DIR
This is only used in check-translations, where we can just use a
relative path from the test script
2025-03-19 18:26:11 +01:00
Fabian Boehm
d203ee4d53 function: Also error for read-only var in positional arg
We have this hack where any positional arguments are taken as argument
names if "--argument-names" is given, and that didn't check for
read-only variables.

Fixes #11295
2025-03-17 19:55:14 +01:00
Fabian Boehm
411a396fa9 tests: Just check that the version starts with a digit
Our versions look like

4.0.0
4.0b1
4.0.1-535-abfef-dirty

But packagers may want to add more information here, and we don't
really care. Note that we no longer ever set the version to "unknown"
since 5abd0e46f5.

Supersedes #11173
2025-03-15 10:54:12 +01:00
Johannes Altmanninger
9f79fe17fc Quote only unique completions, use backslashes for ambiguous ones
Commit 29dc307111 (Insert some completions with quotes instead of backslashes,
2024-04-13) breaks some workflows. Given

	touch '[test] file1'
	touch '[test] file2'
	ls tes<Tab>

we insert completions quoted, which is inconvenient when using globs.

This implicit quoting feature is somewhat minor. But quotes look nicer,
so let's try to keep them.  Either way, users can ask for it by starting a
token with «"».

Use quoting only when we insert unique completions.

Closes #11271
2025-03-14 22:21:42 +01:00
Fabian Boehm
6627d403d3 tests: Override __fish_print_help
This effectively disables "--help", replacing it with just a stand-in
string.

The upshot is that it makes the test suite immune to whether or not it
can find the documentation - until now it needed to *not* find it,
which is weird.

(also it saves some useless lines)

Fixes #11270
2025-03-13 18:13:10 +01:00
Johannes Altmanninger
2930c85926 Add hack to restore cursor position on undo ofter exec again
See f2dde229aa (Revert changes to restore cursor position after undo,
2025-03-05).

I think there are two problems with tmux when doing a final redraw of a
larger-than-screen commandline.  One is easy to trigger independent of
f2dde229aa.  The other is reproduced by the broken output in the tmux test
removed by that commit. Should root-cause them later.

Use a hack for now; this also happens to fix the broken output in tmux.
2025-03-08 13:12:38 +01:00
Peter Ammon
f2dde229aa Revert changes to restore cursor position after undo
This feature is nice and desirable, but it was implemented in a intrusive way
by modifying the sequence of bytes we emit when running a command; this in
turn requires changing a bunch of tests.

This sequence hasn't changed in decades and the consequences of changing it
are hard to predict, given that it is likely terminal dependent; we've
already found a regression.

It's fine to reintroduce this but it should be done in a less intrusive way
(conceptually that seems straightforward - we're just remembering the cursor
position).

Revert "Fix spurious blank lines when executing scrolled commandline"

This reverts commit 0e512f8033.

Revert "On undo after execute, restore the cursor position "

This reverts commit 610338cc70.
2025-03-05 17:57:48 -08:00
Johannes Altmanninger
852cb60ebd Make abbreviation completions shadow commands
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$yD_Lutaftf6ytk617kjw5vC-k_OgHRQxIiSRv89uBMI
it's weird that command name completions shadow abbreviation name
completions, given that the abbreviation will the one that will be
executed in the typical cases. Let's put abbreviation completions first;
unique_completions_retaining_order() will take care of removing any command
completions we add later.
2025-03-04 09:45:15 +01:00
Johannes Altmanninger
50e595503e completions/git: fix completions for third-party git commands
Before 798527d79a (completions: fix double evaluation of tokenized commandline, 2024-01-06)
git-foo completions did something like

	set -l subcommand_args (commandline -opc)
	complete -C "git-foo $subcommand_args "

As mentioned in 368017905e (builtin commandline: -x for expanded tokens,
supplanting -o, 2024-01-06), the "-o" option is bad
because it produces a weird intermediate, half-expanded state.

The immediate goal of 798527d79a was to make sure we do not do any
more expansion on top of this.  To that end, it changed the above to
"\$subcommand_args".  The meaning is more or less the same[^*] but crucially,
the recursive completion invocation does not see through the variable,
which breaks some completions.

Fix this with the same approach as in 6b5ad163d3 (Fix double expansion of
tokenized command line, 2025-01-19).

[^*]: It wasn't semantically correct before or after -- this was later
corrected by 29f35d6cdf (completion: adopt commandline -x replacing deprecated
-o, 2024-01-22)).

Closes #11205
2025-03-03 14:30:48 +01:00
Johannes Altmanninger
f415413bfb Strip "$ " prefixes on paste
Code blocks are often written like

	$ echo hello world
	hello world

The "$ " is widely understood to introduce a shell command.  It's often
easier to copy the whole line than copying everything after "$ ".

This gets more pronounced when there are multiple commands without interleaved
output (either due to omission or the rule of silence). Copying the whole
code block is the most natural first step.

You could argue that this is a presentation issue - the dollar prefix
should be rendered but not copied to clipboard. But in my experience there
are many cases where there is no HTML or Javascript that would allow the
copy-to-clipboard functionality to strip the prefixes.

The "$ " prefix is almost never useful when pasting; strip it automatically.

Privileged commands use "# " as prefix which overlaps with comments, so do
not strip that until we can disambiguate (another potential reason not to
do that would be safety but it's unclear if that really matters).

Add the new logic to the commandline builtin, because we don't know about the
AST in fish script. (Technically, the tokenizer already knows whether a "$
" is in command position and at the beginning of a line, but we don't
have that either (yet).)

Maybe we should move the rest of __fish_paste over as well. I'm not sure what
difference that would make; for one, pasting could no longer be cancelled
by ctrl-c (in theory), which seems like a good direction?
2025-03-01 07:55:53 +01:00
Laurențiu Nicola
f224ff1d28 Fix create-base-directories.fish with SELinux 2025-02-27 10:33:22 +08:00
Fabian Boehm
3688dd01ba fixup! import sys
I always forget that's not a builtin.
2025-02-21 17:54:25 +01:00
Fabian Boehm
1835f141eb Disable tmux-multiline-prompt.fish and fkr.py tests on CI
See #11036
2025-02-21 17:46:26 +01:00
Johannes Altmanninger
afbdb9f268 Fix off-by-one error in new commandline --column
parse_util_lineno() returns 1-based line numbers but
parse_util_get_offset_from_line() expects zero based line offsets.

Fixes #11162
2025-02-19 10:44:00 +01:00
Peter Ammon
5e38a2a46b Get tmux-history-search2.fish passing on macOS 2025-02-16 13:02:23 -08:00
Peter Ammon
22b944ef4b Get tmux-complete2.fish passing on macOS 2025-02-16 11:44:43 -08:00
Łukasz Wieczorek
82750bbaec Reformat with black. 2025-02-12 22:59:27 +08:00
Johannes Altmanninger
cad42a0e53 Fix regression stomping commandline when completing after history search
Commit 82c4896809 (Fix unnecessary undo when exiting the history
pager with an empty cmd and no matches, 2025-02-02) was a nice fix
but failed to account for the code path where we switch from history
search to completion pager (and maybe also the inverse case).  In this
case we don't want to undo the transient edit but commit it instead.
2025-02-12 14:24:06 +01:00
Johannes Altmanninger
7197bc7760 Add a test for replacing completions of directory-variable name 2025-02-12 14:23:45 +01:00
Fabian Boehm
b6fe6b7bf4 Allow fish_indent builtin to be redirected
Missed write_to_fd calls

Not in 4.0 because fish_indent isn't a builtin there.

This requires str2wcstring, which is awkward but it's not performance-sensitive.

Fixes #11146
2025-02-11 22:19:44 +01:00
Johannes Altmanninger
4b20e3ad91 Back out "Feature flag to prevent executing off buffered keys"
e697add5b5 (Feature flag to prevent executing off buffered keys, 2025-01-02)
breaks my expectations/habits, and it breaks Midnight Commander.
Additionally, I'm not aware of any case where it actually adds security.
We generally assume that terminal echoback sequences do not contain
control characters except for well-known escape sequences.

This backs out commit e697add5b5.

See #10987, #10991
2025-02-09 16:32:49 +01:00
Fabian Boehm
b50c832a35 abbr: Print optional set-cursor arg correctly
Allows the output to round-trip.

Fixes #11141
2025-02-07 12:28:59 +01:00
Fabian Boehm
414293521e tests: Use command ls to avoid indicators
This can happen if your filesystem on macOS has xattrs, so the newly
created dirs will also have them and `ls` will print an "@" indicator.

Fixes #11137
2025-02-07 12:22:23 +01:00
Johannes Altmanninger
9e19e419a4 Back out "Remove test for broken tmux output"
Add back the test from 0e512f8033 (Fix spurious blank lines when
executing scrolled commandline, 2025-01-08).

It's flaky in CI (see b8208d72f7 (Remove test for broken tmux output,
2025-01-09)) but that's not a problem for now because we disabled
the entire test CI in 2508cc9de6 (Disable some more tests under CI,
2025-01-14).
2025-02-06 19:12:00 +01:00
Johannes Altmanninger
7db955374b Fix regression causing off-by-one pager height on truncated autosuggestion
Commit c54131c8c5 (Make at least one character of the autosuggestion
always shown, 2025-01-26) draws autosuggetion until exactly the end
of the line, possibly truncated by an ellipsis.  The line is "barely"
soft-wrapped; no characters or cursors are on the next line.

This means that the pager can start there (on the next line).
The calculation for available pager height fails to recognize that.
Fix that.
2025-02-06 19:12:00 +01:00
Fabian Boehm
8ddb078db8 reader: Only maintain cursor position in non-empty prefix search
Otherwise this would always move the cursor to the beginning.

Fixes #11133

(cherry picked from commit db244e0492)
2025-02-05 22:14:47 +01:00
kerty
82c4896809 Fix unnecessary undo when exiting the history pager with an empty cmd and no matches
Currently, when the history pager is selected, fish always one undo away from the original search term. If the search has no matches, the fish replaces the search term with itself (resulting in no visible change, but it is still treated as a transient edit). However, fish ignores undo operations where the replacement is "" by "", leading to an unnecessary undo. For example:
1. Type 'test'.
2. Do ctrl-c.
3. Open the history pager.
4. Make so there are no matches.
5. Exit - you will undo back to 'test'.

This commit also ensures that if you select a pager element that does not change the content of the commandline, it will not be added to the undo history.
2025-02-04 10:12:30 +01:00
kerty
5e4f801ad5 Fix unnecessary undo in backward history search after returning to the present
Currently, if we return to the present, fish thinks that it still has a transient edit. This results in an unnecessary undo when performing a backward search. For example:
1. Type ': '.
2. Do a backward token search.
3. Do a forward token search.
4. Do another backward token search - this will result in the undo of ': '.
2025-02-04 10:12:30 +01:00
Fabian Boehm
8d6fdfd9de Remove cmake "test" target
This can no longer be overridden, which means we have a broken "test"
target now. Instead, you need to call "make fish_run_tests".

Blergh.

Fixes #11116
2025-02-02 13:41:43 +01:00
Johannes Altmanninger
66e2b6d8c1 Fix query response wait confusion over builtin read
Every reader gets their own wait handle which is wrong and not actually
needed - it's a singleton.  We should probaly make it global. Let's
do an intermediate solution for now -- not much time this weekend ;).

Fixes #11110
2025-02-01 09:25:53 +01:00
kerty
e2c9969840 Fix deletion of prompt in last 2 columns when first line soft wrapped
When drawing a soft wrapped line, the last 2 characters of the previous line are redrawn. If these 2 characters are occupied by the prompt, they are replaced with ' '.
Steps to reproduce:
fish -C 'function fish_prompt; printf %0"$(math $COLUMNS)"d 0; end'
# type anything
# observe that the last two characters of the prompt have been deleted
2025-01-31 13:37:27 +01:00
Johannes Altmanninger
b73c8abb79 Fix regression causing crash when history token search hits end
This is consistent with what we do for highlighting history search,
see d7354880e3 (Fix regression causing crash in token history search,
2025-01-27).  In future, we should try to find a better fix (and a
better test).

Fixes the other problem described in #11096
2025-01-27 18:13:07 +01:00
ccoVeille
90e916e164 Fix typo in tests 2025-01-26 20:30:48 -08:00
ccoVeille
b6a1bedab9 Fix typos in comments 2025-01-26 20:30:48 -08:00
Johannes Altmanninger
c651a79cb6 Fix regression causing builtin commandline to report wrong relative cursor
Regressed in 55fd43d86c (Port reader, 2023-12-22).

Fixes #11085
2025-01-26 15:51:05 +01:00
Johannes Altmanninger
64859fc242 Blocking wait for responses to startup queries
At startup we query for
- the cursor position (CSI 6 n)
- kitty keyboard protocol support (CSI ? u)
- terminfo capabilities via XTGETTCAP

Since we don't wait for responses, those can leak into child processes.
Some child processes like fzf cannot decode DCS replies.  Plug the
leak by ending each round of querying by asking for the Primary Device
Attribute, and resume input processing only after a response has been
received, (or ctrl-c as an escape hatch).

This is a nice simplification. Tested with the lowest common
denominator (putty, Terminal.app and st).

Fixes #11079
2025-01-26 14:22:52 +01:00
Johannes Altmanninger
06b49b9721 Update pexpect helper output sanitization 2025-01-26 14:19:40 +01:00
Fabian Boehm
eab9e647f4 checks/tmux-history-pager: Disable on CI in general
Keeps failing for timing reasons and it's already quite slow.

See #11036
2025-01-21 17:32:27 +01:00
Johannes Altmanninger
8208a12a76 Back out "Support help argument in "{ -h""
This backs out commit efce176ceb.
2025-01-19 18:57:21 +01:00
Johannes Altmanninger
d3c37de753 Back out "Always treat brace at command start as compound statement"
This backs out commit 98750e1ae5.
2025-01-19 18:57:21 +01:00
Johannes Altmanninger
92bd366c1b Back out "Allow if/then/fi, while/do/done and for/do/done"
This backs out commit e32572e4e6.
2025-01-19 18:57:13 +01:00
Fabian Boehm
5b0622cf00 Disable tmux-history-pager test on ASAN 2025-01-19 18:54:56 +01:00
Fabian Boehm
0494b1b608 tests/checks/exec: Match entire env line 2025-01-19 18:47:28 +01:00
Fabian Boehm
494bdfa013 Revert accidentally pushed fork
Revert "README for this fork"

This reverts commit 97db461e7f.

Revert "Allow foo=bar global variable assignments"

This reverts commit 45a2017580.

Revert "Interpret () in command position as subshell"

This reverts commit 0199583435.

Revert "Allow special variables $?,$$,$@,$#"

This reverts commit 4a71ee1288.

Revert "Allow $() in command position"

This reverts commit 4b99fe2288.

Revert "Turn off full LTO"

This reverts commit b1213f1385.

Revert "Back out "bind: Remove "c-" and "a-" shortcut notation""

This reverts commit f43abc42f9.

Revert "Un-hide documentation of non-fish shell builtins"

This reverts commit 485201ba2e.
2025-01-19 18:34:59 +01:00
Johannes Altmanninger
45a2017580 Allow foo=bar global variable assignments
override fixes
2025-01-19 18:29:07 +01:00