Commit Graph

2041 Commits

Author SHA1 Message Date
Johannes Altmanninger
156fa8081c Underline styles for double/dotted/dashed
My phone uses dotted underline to indicate errors; that seems nice, a bit
less aggressive than curly.  Unfortunately dotted underlines are not as well
supported in terminal emulators; sometimes they are barely visible.  So it's
unlikely that we want to use --underline=dotted for an important theme.
Add double and dashed too I guess, even though I don't have a concrete
use case..
2025-05-11 22:18:06 +02:00
Johannes Altmanninger
80e30ac756 Always treat brace at command start as compound statement
For backwards compatibility, fish does not treat "{echo,hello}" as a compound
statement but as brace expansion (effectively "echo hello").  We interpret
"{X...}" as compound statement only if X is whitespace or ';' (which is an
interesting solution).

A brace expansion at the very start of a command 
is usually pointless (space separation is shorter).
The exception are cases where the command name and the first few arguments
share a suffix.

	$ {,1,2,3,4}echo
	1echo 2echo 3echo 4echo

Not sure if anyone uses anything like that.  Perhaps we want to trade
compatibility for simplicity. I don't have a strong opinion on this.

Always parse the opening brace as first character of a command token as
compound statement.
Brace expansion can still be used with a trick like: «''{echo,foo}»

Closes #11477
2025-05-11 22:00:43 +02:00
Johannes Altmanninger
cc2ca60baa commandline.rst: deprecate --tokens-raw option
This was added without a use case.  Now there is a use case (#11084) that
needs it to include all tokens which the sister option "--tokens-expanded"
should not do.  The inconsistency is probably not worth it, given that this
"--tokens-raw" use case can be served by a future "read -zal --tokenize-raw".
2025-05-11 12:46:08 +02:00
Ethan Fredsti
1e61e6492d fixed typo mentioned in issue #11454
I found the same typo mentioned in issue #11454 in this file and proposed the suggested change.
2025-05-04 19:52:06 -07:00
Bergbok
83b10c3919 Rephrase set_color tutorial docs
Closes #11446
2025-05-04 11:56:14 +02:00
Johannes Altmanninger
4a3fc5211f Document workaround for making tab focus search field
Closes #11450
Closes #11449
2025-05-04 11:56:14 +02:00
Johannes Altmanninger
7c25d6a1ba Merge pull request #11443 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
0950cd1598 Merge pull request #11422 2025-05-03 14:15:33 +02:00
Axlefublr
91b9bbf651 fix single backticks 2025-05-03 19:26:07 +08:00
Fabian Boehm
8048e38ea4 docs: Actually document commandline --input
This is a useful option and has been a thing for years.
2025-05-02 20:55:36 +02:00
Axlefublr
1d69226c58 preciser wording for builtin crossmode alt+p binding 2025-05-01 13:58:18 +08:00
Johannes Altmanninger
1122bba3c1 Fix typo in docs 2025-04-29 13:51:18 +02:00
Johannes Altmanninger
829709c9c4 Replace synchronized update workaround
Old versions of ConHost and Putty can't parse DCS sequences.
For this reason, we briefly switch to the alternate screen buffer while sending
DCS-format (e.g. XTGETTCAP) queries. For extra paranoia, we wrapped this
procedure in a synchronized update. This doesn't seem to be needed; neither
ConHost nor Putty show glitches when the synchronized update is omitted.

As of today, every terminal that implements XTGETTCAP also implements
synchronized updates but that might change.

Let's remove it, to reduce surprise for users and terminal developers.

As a bonus, this also fixes a glitch on Terminal.app which fails to parse
the synchronized-update query (`printf '\x1b[?2026$p'`) and echoes the "p"
(bug report ID FB17141059). Else we could work around this with another
alternate screen buffer.

Unfortunately, this change surfaces two issues with GNU screen.  For one,
they don't allow apps to use the alternate screen features (the user may
allow it with "altscreen on"). Second, screen unconditionally echoes
the payload of DCS commands.  A possible fix has been suggested at
https://lists.gnu.org/archive/html/screen-devel/2025-04/msg00010.html

