Commit Graph

19929 Commits

Author SHA1 Message Date
Johannes Altmanninger
6b5ad163d3 Fix double expansion of tokenized command line
Commit 798527d79a (completions: fix double evaluation of tokenized
commandline, 2024-01-06) fixed some completions such as the "watchexec"
ones by adding "string escape" here:

	set argv (commandline -opc | string escape) (commandline -ct)

This fixed double evaluation when we later call `complete -C"$argv"`.

Unfortunately -- searching for "complete -C" and
"__fish_complete_subcommand" -- it seems like that commit missed some
completions such as sudo.  Fix them the same way.

Alternatively, we could defer expansion of those arguments (via
--tokens-raw), since the recursive call to completion will expand
them anyway, and we don't really need to know their value.

But there are (contrived) examples where we do want to expand first,
to correctly figure out where the subcommand starts:

	sudo {-u,someuser} make ins

By definition, the tokens returned by `commandline -opc` do not
contain the token at cursor (which we're currently completing).
So the expansion should not hurt us. There is an edge case where
cartesian product expansion would produce too many results, and we
pass on the unexpanded input. In that case the extra escaping is very
unlikely to have negative effects.

Fixes # 11041
Closes # 11067

Co-authored-by: kerty <g.kabakov@inbox.ru>
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
7ad47c34e8 Fix regression causing scrollback-push to not clear text below cursor
If a child program crashes with some text rendered below the cursor,
we fail to clear that text. For example run vim, "pkill -9 vim" and
observe that scrollback-push fails to clean up the leftover text.
Fix that.
2025-01-19 18:29:07 +01:00
Ilya Grigoriev
a328fd995b Clarify __fish_complete_subcommand comment 2025-01-19 10:49:07 +01:00
Ilya Grigoriev
bcc69da569 tmux completions: complete shell commands 2025-01-19 10:49:07 +01:00
Dmitry Gerasimov
dfa77e6c19 completions/git: show custom aliases for --pretty option
Custom formats for --pretty/--format option can only be written in [pretty]
section, thus only this section is searched.

[ja: add ? to the regex]

Closes #11065
2025-01-19 10:48:01 +01:00
Dmitry Gerasimov
9752b83e65 completions/git: update supported git format options
--format=reference is supported since git 2.25
--format=mboxrd is supported since git 2.27
2025-01-19 10:48:01 +01:00
Ilya Grigoriev
4208798585 completions: add unbuffer completions
unbuffer is sometimes bundled with `expect` (which fish already ships
completions for), and sometimes is bundled separately. It's often
recommended for forcing colors to have color output.

https://manpages.debian.org/bookworm/expect/unbuffer.1.en.html

Ads for unbuffer:

https://wiki.archlinux.org/title/Color_output_in_console#Reading_from_stdin
https://jvns.ca/blog/2024/10/01/terminal-colours/
2025-01-19 10:46:55 +01:00
Mahmoud Al-Qudsi
8a6ba7fc4c Silence unused_imports on newer compilers 2025-01-18 17:10:51 -06:00
Fabian Boehm
f2d2632eca fixup! Add IsSomeAnd backport 2025-01-18 10:00:23 +01:00
Fabian Boehm
1123169bbd Remove some uses of unsafe
libc::getpid and getpgrp *cannot fail*, so an unsafe declaration here
is just noise.

I mean sure, if your libc is broken and these fail, but at that point
I'm comfortable declaring your computer a platypus that we do not need
to support.
2025-01-18 09:55:46 +01:00
Fabian Boehm
79320e3ba7 Remove some .unwrap() 2025-01-18 09:55:44 +01:00
Fabian Boehm
5d55dd9879 docs/fish: Add invocation examples 2025-01-17 20:27:36 +01:00
Fabian Boehm
fb2caf63e5 Fix error for "fish --foo" without option argument
Wgetopt needs a ":" at the beginning to turn on this type of error.

I'm not sure why that is now, and we might want to change it (but tbh
wgetopt could do with a replacement anyway).

Fixes #11049
2025-01-17 10:03:19 +01:00
Johannes Altmanninger
ba4ead6ead Stop saving autosuggestions that we can't restore
Sorry, commit 51adba6ee0 (Restore autosuggestion after corrected
typo, 2025-01-10) was pushed too early.  One issue is that it saves
autosuggestions also when we edit in the middle, where we can't
restore it.  We'd still restore it in some cases, even though it
doesn't apply. This breaks invariants that may cause various problems
when interacting with the autosuggestion.

Fix it by only saving the autosuggestion when we will be able to
restore it correctly.
2025-01-17 09:58:26 +01:00
Johannes Altmanninger
3d797b9eb8 Refactor autosuggestion saving lifecycle a bit 2025-01-17 09:58:26 +01:00
Fabian Boehm
1516c08e89 fmt 2025-01-16 19:55:59 +01:00
Fabian Boehm
6e6495664c Don't clone argv for builtins
We capture the process already, and we use argv by reference for the
other cases.