I think this combination of behaviors is unique among terminals.  I'm sure
there are more terminals that don't parse DCS commands yet, but I think almost
all terminals implement alternate screen buffer. Probably only terminal
multiplexers are prone to this issue. AFAICT very few multiplexers exists,
so we can work around those until they are fixed.

Disable XTGETTCAP queries for GNU screen specifically.  Unfortunately screen
does not implement XTVERSION, so I don't know how to reliably identify
it. Instead, check STY and some commonly-used values TERM values.
This has false negatives in some edge cases.
But the worst thing that happens is that "+q696e646e" will be echoed once
at startup, which is easy to ignore, or work around with something like

	function workaround --on-event fish_prompt
		commandline -f repaint
		functions --erase workaround
	end

which I don't think we should apply by default, because it can mask other
issues.

We should give screen more time to respond. I guess I'll open an issue so
we don't forget. In doubt, we can always go back to the previous approach
(but implement it in fish script).

Alternative workaround: instead of the alternative screen buffer, we could
try something like clr_eol/clr_bol to erase the spuriously echoed text. I
tried to do this in various ways but (surprisingly) failed.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
7bdb561d24 builtin set_color: stop resetting unrelated attributes on --background=normal
"set_color --background=normal" resets all attributes.  I don't expect anyone
relied on this behavior. Let's remove it, to reduce surprise.  This also
improves consistency with "set_color --underline-color=normal".

As suggested in
https://github.com/fish-shell/fish-shell/issues/11417#issuecomment-2825023522

For backwards compatibility reasons, "set_color normal" still resets
everything though.  In future we could make "set_color --foreground=normal"
reset only foreground.

Closes #11418
2025-04-29 10:14:32 +02:00
Johannes Altmanninger
1f944c1c54 set_color.rst: update docs on fallback colors
Commit 6fcb418ae3 (Enable 24-bit RGB colors by default, 2025-04-11)
invalidated some documentation about fallback colors; by default we prefer
RGB unless the user has explicitly set fish_term256=0.

Note that this made fallback colors much less useful, because they are only
active if the user sets fish_term256=0.  Note that setting fish_term24bit=0
is *not* enough; in that case we use the 256 color palette (and assume that
it is a subset of the 24-bit colors).

We do have some themes that use fallback colors:

	fish_pager_color_description B3A06D yellow

By default, those will be less useful now.

See also https://github.com/fish-shell/fish-shell/issues/11393
2025-04-25 14:07:10 +02:00
Johannes Altmanninger
05508fa551 set_color.rst: remove redundant documentation
Also clarify that only a foreground "normal" resets everything (at least
with https://github.com/fish-shell/fish-shell/pull/11418)
2025-04-25 13:04:16 +02:00
Fabian Boehm
2f9d5ac7d6 docs: Correct "cancel"
This never, AFAIK, emptied the commandline, and I don't think that
would be a sensible thing to do
2025-04-24 19:54:39 +02:00
Anton Bilous
b7b1753716 Mention replace mode in fish_mode_prompt docs 2025-04-24 16:26:45 +03:00
Anton Bilous
0349a70321 Fix typo in language docs 2025-04-23 21:07:31 +08:00
Johannes Altmanninger
ce631fd2fb Colored underlines in set_color and fish_color_*
Add a new underline-color option to set_color (instead of adding an optional
color argument to --underline); this allows to set the underline color
independently of underline style (line, curly, etc.). I don't think this
flexibility is very important but this approach is probably the least hacky.

Note that there are two variants:
1. \e[58:5:1m
2. \e[58;5;1m

Variant 1 breaks:
breakage from colon-variant for colored underlines
- cool-retro-term makes text blink
- GNU screen (goes into bold mode)
- terminology (goes into bold mode)

Variant 2 would break:
- mintty (Cygwin terminal) -- it enables bold font instead.
- Windows Terminal (where it paints the foreground yellow)
- JetBrains terminals echo the colons instead of consuming them
- putty
- GNU screen (goes into bold mode)
- st
- urxvt
- xterm
- etc.

So choose variant 1.

Closes #11388
Closes #7619
2025-04-21 18:38:11 +02:00
Johannes Altmanninger
cc9849c279 Curly underlines in set_color and fish_color_*
set_color --underline=curly outputs \e[4:3m which breaks the following
terminals:
- Terminal.app interprets it as yellow background
- abduco and dvtm interpret it as green foreground
- JetBrains terminals interprets it as yellow background
- urxvt interprets it as yellow background

terminals that interpret curly as single underline:
- tmux [1]
- emacs ansi-term [2]
- emacs vterm
- GNU screen (also wrongly turns on italic mode)
- terminology (also wrongly turns on italic mode)
- Vim's :terminal

[1]: https://github.com/orgs/tmux/discussions/4477
[2]: https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-04/msg01093.html

Closes #10957
2025-04-21 18:12:42 +02:00
Johannes Altmanninger
ef25f1d27b Break up long line 2025-04-21 18:11:44 +02:00
Johannes Altmanninger
6cf96c5950 sgr0 *does* reset both foreground and background color
We have a a workaround with a comment saying

> We don't know if exit_attribute_mode resets colors, so we set it to
> something known.

I'm pretty sure fish (and other software) makes this assumption.
I'd be very surprised if a relevant terminal behaves differently.
Let's remove our attempt to work around around this.

While at it, extract a function to be used in two other places
(but don't change their behavior yet).
2025-04-21 17:37:36 +02:00
Fabian Boehm
ca8416f18d docs/bind: Fix typo
Fixes #11408
2025-04-20 21:54:57 +02:00
Johannes Altmanninger
afa517d907 doc/terminal-compatibility: document cursor shaping sequence
While at it, also document the command to reset the shape to the default,
which we should probably use.  See foot commit 49034bb7 (csi: let CSI 0 q mean
"switch to user configured cursor style", 2019-07-22).

As of today, the XTerm documentation is a not clear on this; in
XTerm itself, CSI 0 q may actually change the cursor because they have an
additional default cursor is configured differently..
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
b569f0d62f Update docs for transient prompt
Closes #11153
2025-04-12 12:09:08 +02:00
kerty
b3e417fd05 Add documentation for transient prompt 2025-04-12 12:07:26 +02:00
Johannes Altmanninger
6fcb418ae3 Enable 24-bit RGB colors by default
I think `set_color ff0000` should default to outputting true-color sequences.
Unfortunately there is no good and widely-supported way to query for true-color
support.  `COLORTERM=truecolor` doesn't work in some cases such as ssh.

Since many terminals nowadays implement the RGB sequences, let's try using
them by default.

Note that Emacs's ansi-term implements truecolor now.

See also the discussion around
https://github.com/fish-shell/fish-shell/pull/11345#issuecomment-2794920900

Closes #11372
2025-04-11 22:20:45 +02:00
Fabian Boehm
ee2a6a851d Document and complete status get-file/list-files 2025-04-11 17:29:22 +02:00
Fabian Boehm
2a1c5b18e8 Remove --install option
This is no longer useful, given that we read files from in the binary.

In the upcoming commits, this can be done with status list-files/get-file if you need it
2025-04-11 17:29:22 +02:00
Johannes Altmanninger
17b4b39c8b Stop reading terminfo database
Our use of the terminfo database in /usr/share/terminfo/$TERM is both
1. a way for users to configure app behavior in their terminal (by
   setting TERM, copying around and modifying terminfo files)
2. a way for terminal emulator developers to advertise support for
   backwards-incompatible features that are not otherwise easily observable.

To 1: this is not ideal (it's very easy to break things). There's not many
things that realistically need configuration; let's use shell variables
instead.

To 2: in practice, feature-probing via terminfo is often wrong.  There's not
many backwards-incompatible features that need this; for the ones that do
we can still use terminfo capabilities but query the terminal via XTGETTCAP
directly, skipping the file (which may not exist on the same system as
the terminal).

---

Get rid of terminfo. If anyone finds a $TERM where we need different behavior,
we can hardcode that into fish.

* Allow to override this with `fish_features=no-ignore-terminfo fish`
  Not sure if we should document this, since it's supposed to be removed soon,
  and if someone needs this (which we don't expect), we'd like to know.
  * This is supported on a best-effort basis; it doesn't match the previous
    behavior exactly.  For simplicity of implementation, it will not change
    the fact that we now:
    * use parm_left_cursor (CSI Ps D) instead of  cursor_left (CSI D) if
      terminfo claims the former is supported
    * no longer support eat_newline_glitch, which seems no longer present
      on today's ConEmu and ConHost
* Tested as described in https://github.com/fish-shell/fish-shell/pull/11345#discussion_r2030121580
* add `man fish-terminal-compatibility` to state our assumptions.
  This could help terminal emulator developers.
* assume `parm_up_cursor` is supported if the terminal supports XTGETTCAP
* Extract all control sequences to src/terminal_command.rs.
* Remove the "\x1b(B" prefix from EXIT_ATTRIBUTE_MODE. I doubt it's really
  needed.
* assume it's generally okay to output 256 colors
  Things have improved since commit 3669805627 (Improve compatibility with
  0-16 color terminals., 2016-07-21).
  Apparently almost every actively developed terminal supports it, including
  Terminal.app and GNU screen.
  * That is, we default `fish_term256` to true and keep it only as a way to
    opt out of the the full 256 palette (e.g. switching to the 16-color
    palette).
    * `TERM=xterm-16color` has the same opt-out effect.
* `TERM` is generally ignored but add back basic compatiblity by turning
  off color for "ansi-m", "linux-m" and "xterm-mono"; these are probably
  not set accidentally.
* Since `TERM` is (mostly) ignored, we don't need the magic "xterm" in
  tests. Unset it instead.
* Note that our pexpect tests used a dumb terminal because:
  1. it makes fish do a full redraw of the commandline everytime, making it
     easier to write assertions.
  2. it disables all control sequences for colors, etc, which we usually
     don't want to test explicitly.
  I don't think TERM=dumb has any other use, so it would be better
  to print escape sequences unconditionally, and strip them in
  the test driver (leaving this for later, since it's a bit more involved).

Closes #11344
Closes #11345
2025-04-11 15:11:22 +02:00
Fabian Boehm
eb4a0b2560 docs: Fix string-match glob examples
`?` no longer is a wildcard.

See #11361
2025-04-08 17:13:18 +02:00
Johannes Altmanninger
fb2d427a45 Remove "bind -k" terminfo key names, update "bind --key-names"
I don't think there's a relevant terminal where the "bind -k" notation is
still needed. The remaining reason to keep it is backwards compatibility.

But "bind -k" is already subtly broken on terminals that implement either
of modifyOtherKeys, application keypad mode or the kitty keyboard protocol,
since those alter the byte sequences (see #11278).

Having it randomly not work might do more harm than good. Remove it.

This is meant go into 4.1, which means that users who switch back and forth
between 4.1 and 4.0 can already use the new notation.

If someone wants to use the bind config for a wider range of versions they
could use "bind -k 2>/dev/null" etc.

While at it, use the new key names in "bind --key-names", and sort it like
we do in "bind --function-names".

Closes #11342
2025-04-02 01:05:51 +02:00
Johannes Altmanninger
26ca12d5af docs/bind.rst: add missing named keys 2025-04-02 00:53:48 +02:00
Fabian Boehm
6dcead7be5 docs: Make --wraps clearer
Fixes #11317
2025-03-30 19:42:00 +02:00
Fabian Boehm
6ead168c82 docs: Remove "just"/"simply" weasel words
Text like "simply do" or "just press" is patronizing and unnecessary.
The prose is nicer if it's removed, and in some cases other words are
more specific.

Something like "we'll pretend your prompt is just a ``>``" can stay.
2025-03-28 20:12:58 +01:00
Fabian Boehm
d88f5ddbaf docs: Readd bind -k to the docs
Fixes #11329
2025-03-27 15:56:09 +01:00
carsonzhu
4ce552bf94 Token search commands that only match the last token in each line
This add two commands history-last-token-search-backward and
history-last-token-search-forward which behaves like bash's yank-last-arg. So
similar to history-token-search-* but only considers the last argument for
each command.

Closes #10756
Closes #11258
2025-03-15 21:54:47 +01:00
Fabian Boehm
65eb6cfbfe docs: Remove pre-2.4 caveats
2.4 is almost 9 years old and 69% of commits to fish behind. It is
well past worth mentioning.
2025-03-15 16:36:13 +01:00
lengyijun
517b02899a doc: bind ctrl-c clear-commandline 2025-03-15 10:58:34 +01:00
David Adam
3c8e058b75 docs/fish_title: add example on disabling title changing
Work on #11241.
2025-03-12 14:36:40 +08:00
Fabian Boehm
30fa57022a docs: Switch link from gitter to matrix
Gitter is now useless,  matrix is a known thing that people may have
clients and accounts for already
2025-03-05 22:34:38 +01:00
Fabian Boehm
9f5e1736a8 key: Add super modifier
Fixes #11217
2025-03-04 17:00:26 +01:00
Johannes Altmanninger
2bb5cbc959 Default bindings for token movements v2
Commit 6af96a81a8 (Default bindings for token movement commands, 2024-10-05)
has been reverted but not all docs have been.

Key bindings to move by command line argument are quite intuitive, and useful
when moving across URLs or other long arguments.

We have redundant bindings like {alt,ctrl}-left, so let's use one of them
for token movement.  We don't want to break the OS-native shortcut for word
movement, so use the other one on the current platform.

Note that Sublime Text does something similar: it uses the native key
binding for word movement, and the vacant one (e.g. `alt-left` on Linux)
for sub-word movement in camel case words.

While there have been 2.5 votes against making this platform dependent,
the majority of feedback was in favor.

This uses uname which seems wrong; we should rather use the OS that the
terminal is running on. I plan to implement this in future, but there's no
consensus yet on whether terminal applications should be allowed to do this.

See #10926
See #11107
2025-03-04 11:44:47 +01:00
Johannes Altmanninger
495083249b Fix regression causing cursor shape commands to leak into noninteractive shell
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$CLuoHTdvcRj_8-HBBq0p-lmGWeix5khEtKEDxN2Ulfo

Running

	fish -C '
		fzf_key_bindings
		echo fish_vi_key_bindings >>~/.config/fish/config.fish
		fzf-history-widget
	'

and pressing "enter" will add escape sequences like "[2 q" (cursor shape)
to fish's command line.

This is because fzf-history-widget binds "enter" to a filter
that happens to be a fish script:

	set -lx FZF_DEFAULT_OPTS \
		... \
		"--bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'" \
		'--with-shell='(status fish-path)\\ -c)

The above ~/.config/fish/config.fish (redundantly) runs "fish_vi_key_bindings"
even in *noninteractive* shells, then "fish_vi_cursor" will print cursor
sequences in its "fish_exit" handler.  The sequence is not printed to the
terminal but to fzf which doesn't parse CSI commands.

This is a regression introduced by a5dfa84f73 (fish_vi_cursor: skip if stdin
is not a tty, 2023-11-14). That commit wanted "fish -c read" to be able to
use Vi cursor.  This is a noninteractive shell, but inside "read" we are
"effectively interactive".  However "status is-interactive" does not tell
us that.

Let's use a more contained fix to make sure that we print escape sequences only
if either fish is interactive, or if we are evaluating an interactive read.

In general, "fish -c read" is prone to configuration errors, since we
recommend gating configuration (for bind etc) on "status is-interactive"
which will not run here.
2025-03-02 09:34:06 +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
Fabian Boehm
20e9fe9c95 Revert token movement bindings
Comments by macOS users have shown that, apparently, on that platform
this isn't wanted.

The functions are there for people to use,
but we need more time to figure out if and how we're going to bind
these by default.
For example, we could change these bindings depending on the OS in future.

This reverts most of commit 6af96a81a8.

Fixes #10926
See #11107

(cherry picked from commit 378f452eaa)
2025-02-27 21:10:07 +01:00
David Adam
b82d0fcbcc docs/source: document changes from #10774 2025-02-26 21:30:57 +08:00
David Adam
8ec1a3e7b9 docs/bind: improve description of cancel binding
Closes #9644
2025-02-26 21:23:40 +08:00
Fabian Boehm
750fe3bcc1 docs/bind: More on how default mode is normal mode 2025-02-20 19:08:24 +01:00