argv can be big, and this reduces allocations and thereby memory usage
and speed.

E.g. `set -l foo **` with 200k matches has 25% reduced memory usage
and ~5% reduced runtime.
2025-01-16 19:32:15 +01:00
Fabian Boehm
ced5569a25 format
I didn't touch these lines?
2025-01-16 16:42:52 +01:00
Fabian Boehm
37e3111069 Don't send modifyOtherKeys if kitty protocol is supported
No use in doing this and it would trigger an ugly log message from kitty.
2025-01-16 16:37:04 +01:00
Fabian Boehm
6126237bc4 Remove awkward assert
We should really stop asserting for things that at worst don't show an
autosuggestion.

Fixes #11055
2025-01-16 13:03:11 +01:00
Johannes Altmanninger
0cc7ee5511 Fix regression causing crash on unconsumed }
Fixes #11052
2025-01-16 04:40:21 +01:00
David Adam
dd2b9943a7 make_tarball: generate debug binaries
The extended build time isn't worth it for an executable which is run once then thrown away.
2025-01-15 23:29:42 +08:00
David Adam
d6e001ac7e fix tests for 24abbb6de7 2025-01-15 23:28:08 +08:00
David Adam
24abbb6de7 feature_flags: update target release for 3.8 flags to 4.0 2025-01-15 22:11:28 +08:00
Johannes Altmanninger
1bf2b43d30 Allow { } for command grouping, like begin / end
For compound commands we already have begin/end but

> it is long, which it is not convenient for the command line
> it is different than {} which shell users have been using for >50 years

The difference from {} can break muscle memory and add extra steps
when I'm trying to write simple commands that work in any shell.

Fix that by embracing the traditional style too.

---

Since { and } have always been special syntax in fish, we can also
allow

	{ }
	{ echo }

which I find intuitive even without having used a shell that supports
this (like zsh. The downside is that this doesn't work in some other
shells.  The upside is in aesthetics and convenience (this is for
interactive use). Not completely sure about this.

---

This implementation adds a hack to the tokenizer: '{' is usually a
brace expansion. Make it compound command when in command position
(not something the tokenizer would normally know). We need to disable
this when parsing a freestanding argument lists (in "complete somecmd
-a "{true,false}").  It's not really clear what "read -t" should do.
For now, keep the existing behavior (don't parse compound statements).

Add another hack to increase backwards compatibility: parse something
like "{ foo }" as brace statement only if it has a space after
the opening brace.  This style is less likely to be used for brace
expansion. Perhaps we can change this in future (I'll make a PR).

Use separate terminal token types for braces; we could make the
left brace an ordinary string token but since string tokens undergo
unescaping during expansion etc., every such place would need to know
whether it's dealing with a command or an argument.  Certainly possible
but it seems simpler (especially for tab-completions) to strip braces
in the parser.  We could change this.

---

In future we could allow the following alternative syntax (which is
invalid today).

	if true {
	}
	if true; {
	}

Closes #10895
Closes #10898
2025-01-15 11:18:46 +01:00
Johannes Altmanninger
349f62cd7c Sort enum-like AST nodes 2025-01-15 10:54:50 +01:00
Johannes Altmanninger
10dd8a8e73 Add range to closing-unopened brace error
The error on "echo }" is needlessly inconsistent with "echo )" and
"echo (}" etc; fix that I guess.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
3a6e87744b Minor formatting fixes 2025-01-15 10:54:18 +01:00
Johannes Altmanninger
67ccbdae96 Refine errors on "begin; case"
This will also give better errors for unbalanced braces (which are
sigils for begin/end), see a following commit.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
debfdf0a39 Fix inconsistent error message on quoted keyword
Commit bdfbdaafcc (Forbid subcommand keywords in variables-as-commands
(#10249), 2024-02-06) banned "set x command; $x foo" because the
parser will not recognize "$x" as decorator.
That means that we would execute only the builtin stub,
which usually exist only for the --help argument.

This scenario does not apply for keywords that are quoted or contain
line continuations. We should not treat «"command"» differently
from «command».  Fix this inconsistency to reduce confusion.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
6d18f57e96 Make ! a builtin too, fixing "! -h"
UnLike other aliases (":.["), ! is special in the grammar but in the
few cases like "! -h" where we parse it as decorated statement they
are equals. Add it to the built in list, so the help argument works.

It can still be overridden, so this should not break anything.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
373bb56441 Treat '!' as super-command (it's not reserved!)
Other sigil-aliases ('[' and '_') are reserved words that cannot be
redefined as function. Only '!' is not.

Whereas several users define "function !!", I
found only one public occurrence of "function !":
5c7f87ed07/fish/functions/!.fish

Note that "function !" only works if invoked as "!", "! -h" or
"! --help" or "foo | !".  In most other cases we parse it as negation.

We should probably make it a reserved word to reduce confusion.
If we do that, we should also add it to __fish_print_help, to make
"! -h" work.

For now let's rearrange the code so we can recognize "!" as
super-command. This fixes completion-based autosuggestions on "! ".
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
e678fb8578 Fix autosuggestions on quoted subcommand keyword
The commandline "and fis" rightly gets command autosuggestions whereas
"'and' fis" wrongly gets file autosuggestions.  The former works via
a hack. Extend it to quoted keywords.
2025-01-15 10:54:18 +01:00
Johannes Altmanninger
80a6ece45b Make newline after "else" optional
This makes it consistent with "else if", and with other shells.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
f5b2928cbb Refactor subcommand keyword detection
This file has bitrotted; for example commit bc66921ac9 (Optimize
keyword detection, 2019-04-03) removed use of SKIP_KEYWORDS but
confusingly it's still around (even after 0118eafee1 (Remove unused
functions, members (and a variable), 2022-04-09).

Also some keywords appear in multiple lists; the separate lists are
not really used today; there is a comment stating they may be useful
in future.

It would be great to add an optimization back but either way we should
present the set of reserved words in source code as a contiguous list,
to make it easy for humans to see all relevant information.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
c7adb572d0 Address clippy lints 2025-01-15 10:53:09 +01:00
Johannes Altmanninger
de6c4f85bc Don't put every enum-like AST nodes in a box
StatementVariant needs an indirection because for example NotStatement
may contain another whole statement (error[E0072]: recursive type
has infinite size).

This is dealt with by putting each StatementVariant in a Box.
This Box was also used by the AST walk implementation to implement
tagged dispatched for all variant AST nodes (see "visit_union_field").
Because of this, all other variant AST are boxed the same way, even
though they may not by cyclic themselves.

Reduce confusion by boxing only around the nodes that are actually
recursive types, and use a different tag for static dispatch.
This means that simple nodes like most normal commands and arguments
need one fewer allocation.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
9fd1fd366c Remove stale todo comment
This has been fixed.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
24a32d5202 Fix format string for internal parser error 2025-01-15 10:53:09 +01:00
Johannes Altmanninger
3695c349c6 Note "Restore autosuggestion after corrected typo" in changelog
Seems easy enough to explain, and somewhat noticeable. Let's see if
it causes problems.
2025-01-15 10:53:09 +01:00
Johannes Altmanninger
40f5aac764 Fix forward-token hiccup at operators
For better or worse, backward-token completely skips over operators
like > & |.
forward-token is (accidentally?) inconsistent with that. Fix that.

Skipping over those tokens might be wrong weird.  Maybe not for
redirections since they are tighly coupled to their target.  Maybe we
can improve this in future.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
674b7b6f92 Reject commandline --search-field --tokens*
As of today, it makes no sense to tokenize the search field.
We already reject arguments like --current-process.
Extend that to the --tokens family.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
6f480d1d85 Also trim trailing newlines when adding to history
When pasting and executing a full line, the trailing newline character
will be included in history.

I usually manually delete the newline before executing, but sometimes
I forget. When I recall my (typically single-line) commands, it's
surprising that the cursor is on the blank second line.

The newline doesn't seem useful. Let's remove it automagically.
I wonder if anyone will be thrown off by this smart behavior.

In future, we can make this space trimming configurable, similar to
fish_should_add_to_history.
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
081c3282b7 Refresh TTY timestamps also in some rare cases
As mentioned in
https://github.com/fish-shell/fish-shell/pull/11045#discussion_r1915994998,
we need to refresh TTY timestamps to avoid timing-based issues.

For some context see

	git log --grep='[Rr]efresh.* TTY'

Make things more consistent again. I don't know if all of these are
absolutely necessary, hoping to find out later (and consolidate this
logic in outputter).
2025-01-15 10:52:43 +01:00
Johannes Altmanninger
2e025cfd76 Sort match statement 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
4e29dba1d5 Minimize logic 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
c4b4e90031 Fix file completions for builtin fish_indent 2025-01-15 10:52:43 +01:00
Johannes Altmanninger
c12f853db2 Reformat share/{completions,functions} 2025-01-15 10:50:04 +01:00
kerty
f139d8ebed Improve mouse support
Some checks failed
make test / ubuntu (push) Has been cancelled
make test / ubuntu-32bit-static-pcre2 (push) Has been cancelled
make test / ubuntu-asan (push) Has been cancelled
make test / macos (push) Has been cancelled
Rust checks / rustfmt (push) Has been cancelled
Rust checks / clippy (push) Has been cancelled
Lock threads / lock (push) Has been cancelled
2025-01-15 00:52:15 +01:00
kerty
a0e687965e Fix unsaved screen modification 2025-01-15 00:52:15 +01:00