Compare commits

...

4539 Commits

Author SHA1 Message Date
Johannes Altmanninger
0c7062def9 WIP cirrus: trigger after github action finishes
(TODO this is totally untested and mostly vibe coded.)

Whenever we push changes do docker/**, our docker images for Cirrus
CI will be rebuilt.

However, the Cirrus CI jobs will kick off at the same time as the
Docker builds, so they will likely use old images.  This can cause
surprising (albeit transient) failures.

Fix this by having Cirrus wait for GitHub Actions.

This addresses the second part of
https://github.com/fish-shell/fish-shell/pull/11884#discussion_r2423344925
2025-10-12 08:41:14 +02:00
Johannes Altmanninger
8a4a8bb6a0 cirrus: disable jammy-armv7-32bit for now
This fails with "exec format error" because our container is built
on a 64 bit system on GitHub Actions.  Not yet sure how to fix that.
2025-10-12 07:17:48 +02:00
David Adam
e1b064f6cc Bravely revert "CI: Disable some Cirrus CI jobs during RIIR transition"
This reverts what remains of commit
91be7489bc.

Closes #11871
Closes #11884
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
68a8cd4501 cirrus.yml: switch back to org docker image paths
These should work now that we have (automatically-updated) docker
builds via .github/workflows/docker_builds.yml.

Ref: https://github.com/fish-shell/fish-shell/pull/11884#discussion_r2405536855
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
5f0d83d2f2 cirrus: remove "file" dependency from focal-arm64 builds
Probably that was also part of --install-recommends.
fish requires "file", but system tests don't.
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
03f54171c6 cirrus: delete commented configurations 2025-10-12 07:17:48 +02:00
Johannes Altmanninger
f391b4a179 docker: add back CMake for the images used in Cirrus
build_tools/check.sh would give more coverage (the translation
checks is the main difference) but it tests embed-data builds;
for now testing, traditionally installed builds is more important
(especially since I always test check.sh locally already). In future
we will probably make embedding mandatory and get rid of this schism.
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
8db674b6b5 docker: fix SSL error
Cirrus builds fail with

	error: failed to get `pcre2` as a dependency of package `fish v4.1.0-snapshot (/tmp/cirrus-ci-build)`
	...
	Caused by:
	  the SSL certificate is invalid; class=Ssl (16); code=Certificate (-17)

Likely introduced by b644fdbb04 (docker: do not install recommended
packages on Ubuntu, 2025-10-06).  Some Ubuntu Dockerfiles already
install ca-certificates explicitly but others do not. Fix the latter.
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
f03113d048 __fish_cache_put: fix for BusyBox stat
On alpine, tests/checks/check-completions fails with

	stat: can't read file system information for '%u:%g': No such file or directory
2025-10-12 07:17:48 +02:00
Johannes Altmanninger
6c48e214ca tests/checks/check-completions: fix for embed-data builds 2025-10-12 07:17:48 +02:00
Johannes Altmanninger
189a2e90dd __fish_print_commands: remove code clone
Also, use it for help completions also on embed-data builds.
2025-10-12 07:11:35 +02:00
Johannes Altmanninger
9b44138917 __fish_print_commands: fix environment variable injection 2025-10-12 07:08:24 +02:00
Johannes Altmanninger
ec7d20b347 Reapply "test_driver: support Python 3.8 for now"
Re-apply commit ec27b418e after it was accidentally reverted in
5102c8b137 (Update littlecheck, 2025-10-11),
fixing a hang in e.g.

	sudo docker/docker_run_tests.sh docker/jammy.Dockerfile
2025-10-12 07:01:36 +02:00
Peter Ammon
84b52a3ed1 Resurrect some Dockerfiles
Add missing black and rustfmt
2025-10-11 12:24:20 -07:00
Peter Ammon
30b1c9570f Suppress a deprecation warning on time_t
Continue to pull cirrus builds back into the land of the living.
2025-10-11 12:24:20 -07:00
Johannes Altmanninger
b88622bc35 tests/tmux-job: fix on macOS CI
The rapid input can make the screen look like this:

    fish: Job 1, 'sleep 0.5 &' has ended
    prompt 0> echo hello world
    prompt 0> sleep 3 | cat &
    bg %1 <= no check matches this, previous check on line 24
2025-10-11 18:02:57 +02:00
Johannes Altmanninger
a4edb4020d test_driver.py: output as tests/checks/... not checks/...
Something like

	tests/test_driver.py target/debug checks/foo.fish

is invalid (needs "tests/checks/foo.fish").
Let's make failure output list the right fiel name.

At least when run from the root directory.
Don't change the behavior when run from "tests/";
in that case the path was already relative.
2025-10-11 17:56:31 +02:00
Johannes Altmanninger
e1e5dfdd62 test_driver: don't chdir in async driver
The test driver is async now; so we can't change the process-wide
working directory without causing unpredictable behavior.
For example, given these two tests:

	$ cat tests/checks/a.fish
	#RUN: %fish %s
	#REQUIRES: sleep 1
	pwd >/tmp/pwd-of-a

	$ cat tests/checks/b.fish
	#RUN: %fish %s
	pwd >/tmp/pwd-of-b

running them may give both fish processes the same working directory.

	$ tests/test_driver.py target/debug tests/checks/a.fish tests/checks/b.fish
	tests/checks/b.fish  PASSED      13 ms
	tests/checks/a.fish  PASSED    1019 ms
	2 / 2 passed (0 skipped)
	$ grep . /tmp/pwd-of-a /tmp/pwd-of-b
	/tmp/pwd-of-a:/tmp/fishtest-root-1q_tnyqa/fishtest-s9cyqkgz
	/tmp/pwd-of-b:/tmp/fishtest-root-1q_tnyqa/fishtest-s9cyqkgz
2025-10-11 17:56:31 +02:00
Johannes Altmanninger
5102c8b137 Update littlecheck
Commit c12b8ed (Clean up some lints, 2025-08-28)
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
9ae9db7f70 test_driver: fix code clone 2025-10-11 17:54:09 +02:00
Johannes Altmanninger
d0aaa8d809 create_manpage_completions: fix deprecation warning
Fixes #11930
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
6024539c12 CI lint: consolidate clippy definitions 2025-10-11 17:54:09 +02:00
Johannes Altmanninger
fb06ad4a44 Update sourcehut build images 2025-10-11 17:54:09 +02:00
Johannes Altmanninger
598e98794c Fixes for tmux-fish_config.fish
This fails sometimes in high-concurrency scenarios
(build_tools/check.sh), so allow sleeping a bit longer.
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
b3a295959d webconfig: remove obsolete macOS workaround
As mentioned in #11926 our "fish_config" workaround for macOS
10.12.5 or later has been fixed in macOS 10.12.6 according to
https://andrewjaffe.net/blog/2017/05/python_bug_hunt/, I think we
can assume all users have upgraded to that patch version Remove
the workaround.
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
50dfd962ec Document system test dependencies
Notably, the parent commit adds wget.

While at it, extract a reusable action.
2025-10-11 17:54:09 +02:00
Nahor
65332eaacc Add test for fish_config in browser modified
In particular
- test that it will return an error if the URL is invalid
- that the main page matches the index.html in git
- that "Enter" key will exit

Part of #11907
2025-10-11 17:54:09 +02:00
Nahor
a00e6f8696 Add Github action to compile for MSYS2
Closes #11907
2025-10-11 17:54:09 +02:00
Nahor
6415dfbd35 Ensure different network ports in fish_config
- Windows allows port reuse under certain conditions. In fish_config
case, this allows the signal socket to use the same port as http (e.g.
when using MINGW python). This can cause some browsers to access the
signal socket rather than the http one (e.g. when connecting using
IPv4/"127.0.0.1" instead of IPv6/"::1").
- This is also more efficient since we already know that all ports up to
and including the http one are not available

Fixes #11805

Part of #11907
2025-10-11 17:54:09 +02:00
Nahor
8c387c58de Fix build for MSYS2 (missing ulimits)
Part of #11907
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
da411f6fa7 bg/fg/wait/disown/function: check for negative PID argument
While at it, extract a function.

Seems to have regressed in 4.0.0 (fc47d9fa1d (Use strongly typed
`Pid` for job control, 2024-11-11)).

Fixes #11929
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
8fe402e9f7 fg: remove rogue abs() on PID argument
Present since the initial commit but I don't think anyone relies
on this.
2025-10-11 17:54:09 +02:00
Johannes Altmanninger
c41fc52077 bg: deduplicate job argument
"bg %1" of a pipline prints the same line twice because it tries
to background the same job twice.  This doesn't make sense and
other builtins like "disown" already deduplicate, so do the same.
Unfortunately we can't use the same approach as "disown" because we
can't hold on to references to job, since we're modifying the job list.
2025-10-11 17:53:30 +02:00
Johannes Altmanninger
f7d730390c Rename process id -> process ID 2025-10-11 11:47:34 +02:00
Johannes Altmanninger
8fc30d5243 po/fr.po: delete bad translation 2025-10-11 11:47:16 +02:00
Isaac Oscar Gariano
93c4d63295 Allow overwriting argv with function -a and -V
Previously, if you called a function parameter 'argv', within the body
of the function, argv would be set to *all* the arguments to the
function, and not the one indicated by the parameter name.
The same behaviour happened if you inherited a variable named 'argv'.
Both behaviours were quite surprising, so this commit makes things more
obvious, although they could alternatively simply be made errors.

Part of #11780
2025-10-11 10:51:36 +02:00
Isaac Oscar Gariano
7a07c08860 Output function argument-names in one group.
This makes it so that printing a function definition will only use one
--argument-names group, instead of one for argument name.
For example, "function foo -a x y; ..." will print with "function foo
--argument-names x y" instead of "function foo --argument-names x
--argument-names y", which is very bizarre.

Moreover, the documentation no longer says that argument-names "Has to
be the last option.". This sentence appears to have been introduced in
error by pull #10524, since the ability to have options afterwards was
deliberately added by pull #6188.

Part of #11780
2025-10-11 10:50:07 +02:00
Isaac Oscar Gariano
1cf110d083 Use idiomatic Rust error handling for function builtin.
This simply does the same thing as #10948, but for the function builtin.

Part of #11780
2025-10-11 10:46:21 +02:00
Johannes Altmanninger
fef358fc74 Move remaining builtin implementations to dedicated files
This makes them a bit easier to find I guess.
2025-10-11 09:40:37 +02:00
Daniel Rainer
b5feb79a7c style: format entire repo by default
We want all Rust and Python files formatted, and making formatting
behavior dependent on the directory `style.fish` is called from can be
counter-intuitive, especially since `check.sh`, which also calls
`style.fish` is otherwise written in a way that allows calling it from
arbitrary working directories and getting the same results.

Closes #11925
2025-10-10 10:36:52 +02:00
Daniel Rainer
4d52245617 ci: run style.fish
This allows checking formatting of fish script and Python files, in
addition to Rust files.

Closes #11923
2025-10-10 10:36:52 +02:00
Daniel Rainer
ff308b36af ci: rename workflows
The new names are consistently formulated as commands.

`main` is not very descriptive, so change it to `test`, which is more
informative and accurate.

`rust_checks` are replaced be the more general `lint` in preparation for
non-Rust-related checks.

These changes were suggested in
https://github.com/fish-shell/fish-shell/pull/11918#discussion_r2415957733

Closes #11922
2025-10-10 10:36:08 +02:00
Johannes Altmanninger
fa8cf8a1a5 abbr: fix extra Chinese translation
Closes #11919
2025-10-09 18:12:04 +02:00
Daniel Rainer
5ade4a037e style: replace black with ruff for Python formatting
Ruff's default format is very similar to black's, so there are only a
few changes made to our Python code. They are all contained in this
commit. The primary benefit of this change is that ruff's performance is
about an order of magnitude better, reducing runtime on this repo down
to under 20ms on my machine, compared to over 150ms with black, and even
more if any changes are performed by black.

Closes #11894

Closes #11918
2025-10-09 18:12:03 +02:00
Johannes Altmanninger
861002917a tests/checks/po-files-well-formed: fix inconsistent msgfmt check 2025-10-09 18:12:03 +02:00
Fabian Boehm
eddb26d490 completions/ssh: Don't read ":" from historical hosts
Fixes #11917
2025-10-09 17:14:09 +02:00
Johannes Altmanninger
b7fe3190bb Revert "builtin function: remove dead code"
This reverts commit 993b977c9b.

Fixes #11912
2025-10-08 10:51:47 +02:00
Johannes Altmanninger
b6ddb56cc7 release.sh: fix milestone API calls 2025-10-08 10:51:47 +02:00
Johannes Altmanninger
8dd59081d7 github workflows lockthreads: only run on main repo
We should disable the whole action instead of the job but I don't
know how to do that.
2025-10-08 10:51:47 +02:00
Johannes Altmanninger
3ae17ea100 release.sh: fix deployment approval logic
(cherry picked from commit e074b27abf)
2025-10-08 10:51:47 +02:00
Fabian Boehm
10c34c5353 Revert "Move the C compiler requrement in readme"
build.rs still uses cc:: for feature detection, as 50819666b1 points out.

This reverts commit 594f1df39c.
2025-10-07 22:47:14 +02:00
Johannes Altmanninger
e3ebda3647 tests/checks/fish_config: fix for non-embedded builds 2025-10-07 22:23:04 +02:00
Johannes Altmanninger
092e7fa274 release.sh: check fish-site worktree staleness 2025-10-07 22:23:04 +02:00
Johannes Altmanninger
dd47c2baa2 Sanitize cursor position report on kitty click_events
This is easy to trigger by having a background process do "echo" to
move the terminal cursor to the next line, and then clicking anywhere.

Fixes #11905
2025-10-07 21:54:26 +02:00
Johannes Altmanninger
15065255e9 fish_config: fix regression "theme show" not showing custom themes
This regressed in 6f0532460a5~2..6f0532460a5 (fish_config: fix for
non-embedded builds, 2025-09-28).

Fixes #11903
2025-10-07 21:54:26 +02:00
Johannes Altmanninger
594f1df39c Move the C compiler requrement in readme
Fixes #11908
2025-10-07 21:54:26 +02:00
Johannes Altmanninger
724416125e tests/checks/config-paths-standalone.fish: fix bad assertion
Fixes #11906
2025-10-07 17:26:48 +02:00
Johannes Altmanninger
3afafe6398 Fix build on OpenBSD/NetBSD
Co-authored-by: Michael Nickerson <darkshadow02@me.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>

Tested on OpenBSD; we'll see about NetBSD.

Closes #11893
Closes #11892
Closes #11904
2025-10-07 15:24:02 +02:00
Johannes Altmanninger
af7446a055 Start using cfg_if 2025-10-07 15:24:02 +02:00
Johannes Altmanninger
7be101e8c9 Add OpenBSD sourcehut config 2025-10-07 15:24:01 +02:00
Johannes Altmanninger
5f18b173dd ulimit: add back RLIMIT_NICE on linux 2025-10-07 15:24:01 +02:00
Johannes Altmanninger
3fec9c8145 Embedded builds to use $workspace_root/etc again if run from build dir
Commit f05ad46980 (config_paths: remove vestiges of installable
builds, 2025-09-06) removed a bunch of code paths for embed-data
builds, since those builds can do without most config paths.

However they still want the sysconfig path.  That commit made
embedded builds use "/etc/fish" unconditionally.  Previously they
used "$workspace_root/etc".  This is important when running tests,
which should not read /etc/fish.

tests/checks/invocation.fish tests this implicitly: if /etc/fish does
not exist, then

	fish --profile-startup /dev/stdout

will not contain "builtin source".

Let's restore historical behavior.  This might be annoying for users
who "install" with "ln -s target/debug/fish ~/bin/", but that hasn't
ever been recommended, and the historical behavior was in effect
until 4.1.0.

Fixes #11900
2025-10-07 15:24:01 +02:00
Johannes Altmanninger
bdca70bfb0 build.rs: extract function for overridable paths
Also get rid of cursed get_path().
2025-10-07 15:24:01 +02:00
Johannes Altmanninger
5e28f068ec build.rs: dedicated error for bad encoding in environment variables
We should probably not silently treat invalid Unicode the same as
"the variable is unset", even though it probably makes no difference
in practice.
2025-10-07 15:24:01 +02:00
Johannes Altmanninger
a0b22077a5 Extract constant for resolved build directory
Also use a different name than for the CMake variable, to reduce
confusion.
2025-10-07 11:59:45 +02:00
Daniel Rainer
1d36b04ea6 check.sh: export gettext extraction file variable
Some versions of `/bin/sh`, e.g. the one on FreeBSD, do not propagate
variables set on a command through shell functions. This results in
`FISH_GETTEXT_EXTRACTION_FILE` being set in the `cargo` function, but
not for the actual `cargo` process spawned from the function, which
breaks our localization scripts and tests. Exporting the variable
prevents that.

Fixes #11896

Closes #11899
2025-10-07 10:49:39 +02:00
Daniel Rainer
6829c9d678 printf-c: restore length modifiers
These were accidentally removed when semi-automatically removing length
modifiers from Rust code and shell scripts.

In C, the length modifiers are required.

Closes #11898
2025-10-07 07:52:26 +02:00
Ilya Grigoriev
e1f6ab8916 checks: make tmux-multiline-prompt less affected by less config
Fixes #11881 for me. Thanks, @krobelus, for the help with debugging
this!

The `-+X` is unrelated to the bug, strictly speaking, but makes sure the
test tests what it is intended to test.

I initially thought of also adding `LESS=` and something like
`--lesskey-content=""` to the command, but I decided against it since
`less` can also maybe be configured with `LESSOPEN` (?) and I don't know
how long the `--lesskey-content` option existed.

Closes #11891
2025-10-06 15:08:25 +02:00
Daniel Rainer
778baaecb5 sprintf: remove signed int size info
The size was used to keep track of the number of bits of the input type
the `Arg::SInt` variant was created from. This was only relevant for
arguments defined in Rust, since the `printf` command takes all
arguments as strings.

The only thing the size was used for is for printing negative numbers
with the `x` and `X` format specifiers. In these cases, the `i64` stored
in the `SInt` variant would be cast to a `u64`, but only the number of
bits present in the original argument would be kept, so `-1i8` would be
formatted as `ff` instead of `ffffffffffffffff`.

There are no users of this feature, so let's simplify the code by
removing it. While we're at it, also remove the unused `bool` returned
by `as_wrapping_sint`.

Closes #11889
2025-10-06 15:08:25 +02:00
Daniel Rainer
a189f79590 input: remove dead code
See https://github.com/fish-shell/fish-shell/pull/11874#discussion_r2404478880
> There is a comment saying `// Keep this function for debug purposes`
but I'm sure that's obsolete, since ReadlineCmd implements `Debug` now.

Closes #11887
2025-10-06 15:08:25 +02:00
Ada Magicat
6395644e8c doc: correct example of fish_should_add_to_history
Closes #11886
2025-10-06 15:08:25 +02:00
Johannes Altmanninger
a958f23f63 Fix regression on paste in non-interactive read
As reported in
https://github.com/fish-shell/fish-shell/issues/11836#issuecomment-3369973613,
running "fish -c read" and pasting something would result this error
from __fish_paste:

	commandline: Can not set commandline in non-interactive mode

Bisects to 32c36aa5f8 (builtins commandline/complete: allow handling
commandline before reader initialization, 2025-06-13).  That commit
allowed "commandline" to work only in interactive sessions, i.e. if
stdin is a TTY or if overridden with -i.

But this is not the only case where fish might read from the TTY.
The notable other case is builtin read, which also works in
noninteractive shells.
Let's allow "commandline" at least after we have initialized the TTY
for the first reader, which restores the relevant historical behavior
(which is weird, e.g. « fish -c 'read; commandline foo' »).
2025-10-06 15:08:25 +02:00
Johannes Altmanninger
ec8756d7a3 tests/checks/read: add test for non-interactive use of commandline 2025-10-06 15:04:19 +02:00
Xiretza
b7fabb11ac Make command run by __fish_echo output to TTY for color detection
Without this, e.g. Alt-L shows the directory entries one per line and
without colors.

Closes #11888
2025-10-06 13:39:30 +02:00
Johannes Altmanninger
74ba4e9a98 docker_builds: run only on fish-shell/fish-shell repo
Else this runs when people push to their master's forks, see
https://github.com/fish-shell/fish-shell/pull/11884#discussion_r2405618358
2025-10-06 13:29:08 +02:00
Johannes Altmanninger
b1e8fdfaa2 Revert "CI: use build_tools/check.sh in Cirrus CI"
I think we do want to stop using CMake on Cirrus but this should
first be tested in combination with all the other changes that made
it to master concurrently (test by pushing a temporary branch to the
fish-shell repo), to avoid confusion as to what exactly broke.

This reverts commit d167ab9376.

See #11884
2025-10-06 13:28:49 +02:00
Johannes Altmanninger
9eb439c01d Revert "Allow black to be missing in style.fish"
The root cause was that FISH_CHECK_LINT was not set. By
default, check.sh should fail if any tool is not installed, see
59b43986e9 (build_tools/style.fish: fail if formatters are not
available, 2025-07-24); like it does for rustfmt and clippy.

This reverts commit fbfd29d6d2.

See #11884
2025-10-06 13:27:47 +02:00
Peter Ammon
fbfd29d6d2 Allow black to be missing in style.fish
Stop failing BSD builds because black is missing.
2025-10-05 20:49:49 -07:00
Peter Ammon
f158a3ae3e Revert "Attempt to fix Cirrus builds harder"
This reverts commit d683769e1f.
2025-10-05 20:38:22 -07:00
Peter Ammon
7d59b4f4e2 Add an unnecessary_cast suppression
Continue to help fix BSD builds.
2025-10-05 20:12:55 -07:00
Peter Ammon
e99eca47c3 Add .claude to gitignore 2025-10-05 19:58:28 -07:00
Peter Ammon
d683769e1f Attempt to fix Cirrus builds harder
Install black
2025-10-05 19:58:02 -07:00
Peter Ammon
9ea328e43a Fix the BSD builds
These relied on constants that don't actually exist.
2025-10-05 19:30:33 -07:00
David Adam
f6d93f2fdb GitHub Actions: add workflow to build Docker images for CI 2025-10-06 09:50:56 +08:00
David Adam
b644fdbb04 docker: do not install recommended packages on Ubuntu
This should speed things up a bit, but various additional packages need
to be installed.
2025-10-06 09:50:56 +08:00
David Adam
7647d68b68 docker: fix Rust package name for jammy 2025-10-06 09:50:56 +08:00
David Adam
d167ab9376 CI: use build_tools/check.sh in Cirrus CI
08b03a733a removed CMake from the Docker images used for the
Cirrus builds.

It might be better to use fish_run_tests.sh in the Docker image, but
that requires some context which I'm not sure is set up properly in
Cirrus.
2025-10-06 09:50:55 +08:00
David Adam
e68bd2f980 build_tools/check.sh: add support for FISH_TEST_MAX_CONCURRENCY 2025-10-06 09:50:55 +08:00
Jesse Harwin
b5c17d4743 completions/bind: bug fixes, cleanup, and complete multiple functions
Revamped and renamed the __fish_bind_test2 function. Now has a
more explicit name, `__fish_bind_has_keys`  and allows for multiple
functions after the key-combo, doesn't offer function names after an
argument with a parameter (e.g. -M MODE).

Logic on the function is now more concise.

Closes #11864
2025-10-05 15:16:41 +02:00
Jesse Harwin
66ca7ac6d0 completions/bind: removed the unused __fish_bind_test1 function 2025-10-05 15:16:41 +02:00
Johannes Altmanninger
e97a616ffa completions/bind: don't suggest key names if --function-names is given
This combination makes no sense and should be an error.  (Also the
short options and --key-names were missing, so this was quite
inconsistent.)

See #11864
2025-10-05 15:16:41 +02:00
Ilya Grigoriev
061517cd14 completion/set: fix bug preventing showing history or fish_killring
Previously, `set -S fish_kill<TAB>` did not list `fish_killring`. This
was because `$1` wasn't sufficiently escaped, and so instead of
referring to a regex capture group, it was always empty.

Closes #11880
2025-10-05 15:16:41 +02:00
Johannes Altmanninger
6accc475c9 Don't use kitty keyboard protocol support to decide timeout
As reported in
https://github.com/fish-shell/fish-shell/discussions/11868, some
terminals advertise support for the kitty keyboard protocol despite
it not necessarily being enabled.

We use this flag in 30ff3710a0 (Increase timeout when reading
escape sequences inside paste/kitty kbd, 2025-07-24), to support
the AutoHotKey scenario on terminals that support the kitty keyboard
protocols.

Let's move towards the more comprehensive fix mentioned in abd23d2a1b
(Increase escape sequence timeout while waiting for query response,
2025-09-30), i.e. only apply a low timeout when necessary to actually
distinguish legacy escape.

Let's pick 30ms for now (which has been used successfully for similar
things historically, see 30ff3710a0); a higher timeout let alone
a warning on incomplete sequence seems risky for a patch relase,
and it's also not 100% clear if this is actually a degraded state
because in theory the user might legitimately type "escape [ 1"
(while kitty keyboard protocol is turned off, e.g. before the shell
regains control).

This obsoletes and hence reverts commit 623c14aed0 (Kitty keyboard
protocol is non-functional on old versions of Zellij, 2025-10-04).
2025-10-05 15:16:41 +02:00
Johannes Altmanninger
c2e2fd6432 fish_add_path: remove extra argument to printf 2025-10-05 15:16:41 +02:00
Daniel Rainer
83af5c91bd printf: remove all uses of length modifiers
Length modifiers are useless. This simplifies the code a bit, results in
more consistency, and allows removing a few PO messages which only
differed in the use of length modifiers.

Closes #11878
2025-10-05 15:16:41 +02:00
Peter Ammon
e9f5982147 Fix a clipply 2025-10-04 19:25:10 -07:00
Peter Ammon
50819666b1 Remove our own C bits
fish-shell itself no longer depends on a C compiler; however we still
use cc for feature detection. Removing that will have to wait for another day.
2025-10-04 18:56:11 -07:00
Peter Ammon
6ad13e35c0 Bravely define PATH_BSHELL
PATH_BSHELL is always "/bin/sh" except on Android where it's "/system/bin/sh".

This isn't exposed by Rust, so just define it ourselves.
2025-10-04 17:27:16 -07:00
Peter Ammon
39e2f1138b Bravely stop setting stdout to unbuffered
Issue #3748 made stdout (the C FILE*, NOT the file descriptor) unbuffered,
due to concerns about mixing output to the stdout FILE* with output output.

We no longer write to the C FILE* and Rust libc doesn't expose stdout, which may
be a macro. This code no longer looks useful. Bravely remove it.
2025-10-04 17:27:15 -07:00
Peter Ammon
cd37c71e29 Adopt Rust libc RLIMIT_* fields
Moving more stuff out of C.
2025-10-04 14:09:47 -07:00
Peter Ammon
c1f3d93b3b Adopt Rust libc::MNT_LOCAL
Note the ST_LOCAL usage on NetBSD is also covered by this.
2025-10-04 14:09:46 -07:00
Peter Ammon
0aa05032c4 Adopt rust _PC_CASE_SENSITIVE
fish no longer needs to expose this - the libc crate does the job.
2025-10-04 14:01:13 -07:00
Peter Ammon
174130fe2f Adopt Rust libc _CS_PATH
This is now supported directly by the libc crate - no need for fish
to expose this via C.
2025-10-04 14:01:11 -07:00
Peter Ammon
d06f7f01d2 Remove MB_CUR_MAX from our libc ffi
We no longer need this.
2025-10-04 13:39:22 -07:00
Peter Ammon
a04ddd9b17 Adopt get_is_multibyte_locale in the pager 2025-10-04 13:39:22 -07:00
Peter Ammon
12929fed74 Adopt get_is_multibyte_locale in decode_input_byte
Move away from MB_CUR_MAX
2025-10-04 13:39:22 -07:00
Peter Ammon
87bf580f68 Adopt get_is_multibyte_locale in wcs2string_callback
Move away from MB_CUR_MAX
2025-10-04 13:39:22 -07:00
Peter Ammon
66bab5e767 Early work aiming to remove MB_CUR_MAX from fish libc FFI
Start detecting multibyte locales in Rust.
2025-10-04 13:39:21 -07:00
Peter Ammon
4b12fb2887 Migrate invalidate_numeric_locale into fish_setlocale
Centralizes where locale information is recomputed.
2025-10-04 13:39:21 -07:00
Johannes Altmanninger
623c14aed0 Kitty keyboard protocol is non-functional on old versions of Zellij
try_readb() uses a high timeout when the kitty keyboard protocol is
enabled, because in that case it should basically never be necessary
to interpret \e as escape key, see 30ff3710a0 (Increase timeout when
reading escape sequences inside paste/kitty kbd, 2025-07-24).

Zellij before commit 0075548a (fix(terminal): support kitty keyboard
protocol setting with "=" (#3942), 2025-01-17) fails to enable kitty
keyboard protocol, so it sends the raw escape bytes, causing us to
wait 300ms.

Closes #11868
2025-10-04 07:17:34 +02:00
Johannes Altmanninger
7d83dc4758 Refresh TTY timestamps after firing focus events
Using a multi-line prompt with focus events on:

	tmux new-session fish -C '
		tmux set -g focus-events on
		set -g fish_key_bindings fish_vi_key_bindings
		function fish_prompt
		    echo (prompt_pwd)
		    echo -n "> "
		end
		tmux split
	'

switching to the fish pane and typing any key sometimes leads to our
two-line-prompt being redawn one line below it's actual place.

Reportedly, it bisects to d27f5a5 which changed when we print things.
I did not verify root cause, but
1. symptoms are very similar to other
   problems with TTY timestamps, see eaa837effa (Refresh TTY
   timestamps again in most cases, 2025-07-24).
2. this seems fixed if we refresh timestamps after
   running the focus events, which print some cursor shaping commands
   to stdout. So bravely do that.

Closes #11870
2025-10-03 22:35:31 +02:00
Johannes Altmanninger
493d0bca95 Update changelog for patch release 2025-10-03 22:01:39 +02:00
qianlongzt
983501ff8c zh_CN: fix vi case
Part of #11854
2025-10-03 20:51:57 +02:00
The0x539
20da9a2b51 ast: use macro_rules_attribute for the Acceptor trait
Closes #11867
2025-10-03 20:45:01 +02:00
The0x539
7aec6c55f9 ast: use macro_rules_attribute for Leaf trait
Part of #11867
2025-10-03 20:45:01 +02:00
The0x539
532f30e031 ast: use macro_rules_attribute for Node trait
Part of #11867
2025-10-03 20:45:01 +02:00
Daniel Rainer
1d7ab57e3a xgettext: remove --strict flag from msguniq
As with `msgmerge`, this introduces unwanted empty comment lines above
`#, c-format`
lines. We don't need this strict formatting, so we get rid of the flag
and the associated empty comment lines.

Closes #11863
2025-10-03 20:22:59 +02:00
Étienne Deparis
8adc598e90 web_config: Support long options separated with = from their value
Closes #11861
2025-10-03 20:18:38 +02:00
Étienne Deparis
c884c08257 web_config: Use None as default for underline style
Underline is no more a boolean and should be one of the accepted style,
or None. By keeping False as default value, web_config was generating
wrong --underline=False settings

Part of #11861
2025-10-03 20:18:38 +02:00
Daniel Rainer
66dc734c11 printf: remove useless length modifiers
Closes #11858
2025-10-03 20:14:20 +02:00
Daniel Rainer
77fee9acb9 printf: rename direc -> directive
The abbreviation is ambiguous, which makes the code unnecessarily hard
to read. (possible misleading expansions: direct, direction, director,
...)

Part of #11858
2025-10-03 20:14:20 +02:00
Daniel Rainer
6b66c2bc1d printf: use options for idiomatic code
The `have_foo: bool` + `foo: i64` combination is more idiomatically
represented as `foo: Option<i64>`. This change is applied for
`field_width` and `precision`.

In addition, the sketchy explicit cast from `i64` to `c_int`, and the
subsequent implicit cast from `c_int` to `i32` are avoided by using
`i64` consistently.

Part of #11858
2025-10-03 20:14:20 +02:00
Daniel Rainer
81b9f50dc2 printf: reformat doc comments
Part of #11858
2025-10-03 20:14:20 +02:00
Johannes Altmanninger
fcd246064b Stop requesting modifyOtherKeys on old Midnight Commander again
This upstream issue was fixed in 0ea77d2ec (Ticket #4597: fix CSI
parser, 2024-10-09); for old mc's we had worked around this but the
workaround was accidentally removed. Add it back for all the versions
that don't have that fix.

Fixes f0e007c439 (Relocate tty metadata and protocols and clean
it up, 2025-06-19) Turns out this was why the "Capability" enum was
added in 2d234bb676 (Only request keyboard protocols once we know
if kitty kbd is supported, 2025-01-26).

Fixes #11869
2025-10-03 20:14:20 +02:00
Johannes Altmanninger
86a0a348ee Harmonize temporary Midnight Commander workarounds a bit 2025-10-03 18:18:05 +02:00
Johannes Altmanninger
ed36e852d2 release.sh: add next patch milestone
This is still the common case.
2025-10-03 18:08:28 +02:00
Johannes Altmanninger
da5d93c1e2 release.sh: close milestone when done
Don't fail early if this doesn't exist, because it's not needed for
testing this on fish-shell forks that live on GitHub.
2025-10-03 18:08:28 +02:00
Johannes Altmanninger
7b59ae0d82 Unbreak hack to strip " (deleted)" suffix from executable path
Commit 49b88868df (Fix stripping of " (deleted)" from non-UTF8 paths
to fish, 2024-10-12) was wrong because Path::ends_with() considers
entire path components. Fix that.

Refs:
- https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$k2IQazfmztFUXrairmIQvx_seS1ZJ7HlFWhmNy479Dg
- https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$4pugfHejL9J9L89zuFU6Bfg41UMjA0y79orc3EaBego
2025-10-03 18:08:28 +02:00
Fabian Boehm
97acc12d62 Fix scp completions
Introduced when __fish_mktemp_relative was.

Fixes #11860
2025-10-02 18:20:41 +02:00
Johannes Altmanninger
db6a7d26cd update_translations.sh: add header to new files too
Fixes #11855
2025-10-01 18:30:38 +02:00
Johannes Altmanninger
6be03d7cc4 update_translations.sh: fix test invocation when passed a file in non-extant directory
Need to make sure test arguments are not empty lists.
2025-10-01 18:30:38 +02:00
Daniel Rainer
617a6edb13 Extract messages without building default features
Default features are not needed for message extraction, so there is no
need to spend any resources on them.

If a PO files contains a syntax error, extraction would fail if the
`localize-messages` feature is active. This is undesirable, because it
results in an unnecessary failure with worse error messages than if the
`msgmerge` invocation of the `update_translations.fish` script fails.

Closes #11849
2025-10-01 08:05:37 +02:00
王宇逸
31c85723e8 zh_CN: don't translate set command
Closes #11852
2025-10-01 08:02:38 +02:00
王宇逸
d22c905d9f zh_CN: fix typo
Part of #11852
2025-10-01 08:02:38 +02:00
Daniel Rainer
216dc2d473 Remove redundant variable declaration
Closes #11851
2025-10-01 08:00:21 +02:00
Daniel Rainer
918e7abe6b Hide output of msgfmt -h
This command is only used to determine availability of `msgfmt`. Without
these changes, the entire help output shows up if the code panics later
on, which adds useless bloat to the output, making it harder to analyze
what went wrong.

Closes #11848
2025-10-01 07:59:46 +02:00
Daniel Rainer
c145ee6df3 Check exit status of msgfmt
Prior to this, when `msgfmt` failed, this would be detected indirectly
by the parser, which would then panic due to it input being empty.

Explicit checking allows us to properly display `msgfmt`'s error
message.

Closes #11847
2025-10-01 07:59:21 +02:00
Johannes Altmanninger
62543b36a4 release.sh: sunset release announcement email
I'm not sure if our peer projects do this or if it's useful to have
on top of github releases (especially as most releases are patch
releases mainly).

We could certainly use "sphinx-build -b text" in
build_tools/release-notes.sh to extract a nice plaintext changelog
and send that, but that doesn't support links.  Not sure about HTML
email either.
2025-10-01 07:26:50 +02:00
Daniel Rainer
751aad5302 Refactor PO section marking
Use msgids to mark sections. In the PO format, comments are associated
with specific messages, which does not match the semantics for section
markers.
Furthermore, comments are not preserved by `msgmerge`, which required
quite convoluted handling to copy them over from the template.
By using msgids to mark sections, this problem is avoided.

This convoluted handling was also used for header comments. Header
comments are now handled in a simpler way. There is a fixed prefix,
identifying these comments, as well as a list variable containing the
lines which should be put into the header. When a PO file is generated,
all existing lines starting with the prefix are deleted, the and the
current version of the lines is prepended to the file.

Closes #11845
2025-09-30 19:45:31 +02:00
Daniel Rainer
efabab492a Remove useless comments
Most of them have been added automatically for no good reason.

Also remove outdated comments referring to source locations in pt_BR.po.

Closes #11844
2025-09-30 19:44:36 +02:00
Daniel Rainer
c7cdbe60cd Put general comments on top of empty msgid
These should not be comments on an actual message, since they apply
throughout the entire file, so the sensible location is as comments on
the empty msgid.

Closes #11843
2025-09-30 19:44:15 +02:00
Johannes Altmanninger
412149a5de Changelog update for 4.1.1 2025-09-30 19:22:41 +02:00
Johannes Altmanninger
abd23d2a1b Increase escape sequence timeout while waiting for query response
Running "fish -d reader" inside SSH inside Windows terminal sometimes
results in hangs on startup (or whenever we run "scrollback-push"),
because not all of the Primary DA response is available for reading
at once:

	reader: Incomplete escape sequence: \e\[?61\;4\;6\;7\;14\;21\;22\;23\;24\;28\;32

Work around this by increasing the read timeout while we're waiting
for query responses.

We should try to find a better (more comprehensive?) fix in future,
but for the patch release, this small change will do.

Fixes #11841
2025-09-30 19:00:40 +02:00
Johannes Altmanninger
b774c54a6f Changelog for translation fixes from #11833 2025-09-30 19:00:40 +02:00
王宇逸
e4b797405b zh_CN: fix tier 1 translations
Closes #11833
2025-09-30 18:41:44 +02:00
Johannes Altmanninger
81a89a5dec release-notes.sh: fix sphinx warning for patch release notes
Integration_4.1.1 fails to generate release notes with

	CHANGELOG.rst:9: WARNING: Bullet list ends without a blank
	line; unexpected unindent. [docutils].
2025-09-30 18:00:09 +02:00
Johannes Altmanninger
0da12a6b55 Primary Device Attribute is a proper noun
We don't care about any specific attributes but we do very much care
about the specific query and response format associated with VT100's
primary device attribute query. Use a proper noun to emphasize that
we want that one and no other.

Ref: https://github.com/fish-shell/fish-shell/pull/11833#discussion_r2385659040
2025-09-30 12:06:08 +02:00
Johannes Altmanninger
86ec8994e6 build.rs: fix MSRV (1.70) clippy 2025-09-30 12:06:08 +02:00
Johannes Altmanninger
caf426ddb2 po/de.po: copy-edit German translations
Go through all existing translations except for tier3.
2025-09-30 11:50:43 +02:00
Johannes Altmanninger
508ae410a6 builtin commandline: fix completion description 2025-09-30 11:47:26 +02:00
Johannes Altmanninger
993b977c9b builtin function: remove dead code 2025-09-30 11:47:26 +02:00
Johannes Altmanninger
a7f0138fc7 builtin function: fix a misleading error message
Issue introduced in 7914c92824 (replaced the functions '--rename'
option with '--copy'., 2010-09-09).
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
ab3c932903 builtin set: fix regression in error message description 2025-09-30 11:47:26 +02:00
Johannes Altmanninger
ae0fdadcff Remove translations for some error messages that basically never happen
Executable path is empty only in contrived circumstances.

The regex error happens only when the user explicitly turns off a
feature flag.

The orphaned process error seems very unlikely, not worth translating.
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
e3974989d8 Fix short description for builtin wait 2025-09-30 11:47:26 +02:00
Johannes Altmanninger
080b1e0e4f Translation update implied by parent commit
Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
a5db91dd85 po: add section markers to indicate translation priority
Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
b62f54631b Translation update implied by parent commit
Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
d835c5252a Prepare to not localize private function descriptions
The overwhelming majority of localizable messages comes from
completions:

	$ ls share/completions/ | wc -l
	$ 1048

OTOH functions also contribute a small amount, mostly via their
descriptions (so usually just one per file).

	$ ls share/functions/ | wc -l
	$ 237

Most of these are private and almost never shown to the user, so it's
not worth bothering translators with them. So:

- Skip private (see the parent commit) and deprecated functions.
- Skip wrapper functions like grep (where the translation seems to
  be provided by apropos), and even the English description is not
  helpful.
  - Assume that most real systems have "seq", "realpath" etc.,
    so it's no use providing our own translations for our fallbacks.
- Mark fish's own functions as tier1, and some barely-used functiosn
  and completions as tier3, so we can order them that way in
  po/*.po. Most translators should only look at tier1 and tier2.
  In future we could disable localization for tier3.

See the explanation at the bottom of
tests/checks/message-localization-tier-is-declared.fish

Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
a53db72564 Mark private functions that don't need localization
See the next commit.

Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
61b0368dac functions/realpath: remove weird wrapping
Wrapping the same thing is redundant and wrapping grealpath is kinda
pointless since we only provide completions for realpath.
2025-09-30 11:47:26 +02:00
Integral
568b4a22f9 completions/help: correct the spelling of "redirection"
Closes #11839
2025-09-30 11:47:26 +02:00
Jiangqiu Shen
8abba8a089 Re-add translations for share/completions/cjpm.fish
As removed in the parent commit.
Cherry-picked from e4c55131c7 (Update translation, 2025-07-04)
2025-09-30 11:47:26 +02:00
王宇逸
b3b789cd68 zh_CN: bad translations are worse than none
Part of #11833
2025-09-30 11:47:26 +02:00
Johannes Altmanninger
425a166111 functions/seq: use early return 2025-09-30 10:37:11 +02:00
Johannes Altmanninger
1dcc290e29 tests/checks/check-all-fish-files.fish: follow naming convention 2025-09-30 10:37:11 +02:00
Johannes Altmanninger
863204dbfa build.rs: remove dead code 2025-09-30 10:37:11 +02:00
Sebastian Fleer
4b21e7c9c7 webconfig: Replace str.stripprefix with str.removeprefix
str.stripprefix doesn't exist in Python:
https://docs.python.org/3/library/stdtypes.html#str.removeprefix

Closes #11840
2025-09-30 10:37:06 +02:00
Johannes Altmanninger
df5230ff4a Reliably disable modifyOtherKeys on WezTerm
WezTerm allows applications to enable modifyOtherKeys by default.
Its implementation has issues on non-English or non-QWERTY layouts,
see https://github.com/wezterm/wezterm/issues/6087 and #11204.

fish 4.0.1 disabled modifyOtherKeys on WezTerm specifically
(7ee6d91ba0 (Work around keyboard-layout related bugs in WezTerm's
modifyOtherKeys, 2025-03-03)), fish 4.1.0 didn't, because at that
time, WezTerm would advertise support for the kitty keyboard protocol
(even if applications are not allowed to enable it) which would make
fish skip requesting the legacy modifyOtherKeys.

WezTerm no longer advertises that if config.enable_kitty_keyboard
is false.  Let's work around it in another way.
2025-09-30 10:33:03 +02:00
Johannes Altmanninger
7cd0943056 Tighten some screws for TTY-specific workarounds 2025-09-30 10:25:23 +02:00
Johannes Altmanninger
6f0532460a fish_config: fix for non-embedded builds
I only tested with embedded-builds; CMake tests were failing because
they use different code paths here.

fish_config could use some love.  Start by extracting common
functionality between "{theme,prompt} show", fixing the behavior.

Fixes 29a35a7951 (fish_config: fix "prompt/theme show" in embed-data
builds, 2025-09-28).
2025-09-28 12:29:18 +02:00
Johannes Altmanninger
29a35a7951 fish_config: fix "prompt/theme show" in embed-data builds
Fixes #11832
2025-09-28 10:59:53 +02:00
Johannes Altmanninger
dd0d45f88f fish_config prompt: remove dead code
Commit 2b74affaf0 (Add prompt selector, 2021-04-22)
intentionally added an unused code path that checks for
$__fish_data_dir/sample_prompts, see

https://github.com/fish-shell/fish-shell/pull/7958#discussion_r621320945

> (note: This was added in preparation of moving the sample_prompts directory out of web_config -
> because it no longer is web-exclusive)

Remove it.
2025-09-28 10:11:01 +02:00
Johannes Altmanninger
0ff0de7efe release workflow: install msgfmt for staticbuilds
This makes us actually embed localized messages.

Part of #11828
2025-09-28 09:56:57 +02:00
Johannes Altmanninger
092ef99551 macos CI: explicitly install gettext
We need msgfmt for embedding translations.

Part of #11828
2025-09-28 09:54:30 +02:00
Johannes Altmanninger
97ae05b69d build_tools/release.sh: actually add new docs
Not quite sure for which step this is actually needed.  While at it,
fix the errexit issue that caused this blunder.
2025-09-27 22:56:49 +02:00
Johannes Altmanninger
3d8eca178e start new cycle
Created by ./build_tools/release.sh 4.1.0
2025-09-27 22:41:54 +02:00
Johannes Altmanninger
29b80bbaf9 Release 4.1.0
Created by ./build_tools/release.sh 4.1.0
2025-09-27 22:20:11 +02:00
Johannes Altmanninger
29470358d4 make_macos_pkg: update CMake invocation for MSRV rustc+cargo
Since 205d80c75a (findrust: Simplify (#11328), 2025-03-30), we need
to set Rust_COMPILER and Rust_CARGO instead of Rust_TOOLCHAIN (which
is no longer used).  Adjust macOS builds accordingly.

When I set only one of the two, the error messages were pretty
unintelligible. But I guess few normal users need to override the
Rust version, and they can always look here.

While at it, enable localization.  AFAIK, the only reason why we didn't
do this on macOS were problems related to the gettext shared library /
dependency. We no longer need that, and it's already tested in CI.
2025-09-27 22:15:25 +02:00
Johannes Altmanninger
8fe68781be Release workflow fixups
(cherry picked from commit ce4aa7669d)
2025-09-27 22:06:26 +02:00
Johannes Altmanninger
aba4d26f95 Emphasize that "status {list-files,get-file}" are meant for internal use
I'm not aware of a lot of sensible use cases where users need to access
our files directly.  The one example we know about is zoxide overriding
exactly our version of "function cd", ignoring any user-provided cd.
I think this is already hacky. But I guess it's here to stay.

I think we should not recommend this for external use, or at least
ask users to tell us what they are using this for.

Given that we expect these to be used mainly/only internally,
get-file/list-files are fine as names.

The other issue is that one has to be careful to always do

	status list-files 2>/dev/null

to support non-embedded builds.

Closes #11555
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
b964072c11 Move scrollback-push feature detection to fish script
A lot of terminals support CSI Ps S.  Currently we only allow them
to use scrollback-up if they advertise it via XTGETTCAP.  This seems
surprising; it's better to make visible in fish script  whether this
is supposed to be working.  The canonical place is in "bind ctrl-l"
output.

The downside here is that we need to expose something that's rarely
useful. But the namespace pollution is not so bad, and this gives
users a nice paper trail instead of having to look in the source code.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
06bbac8ed6 release-notes.sh: add stats, round off committer list
Instead of adding these to the Markdown directly, add it to the
fake CHANGELOG.rst source, which makes escaping easier, and allows
generating other formats than Markdown in future.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
aab22a453b Revert "Only load sphinx_markdown_builder extension if it's used"
sphinx-build fails with

	sphinx.errors.SphinxError: Builder name markdown not registered or available through entry point

Apparently this issue was hidden locally by caching, and not checked
in CI because of this error causing
tests/checks/sphinx-markdown-changelog.fish to be skipped.

	sphinx-build 7.2.6
	runner@runnervm3ublj:~/work/fish-shell/fish-shell$ python -c 'import sphinx_markdown_builder'
	Traceback (most recent call last):
	  File "<string>", line 1, in <module>
	  File "/home/runner/.local/lib/python3.12/site-packages/sphinx_markdown_builder/__init__.py", line 6, in <module>
	    from sphinx.util.typing import ExtensionMetadata
	ImportError: cannot import name 'ExtensionMetadata' from 'sphinx.util.typing' (/usr/lib/python3/dist-packages/sphinx/util/typing.py)


This reverts commit 7b495497d7.

While at it, fail the test earlier if something went wrong, because the
remaining check will likely also fail and confuse.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
4cc2d2ec30 release-notes.sh: remove line breaks from generated Markdown, for GitHub
GitHub-flavored Markdown translates line breaks to <br/>, which does
not match our intent. Work around that by joining lines when producing
Markdown output.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
6ed4e54c1e Remove some dead code and unnecessary allocations
complete --subcommand was added in a8e237f0f9 (Let `complete`
show completions for one command if just given `-c`, 2020-09-09)
but never used or documented.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
829d6bc8fb Move terminal name into status subcommand not variable
Forgot about that; less namespace pollution this way, and it's more
obvious that it's read-only.
2025-09-27 14:22:18 +02:00
Johannes Altmanninger
abae6157d9 Changelog: reduce verbosity a bit, add some more 2025-09-27 14:22:18 +02:00
Daniel Rainer
bce19e7265 Fix typos 2025-09-26 16:34:22 +02:00
Johannes Altmanninger
166b17701a Remove spurious terminal interaction from unit tests
Some of our integration tests require a reader for code execution
and testing cancellation etc., but they never actually read from the
terminal.  So they don't need to call reader_interactive_init(), and
doing so is a bit weird.  Let's stop that; this allows us to assert
that reader_push() is always called with an input file descriptor
that refers to a TTY.
2025-09-26 13:03:20 +02:00
Johannes Altmanninger
f8269be359 Move redundant instances of blocking_query into InputData
We duplicate the same member across all implementations.  Looks like
this never makes sense, so move it to the shared data bag.
2025-09-26 12:59:02 +02:00
Johannes Altmanninger
b907bc775a Use a low TTY query timeout only if first query failed
As mentioned in the comment, query timeouts can happen if either
1. the terminal doesn't support primary device attribute
2. there is extreme (network) latency

In the first case, we want to turn the timeout way down.  In the
second case, probably not, especially because the network latency
may be transient. Let's keep the high timeout in the second case.

Fixes 7ef4e7dfe7 (Time out terminal queries after a while,
2025-09-21).
2025-09-26 12:59:02 +02:00
Johannes Altmanninger
7e3fac561d Query terminal only just before reading from it
Commit 5e317497ef (Query terminal before reading config, 2025-05-17)
disabled the kitty keyboard protocol in "fish -c read".  This seems
surprising, and it's not actually necessary that we query before
reading config; we only need query results before we read from
the TTY for the first time (which is about the time we call
__fish_config_interactive). Let's do that, reverting parts of
5e317497ef.
2025-09-26 12:59:02 +02:00
Johannes Altmanninger
7713e90aeb Make query response handling more consistent 2025-09-26 12:58:10 +02:00
Johannes Altmanninger
08ad5c26ea Give scroll-forward a less confusing name
ECMA-48 calls CSI S "scroll up", so use something like that but try
to avoid ambiguity.
2025-09-26 12:52:28 +02:00
Johannes Altmanninger
310b7eca68 Only initialize kitty keyboard capability on startup
If the initial query is interrupted by ctrl-c, we leave it unset. A
later rogue "\e[?0u" reply would make us enable it, which seems
surprising. Fix that by always setting the capability if we're gonna
read from stdin.
2025-09-26 12:10:56 +02:00
Johannes Altmanninger
e9ae143bab Fix cursor position reports being ignored
When we receive a cursor position report, we only store the result;
we'll act on it only when we receive the primary DA reply.  Make sure
we don't discard the query state until then.

Fixes 06ede39ec9 (Degrade gracefully when failing to receive cursor
position report, 2025-09-23)
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
74d3832610 Early return in reader_execute_readline_cmd() 2025-09-26 12:10:04 +02:00
yegorc
3c04a05ea4 Added documentation for &>>.
The `&>>` redirection was undocumented.

Closes #11824
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
e6541c5c93 Enable sphinx parallelism also when building markdown release notes
We get a warning about sphinx_markdown_builder not being
parallelizable. Fix that.

Ref: https://github.com/liran-funaro/sphinx-markdown-builder/pull/38
2025-09-26 12:10:04 +02:00
Johannes Altmanninger
7b495497d7 Only load sphinx_markdown_builder extension if it's used
As is, building man pages or HTML docs while sphinx_markdown_builder
is installed, will result in unrelated warnings.  Remove those by
removing it from the extensions config.  Markdown building (only used
for changelog) seems to work without this just fine.
2025-09-26 12:08:51 +02:00
Johannes Altmanninger
6e90d9bd6f Fix markdown changelog generation test
System tests typically run outside the workspace directory, but they
still have read-only access to the workspace; fix it accordingly.
This test only works on git checkouts, not in tarballs, so skip it
if .git doesn't exist.
2025-09-26 12:08:51 +02:00
Stevie Alvarez
b8f704e3c4 fish_git_prompt: add diverged upstream char option
Currently, `__fish_git_prompt_char_upstream_diverged` can only be set to
a combination of `__fish_git_prompt_char_upstream_behind` and
`__fish_git_prompt_char_upstream_ahead`s plain-text options. Adding a
combination of the less-plain character options gives users more choice.

Closes #11817
2025-09-25 11:38:52 +02:00
Johannes Altmanninger
b37b57781b Disable sphinx-markdown-builder in tests again for now
Somehow I didn't realize this breaks the tests/checks/sphinx-* tests.
2025-09-24 16:30:21 +02:00
Fabian Boehm
e3a5725a46 Fix crash if there is no xtversion reply 2025-09-24 16:21:18 +02:00
Karel Balej
3d5a5b8740 completions: add basic completions for udevil
Add a set of basic completions for udevil, which is a program that
allows unpriviledged users to mount devices.

Each command has a corresponding long-option-like syntax variant
(sometimes even multiple ones), such as "udevil monitor" -> "udevil
--monitor", which are omitted here for simplicity.

The project unfortunately seems long abandoned and as such no attempt to
submit these completions upstream has been made.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
22ffc31b71 release workflow: credit contributors in release notes
While at it, do a 's/^--$/^---/' to fix Markdown syntax for horizontal
line for CommonMark-based parsers.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
127c02992d Test markdown changelog creation in CI
Extract a github action to install the same version used in the release
workflow.  In future we should probably migrate to requirements.txt
or similar.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
765ca54d59 release workflow: resolve relative references in changelog properly
Instead of having sphinx-build only build CHANGELOG.rst, build the
entire thing, so relative references (":doc:", ":ref:") can be resolved
properly.  Replace our sed-based hacks with 'markdown_http_base'.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1519ea74be release workflow: extract script for generating markdown release notes 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2895986465 tests/sphinx-man: man page building no longer requires fish_indent 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
e9e7ad24b5 Changelog: also extract changes to embed-data to its own section 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4f8aa0a78c Show warnings from sphinx-build when building with cargo 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f821d6dd7f Feature flag for turning off TTY querying
Experience with OSC 133 and kitty keyboard protocol enabling sequences
has shown that a lot of users are still on incompatible terminals.
It's not always easy to fix those terminals straight away. There
are probably some more environments where primary device attribute
queries are not answered.

Add a feature flag (similar to keyboard-protocols and mark-prompt)
to allow users to turn this off.

When the terminal fails to respond to primary device attribute, we
already print an error pointing to "help terminal-compatibility".
Inside that document, inside the "primary device attribute" section,
point out this new feature flag.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4c1da3b2d3 Parse Terminal.app version only if needed 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
a6f975a7e3 Add mark-prompt feature flag
(not sure if we should also include this in 4.1 but I guess better
safe than sorry)

So far, terminals that fail to parse OSC sequences are the only reason
for wanting to turn off OSC 133.  Let's allow to work around it by
adding a feature flag (which is implied to be temporary).

To use it, run this once, and restart fish:

    set -Ua fish_features no-mark-prompt

Tested with

    fish -i | string escape | grep 133 &&
    ! fish_features=no-mark-prompt fish -i | string escape | grep 133

Closes #11749
Also #11609

(cherry picked from commit 6900b89c82)
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
bbd7205de1 Document GNU screen incompatibily & workarounds
The problem described in 829709c9c4 (Replace synchronized update
workaround, 2025-04-25) doesn't seem too bad; let's document the
workaround.

We could probably also remove our $STY-based workaround.  I'm not
yet sure how many problems that one will cause.

Closes #11437
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
64c8d361b0 status.rst: link to feature flag documentation 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
c31e769f7d Use XTVERSION for terminal-specific workarounds
As mentioned in earlier commit
("Query terminal before reading config").

Closes #11812
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
99854c107a Set kitty keyboard capability only at startup 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
5e317497ef Query terminal before reading config
We still have terminal-specific workarounds based on TERM_PROGRAM and
others, see test/test_driver.py.  In future we should get rid of them.

They are also unreliable, potentially missing inside SSH/containers,
incorrect if a terminal was started from another terminal (#11812);
also TERM can be incorrect for many reasons.

The better criterion for terminal-specific workarounds is XTVERSION,
which has none of the above disadvantages.

Since some of the workarounds (tmux, iTerm2) need to be applied before
we draw the first prompt. This also means: before we read any config
because config may call builtin "read".

Do startup queries before reading config.

Some changes implied by this:
1. Remove a call to init_input() which is already done by env_init()
2. call initialize_tty_metadata() only after queries have returned
3. Since we call initialize_tty_metadata() before the first
   call to tty.enable_tty_protocols() in Reader::readline(),
   we can remove the redundant call from reader_interactive_init().
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
96f63159b5 Be consistent about how we handle bad stdin FD
When poll() or read() on stdin fails, fish's interactive reader
pretends it has received SIGHUP, and subsequently exits.

I don't know if this is the right thing to do, or how to reproduce
this in a realistic scenario.

Unlike fish, fish_key_reader seems to ignore these failures, meaning
it will retry poll()/read() immediately.  This seems less correct,
so use fish's behavior for now.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
fadb2fac44 Fix some import conventions 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1b01ac87fa Improve a tcsetpgrp error message 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
4abd390c84 test_driver.py: extend the list of terminal-specific workarounds 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
712bbf00ec fish_key_reader: remove things that don't belong in the builtin
While at it, remove a redundant call to initialize_tty_metadata();
that's done by initial_query().
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
76d1e8d4da fish_key_reader: reuse isatty helper 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2d457adfec builtin read: use a better type 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
6fdce59572 Extract function for setting shell modes
We do the same thing in several places, with lots of small differences.
Extract the most reasonable behavior and use it everywhere.  Note that
we had an explictly-motivated ENOTTY check; the motivating issues
doesn't seem to reproduce anymore here though I did not bisect yet.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
21150726d3 Remove confused redundant mutex lock 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
37a0919fee Also check isatty(0) before querying
A process like "fish -i <somefile ..."  probably shouldn't query
because it's not gonna work.

In future we could enable this by sending/receiving queries to/from
/dev/tty rather than stdout/stdin.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
7a14dd0b7f Be more consistent about when to query the TTY
We are more conservative with querying on startup than we are with
querying for cursor position.

Part of this is oversight (if startup querying is not done, we
basically never get into a position where we query for cursor position,
outside extreme edge cases).

Also, some specific scenarios where we query for cursor position
inside, say, Midnight Commander, are not actually broken, because that
only happens when Midnight Commander gives us control.  But let's
favor consistency for now; the Midnight Commander issue should be
fixed soon anyway.

Use the same logic in both cases.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
fb0e17d6ea tty_handoff: extract Midnight Commander workaround
A following commit wants to run the full initialize_tty_metadata()
only after querying XTVERSION.

But MC_TMPDIR needs to be checked before querying for XTVERSION.

Remove this cyclic dependency by extracting the MC_TMPDIR check.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
a6a38b78d6 Don't initialize interactive reader redundantly
Commands like

	fish -C 'read'

create two top-level readers one after the other.  The second one is
the fish REPL.

Both run some initialization of globals and parser variables.  This is
weird; it should not be necessary.

Let's call reader_interactive_init() only once.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f5420b1110 Remove stale comment 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
90124c7889 Remove workaround for dvtm/abduco
dvtm and abduco are two terminal session managers with the same
original.

Among other issues, they fail to reply to primary device
attribute.  We have added a workaround for that based on
TERM=dvtm-256color (unreliable). A patch has been submitted for dvtm
https://lists.suckless.org/hackers/2502/19264.html

I don't know of a maintained fork (the original ones have had no
commit in 5 years) and there are better alternatives available
(shpool, tmux).  They have other VT100 compatibility issues as well
(accidental DECRST; something like "ls" Tab Tab Tab causes spurious
bold and underline markup).

Also, as of the parent commit, failure to respond to primary DA is
no longer catastrophic. So let's remove the workaround.  This means
that fish inside dvtm/abduco will pause for 2 seconds on startup and
print a warning (unless interrupted by ctrl-c).
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
7ef4e7dfe7 Time out terminal queries after a while
Add a timeout of 2 seconds queries; if any query takes longer, warn
about that and reduce the timeout  so we stop blocking the UI.  This 2
second delay could also happen when network latency is momentarily
really high, so we might want relax this in future.

Note that this timeout is only triggered by a single uninterrupted
poll() (and measured from the start of poll(), which should happen
shortly after sending the query). Any polls interrupted by signals
or uvars/IO port before the timeout would be hit do not matter.
We could change this in future.

Closes #11108
Closes #11117
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
06ede39ec9 Degrade gracefully when failing to receive cursor position report
Follow up the cursor position report query with a primary device
attribute one.  When that one arrives, any cursor position response
must have arrived too. This allows us to prevent a hang on terminals
that only support primary device attribute.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
1612576d1c Restructure query response handling logic
Instead of switching only on the response type, switch on the
combination of that and the expected response.  This helps the
following commits, which add more combinations (due to following up
cursor position report with a primary DA, and adding a timeout). No
behavior change here.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
2260465ed7 Rename enum variants to remove a name clash 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
3bd296ae3d Reuse variable in next_input_event() 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
064a45635c Document inter-dependencies between optional terminal features
- document that we currently require "cursor position report" if
  either of both click_events or XTGETTCAP+indn is implemented.
  One of the following patches will remove this requirement.
- document properly that scrollback-push currently only works
  when XTGETTCAP+indn is implemented. There are still a few terminals
  that don't support SCROLL UP, for example the Linux Console,
  and there is no better way to find out if it's supported.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
6f01c7b707 Changelog: minor edits 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
6f2a701f81 README: recommend latest release in embedded builds section 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f79377e4b0 Revert "Temporary workaround for BSD WEXITSTATUS libc bug"
This reverts commit c1b460525c.

We have libc commit 7a7fe4683 (Apply modulo 256 to BSD WEXITSTATUS,
2024-12-19) now.
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
c3626a3031 builtin read: --tokenize-raw option
Users have tried to get a list of all tokens -- including operators
-- using "commandline --tokens-raw".  That one has been deprecated
by cc2ca60baa (commandline.rst: deprecate --tokens-raw option,
2025-05-05).  Part of the reason is that the above command is broken
for multi-line tokens.

Let's support this use case in a way that's less ambiguous.

Closes #11084
2025-09-24 15:51:32 +02:00
Johannes Altmanninger
f3b27e8d11 Changelog: link to command docs 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
5d71609ff7 Changelog: fix rst syntax for man page output 2025-09-24 15:51:32 +02:00
Johannes Altmanninger
dbd79285cb Contributing: fix rst external link syntax 2025-09-24 15:51:32 +02:00
David Adam
dca571ac4c fixup! fish.spec: also drop %find stanza for lang files 2025-09-23 08:01:04 +08:00
Daniel Rainer
c8f31ceedb Fix release workflow syntax
The previous version results in an immediate workflow failure due to a
syntax error in the YAML. `workflow_dispatch` should be a dictionary
key, with its value being another dictionary (whose only key is `inputs`
at the moment).
2025-09-22 20:25:45 +02:00
Johannes Altmanninger
b1d1ef1b6e github release workflow: fix structure 2025-09-22 18:19:36 +02:00
Johannes Altmanninger
01361b9217 github release workflow: only run on explicit dispatch
Release automation can be tested on any GitHub fork, using

	build_tools/release.sh $version $repository_owner $git_remote

which should work perfectly except for macOS packages (which fail
unless provided GitHub secrets).

People might push tags to their forks, both non-release tags (which
would trigger an early failure in "is-release-tag") or replicas of
our actual release tags (which would create a draft release etc. and
only fail when building macOS packages).

Run on explicit workflow dispatch to make sure it's not triggered by
accident like that.

This means that we'll use the .github/workflows/release.yml from
the default branch (i.e. master), so try to make sure it matches the
version in the release, to prevent accidents.

Closes #11816
2025-09-22 18:15:21 +02:00
Johannes Altmanninger
dab8df1a18 github release workflow: use github context only if needed 2025-09-22 18:15:21 +02:00
Johannes Altmanninger
c771ff06d4 build_tools/make_macos_pkg.sh: fix inconsistent version computation
make_tarball.sh and others do it differently.
2025-09-22 18:15:21 +02:00
David Adam
e5cb1689c5 fish.spec: also drop %find stanza for lang files 2025-09-21 18:45:20 +08:00
David Adam
fa96df3a90 fish.spec: drop find_lang macro
All translations are now handled internally.
2025-09-21 18:11:01 +08:00
Karel Balej
67a9d08778 completions/mpc: conditionally enable file completion for add and insert
When connecting to MPD via a Unix socket, mpc add and insert accept
absolute paths to local files. Offer these in the completion if the
completed token starts with a slash after expansion.
2025-09-20 15:20:19 +02:00
Johannes Altmanninger
5ece9bec6c __fish_print_help: use man as-is
Since 0fea1dae8c (__fish_print_help: Make formatting more man-like,
2024-10-03), there is barely any difference left between "man abbr"
and "abbr -h".

The main difference is that it looks almost like man but is actually
nroff/mandoc and less.  This means it doesn't support environment
variables like MANWIDTH and possibly others.

Let's use full "man" for now.
This matches what "git foo --help" does so it's widely accepted.

Keep around a fallback for a while, in case users/packagers fail to
install the new "man" dependency.

In future, "abbr -h" (as opposed to "abbr --help") could show a more
concise version, not sure.

Closes #11786
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
d422ad603e __fish_print_help: remove error message
__fish_print_help supports printing an error message above the
documentation.

This is currently only used by extremely rare edge cases, namely:

	eval "break"
	eval "continue --unknown"
	fish -c 'sleep 10&; bg %1'

Let's remove this feature to enable us to use man directly (#11786).
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
26116b477e Fix crash on "bg" of non-job-controlled job
fish -c 'sleep 1 & bg %1' is supposed to fail because the job is not
under job control.

When we try to print the failure, we accidentally still
hold a borrow of the job list.  This blows up because we use
"builtin_print_help_error()" to print the failure message; that
function runs "job_reap()" which wants an exclusive borrow of the
job list. Let's drop our job list earlier.
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
87c73b7fbf builtin break/continue: support -h/--help argument
These are not generic builtins because we check whether they're inside
a loop. There's no reason to not support "break -h" when we support
"if -h" etc.; do that.
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
c77255aabc tests: consolidate __fish_print_help overrides 2025-09-20 13:56:23 +02:00
Johannes Altmanninger
0063992195 functions/man: consistent switch-case ordering
Match __fish_print_help
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
1fdf37cc4a __fish_echo: fully overwrite lines
With upcoming multi-line autosuggestions, when I run

	$ function foo
	    true
	  end

and type "function", then I'll get a suggestion for the above command.
Now if press "alt-w", it will echo "function - create a function"
and rewdraw the prompt below.  But the previous autosuggestion is
not cleared, so it will look weird like:

	johannes@abc ~/g/fish-shell> function foo
	function - create a function     true

Let's erase these lines before writing them.

There's an issue remaining: the first line of the autosuggestion
(i.e. "foo") is not erased.  Fortunately this is less annoying,
but it shows that __fish_echo needs more support from core.
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
c0c7b364fc builtin status: rename buildinfo to build-info
See: https://github.com/fish-shell/fish-shell/pull/11726#discussion_r2347389523
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
64bbd41f81 build_tools/release.sh: approve macos-codesign github environment 2025-09-20 13:56:23 +02:00
Johannes Altmanninger
955345dd5b completions/sudo-rs: wrap sudo for now, closes #11800 2025-09-20 13:56:23 +02:00
Johannes Altmanninger
012b507128 Workaround for embed-data debug builds on Cygwin
When running a debug build, rust-embed always sources files from disk.
This is currently broken with on Cygwin.

As a temporary workaround, use the "debug-embed" feature to actually
embed the files into the binary, like we do for release builds.

We can probably fix the rust-embed issue fairly easily.
I haven't checked.  For now, I think this hack is preferrable to
not having an easy way to make debug builds on Cygwin.  (CMake
files would need some changes, and I also hit some problems with
installation). At least this would have helped with investigating
https://github.com/msys2/msys2-runtime/issues/308
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
142cec3a96 github release workflow: use a consistent order for static builds 2025-09-20 13:56:23 +02:00
Johannes Altmanninger
cdc57b97a3 Changelog updates 2025-09-20 13:56:23 +02:00
Johannes Altmanninger
bb916f8d73 Fix regression breaking self-insert of kitty shifted codepoint
Commit 50a6e486a5 (Allow explicit shift modifier for non-ASCII
letters, fix capslock behavior, 2025-03-30) delayed handling of kitty
keyboard protocol's shifted codepoints.  It does handle shifted
codepoints when matching keys to mappings; but it fails to handle
them in the self-insert code paths where we want to insert the text
represented by CharEvent::Key.
Fix it by resolving the shifted key.

Fixes #11813
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
8d12dfe065 Move key codepoint computation to key event
For the next commit.
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
9bf58abcae Changelog: move gettext and argparse changes to dedicated sections
By giving them dedicated headlines, they should be easier for users to skip
over if not interested.
2025-09-20 13:56:23 +02:00
Johannes Altmanninger
b325ff6992 Changelog: syntax fixes and rewording 2025-09-20 13:56:23 +02:00
Daniel Rainer
397969ddcc Add message localization tests
These tests require building with the `localize-messages` feature.

If certain translations are updated, this test might fail, either
because a message was changed in the source, or because a translation of
a message was changed, or because a translation was added in a language
which previously did not have a translation for a particular message,
and we rely on that in the test. If any of these happen, the tests need
to be updated accordingly.

Closes #11726
2025-09-20 13:56:23 +02:00
Daniel Rainer
bee1e122f9 Remove unused locale path code
The locale path was used to tell GNU gettext where to look for MO files
at runtime. Since we now embed the message catalog data into the
executable, we no longer need a locale path.

Part of #11726
2025-09-20 13:56:23 +02:00
Daniel Rainer
ad323d03b6 Switch to builtin gettext implementation
This completely removes our runtime dependency on gettext. As a
replacement, we have our own code for runtime localization in
`src/wutil/gettext.rs`. It considers the relevant locale variables to
decide which message catalogs to take localizations from. The use of
locale variables is mostly the same as in gettext, with the notable
exception that we do not support "default dialects". If `LANGUAGE=ll` is
set and we don't have a `ll` catalog but a `ll_CC` catalog, we will use
the catalog with the country code suffix. If multiple such catalogs
exist, we use an arbitrary one. (At the moment we have at most one
catalog per language, so this is not particularly relevant.)

By using an `EnvStack` to pass variables to gettext at runtime, we now
respect locale variables which are not exported.
For early output, we don't have an `EnvStack` to pass, so we add an
initialization function which constructs an `EnvStack` containing the
relevant locale variables from the corresponding Environment variables.
Treat `LANGUAGE` as path variable. This add automatic colon-splitting.

The sourcing of catalogs is completely reworked. Instead of looking for
MO files at runtime, we create catalogs as Rust maps at build time, by
converting PO files into MO data, which is not stored, but immediately
parsed to extract the mappings. From the mappings, we create Rust source
code as a build artifact, which is then macro-included in the crate's
library, i.e. `crates/gettext-maps/src/lib.rs`. The code in
`src/wutil/gettext.rs` includes the message catalogs from this library,
resulting in the message catalogs being built into the executable.

The `localize-messages` feature can now be used to control whether to
build with gettext support. By default, it is enabled. If `msgfmt` is
not available at build time, and `gettext` is enabled, a warning will be
emitted and fish is built with gettext support, but without any message
catalogs, so localization will not work then.

As a performance optimization, for each language we cache a separate
Rust source file containing its catalog as a map. This allows us to
reuse parsing results if the corresponding PO files have not changed
since we cached the parsing result.

Note that this approach does not eliminate our build-time dependency on
gettext. The process for generating PO files (which uses `msguniq` and
`msgmerge`) is unchanged, and we still need `msgfmt` to translate from
PO to MO. We could parse PO files directly, but these are significantly
more complex to parse, so we use `msgfmt` to do it for us and parse the
resulting MO data.

Advantages of the new approach:
- We have no runtime dependency on gettext anymore.
- The implementation has the same behavior everywhere.
- Our implementation is significantly simpler than GNU gettext.
- We can have localization in cargo-only builds by embedding
  localizations into the code.
  Previously, localization in such builds could only work reliably as
  long as the binary was not moved from the build directory.
- We no longer have to take care of building and installing MO files in
  build systems; everything we need for localization to work happens
  automatically when building fish.
- Reduced overhead when disabling localization, both in compilation time
  and binary size.

Disadvantages of this approach:
- Our own runtime implementation of gettext needs to be maintained.
- The implementation has a more limited feature set (but I don't think
  it lacks any features which have been in use by fish).

Part of #11726
Closes #11583
Closes #11725
Closes #11683
2025-09-20 13:56:23 +02:00
Daniel Rainer
3a196c3a08 Use rsconf::warn! where appropriate
This is a more explicit variant than directly prefixing build script
output with `cargo:warning=`.

Part of #11726
2025-09-20 09:10:39 +02:00
Daniel Rainer
f34dfb8424 Allow 3-letter language codes
Some languages do not have a 2-letter code.
https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html

Part of #11726
2025-09-20 09:10:39 +02:00
Daniel Rainer
e2a9f0eb50 Make build_dir construction more readable
Part of #11726
2025-09-20 09:10:39 +02:00
Johannes Altmanninger
fb0f9842ae Update to Rust 1.90 2025-09-19 15:43:55 +02:00
Johannes Altmanninger
ff633bd744 github release workflow: make sure that last changelog entry isn't given spurious markup 2025-09-18 10:46:21 +02:00
Johannes Altmanninger
0d46c26988 github release workflow: work around trailing "---"-line in changelog
The extracted release notes trigger a sphinx warning

	/tmp/tmp.V6RGP92nc2/src/index.rst:6:Document may not end with a transition.

which we don't seem to get on the full CHANGELOG.rst.
Let's work around that for now.
2025-09-18 09:58:14 +02:00
Johannes Altmanninger
1840df96a2 build_tools/release.sh: relax assertion about changelog title
I'd like to move to a process where everything goes into master first,
and then flows downstream to any release branches (i.e. no merging
of Integration_* branches back into master).

The only thing we need to change for that is to add release notes for
patch releases eagerly on master.  That implies that we want to use
the actual version instead of ???.  (Only if something goes wrong
in the release process, we need to change this on both branches,
but that should happen too often.)
2025-09-18 09:37:44 +02:00
Johannes Altmanninger
3456b33050 build_tools/release.sh: push to the integration branch when all goes well
Also, ignore any "sendemail.to" Git config, and remove a temporary
statement in release notes.
2025-09-18 09:32:16 +02:00
Johannes Altmanninger
9a04c15894 Fix new-style bindings shadowing raw escape sequence bindings
Given

	bind up "echo user up, new notation"
	bind \e\[A "echo user up, legacy notation"

prior to b9d9e7edc6 (Match bindings with explicit shift
first, 2025-05-24), we prioritized the legacy notation because
input_mapping_insert_sorted() makes us try longer sequences first --
and "up" is only one key compared to the three-key legacy sequence.

This prioritization was broken in b9d9e7edc6, causing plugins that
update to the "bind up" notation to break users who haven't (#11803).

Even worse, it caused preset bindings to shadow user ones:

	bind --preset up "echo preset up, new notation"
	bind \e\[A "echo user up, legacy notation"

Restore backwards compatibility by treating matches against legacy
notation like exact matches again.
2025-09-18 09:28:57 +02:00
David Adam
63585a3e26 Merge branch 'Integration_4.0.6' 2025-09-17 14:38:19 +08:00
David Adam
aa1b64f955 build_tools: make tarball scripts use the build version 2025-09-17 13:56:22 +08:00
Piotr Kubaj
91ee45b0e1 path.rs: fix build on ARM / POWER
error[E0308]: mismatched types
   --> src/path.rs:749:13
    |
748 |         let remoteness = remoteness_via_statfs(
    |                          --------------------- arguments to this function are incorrect
749 |             libc::statfs,
    |             ^^^^^^^^^^^^ expected fn pointer, found fn item
    |
    = note: expected fn pointer `unsafe extern "C" fn(*const i8, _) -> _`
                  found fn item `unsafe extern "C" fn(*const u8, _) -> _ {libc::statfs}`
note: function defined here
   --> src/path.rs:712:12
    |
712 |         fn remoteness_via_statfs<StatFS, Flags>(
    |            ^^^^^^^^^^^^^^^^^^^^^
713 |             statfn: unsafe extern "C" fn(*const i8, *mut StatFS) -> libc::c_int,
    |             -------------------------------------------------------------------

error[E0308]: mismatched types
   --> src/path.rs:725:34
    |
725 |             if unsafe { (statfn)(path.as_ptr(), buf.as_mut_ptr()) } < 0 {
    |                         -------- ^^^^^^^^^^^^^ expected `*const i8`, found `*const u8`
    |                         |
    |                         arguments to this function are incorrect
    |
    = note: expected raw pointer `*const i8`
               found raw pointer `*const u8`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `fish` (lib) due to 2 previous errors
2025-09-16 20:03:40 +02:00
Johannes Altmanninger
f69c2a4d4a fish_config: silence error when compiled without embed-data 2025-09-13 15:14:13 +02:00
Johannes Altmanninger
3f7a576835 Support installing to nested subdirectory of CMAKE_BINARY_DIR
The only install directory that's not supported is
-DCMAKE_INSTALL_PREFIX=$CARGO_MANIFEST_DIR, but that's a bad idea
anyway since share/ is Git-tracked.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
75cedd8039 config_paths: extract variable 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
a2c6e22d13 build.rs: don't define unused build environment variables
We set a lot of variables that are never used with
--feature=embed-data.  Remove them.  I don't think this change will
cause any problems with caching.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
aaf5ed7f11 build.rs: fix fallback PATH when embed-data is enabled
On a system where _CS_PATH is not defined (tested by removing that
code path), we get:

	$ cargo b && env -u PATH HOME=$PWD target/debug/fish -c 'set -S PATH'
	$PATH[1]: |.local//bin|
	$PATH[2]: |/usr/bin|
	$PATH[3]: |/bin|

The relative $PATH[1] makes no sense; probably it's an
accident. Restore the traditional $PATH[1]=/usr/local/bin.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
35d791ed49 config_paths: get rid of global variable, initialize locale predictably
Commit bf65b9e3a7 (Change `gettext` paths to be relocatable (#11195),
2025-03-30) made the locale directory (/usr/local/share/locale)
relocatable as well, so that "mv /usr/local /usr/local2" would not
break translations.

But this introduces a weird circular dependency, which was probably
the reason why the locale directory hadn't been relocatable:
1. option parsing might fail and print error messages, which should
   be localized, hence require detection of config paths
2. detection of config paths calls `FLOG`, which depends on options
   parsing (e.g. "-d config -o /tmp/log")

Since commit bf65b9e3a7, fish initializes the config paths
lazily, as soon as needed by translations.

When initializing config paths, we produce logs.  The logs are off by
default so its' fine in practical cases, but technically we should only
log things after we have handled things like FISH_DEBUG_OUTPUT.

Here's an example where the config directory initialization sneakily
injected by an error message's "wgettext_fmt!" causes logs to be
printed to the wrong file spuriously:

	$ FISH_DEBUG='*' FISH_DEBUG_OUTPUT=/tmp/log build/fish --unknown-arg
	config: exec_path: "./build/fish", argv[0]: "./build/fish"
	config: paths.sysconf: ./etc
	config: paths.bin: ./build
	config: paths.data: ./share
	config: paths.doc: ./user_doc/html
	config: paths.locale: ./share/locale
	fish: --unknown-arg: unknown option

Now we could handle "-d config", "-o", and FISH_DEBUG later, but
that would mean that in this example we don't get any logs at all,
which doesn't seem correct either.

Break the circular dependency by determining config paths earlier,
while making sure to log the config path locations only after parsing
options, because options might affect whether we want to log the
"config" category.

The global variable is only needed for locale, so use explicit argument
passing for everything else, as before.

While at it, make other binaries (fish_key_reader, fish_indent) use
the same localization logic as fish. This means that we need to tweak
the «ends_with("bin/fish")» check.

Closes #11785
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
a7f8e294ba config_paths: remove rogue use of std::env::args() 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
01ae00c653 config_paths: remove weird and redundant path handling
This duplicates work already done in get_executable_path().  No idea
why this was added.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
ee8a88a101 config_paths: rework logging a little
The executable path is used for embedded builds too, so let's log
it always.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
b4697231d7 config_paths: remove a comment
I'm not sure if setting PROGRAM_NAME based on argv[0] is a good idea.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
6cddceb37a config_paths: use immutable/SSA style for determining config paths
This logic is extremely confusing because it creates a ConfigPaths
object only to throw it away later. Fix that.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
8640ce8148 config_paths: embed-data has no doc dir
This makes no sense:

	$ target/debug/fish -d config
	config: paths.doc: .local/share/doc/fish

so remove it.

While at it, group config paths by whether they can be embedded.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
f7a2d56046 config_paths: model embed-data dichotomy better
Rather than having every single config path be an Option<Path>,
clarify that we define either all or nothing.

If we want to decide this at runtime, we'd use an enum; but it's all
known at compile time, so we can give the reader even more information.

Unfortunately this means that compile errors in non-embed-data
code paths might go unnoticed for a while, and rust-analyzer often
doesn't work in those code paths. But that's a general problem with
the compile-time feature, it seems orthodox to ifdef away as much
as possible.

There are some odd data paths that don't follow the "all or nothing",
the next commits will fix this.

Note that this breaks localization for target/debug/fish built with
embed-data. But as soon as fish was moved out of the repo, that was
already broken.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
cacb9f50b8 config_paths: use early return 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
cef60fe585 config_paths: remove obsolete installable vars
Same reason as the grandparent commit.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
04a2398c90 config_paths: separate ifdef'd path logic into functions
No functional change, only reduce the number of times we check for
presence of the embed-data feature.

While at it, move ConfigPaths?
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
f05ad46980 config_paths: remove vestiges of installable builds
Commit 3dc49d9d93 (Allow installable builds to be installed into a
specific path (#10923), 2024-12-22) added some ifdefs to use installed
config paths for installable builds that have already been installed.

The "installable" feature has been superseded by "embed-data"
which no longer uses config paths to retrieve files,
so remove those code paths. Further cleanup to follow.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
e9595d4817 config_paths: remove dead code trying to handle in-tree CMake builds
Assuming every in-tree build uses CMake, the source tree must
also be a valid build directory, so we already return in the
env!("FISH_BUILD_DIR") code path above.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
deabcf5478 config_paths: fix comment 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
e73243b879 Reuse workspace_root() helper from fish-build-helper 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
632b6582c5 builds.rs: canonicalize workspace root and build dir only when necessary
This means we can remove the unwrap() calls from fish-build-helper,
which paves the way for reusing it in the config_paths module.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
27db0e5fed Rename repo_root to workspace_root
This seems like a slightly better term
because I think it also applies to tarball.
Ref: https://github.com/fish-shell/fish-shell/pull/11785#discussion_r2335280389
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
33735f507a Fix regression causing build/fish to use wrong config paths
Commit 8b102f2571 (Stop using Cargo's OUT_DIR,
2025-06-22) accidentally removed canonicalization of
FISH_BUILD_DIR=${CMAKE_BINARY_DIR}.  This means that if the path to
${CMAKE_BINARY_DIR} includes a symlink, ${CMAKE_BINARY_DIR}/fish will
wrongly use /usr/share/fish instead of ${CARGO_MANIFEST_DIR}/share.
Fix this and reintroduce the comment.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
bde8a5aa40 path: fix inconsistency in default PATH
path_get_path does not use "getconf PATH", for no apparent reason.
Fix that.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
e0cd9e2e0a bin/fish.rs: remove dead argv fallback
I think argv[0] is guaranteed to be non-null.
2025-09-13 15:12:23 +02:00
Johannes Altmanninger
7e1123fb42 bin/fish.rs: remove needless clone 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
f7648757f1 autoload: simplify conditional compilation 2025-09-13 15:12:23 +02:00
Johannes Altmanninger
78d46f4b47 fish_indent.rst: remove missing debug options 2025-09-13 15:11:35 +02:00
Johannes Altmanninger
443956b8e3 ci: run clippy without --features=embed-data too
That configuration is already tested, but not clippy-checked yet.
This sometimes causes things like unused imports linger on master.
Let's at least enable clippy for stable Rust.

Also do the same build_tools/check.sh; since that script already runs
"cargo test --no-default-features", this shouldn't add much work,
though I didn't check that.
2025-09-13 15:10:24 +02:00
Johannes Altmanninger
a58cd12c4d Merge pull request #11779 2025-09-13 15:10:24 +02:00
Johannes Altmanninger
89883b791d checks/po-files-up-to-date.fish: mention how to update translations
As pointed out in
https://github.com/fish-shell/fish-shell/issues/11610#issuecomment-3240489072
2025-09-13 15:10:24 +02:00
Johannes Altmanninger
7706ce2e82 Merge pull request #11794 2025-09-13 15:10:24 +02:00
Daniel Rainer
027ea88477 Use deterministic timestamps for embedded data
We do not need timestamps of embedded files, so setting them to 0
reduces the potential for unwanted changes to the binary, allowing for
better build reproducibility.
2025-09-12 16:43:55 +02:00
Daniel Rainer
6cbd655b3d Update to rust-embed 8.7.2
This is the most recent version, which allows using the
`deterministic-timestamps` feature.
2025-09-12 16:43:03 +02:00
Johannes Altmanninger
529f722d2f build_tools/release.sh: fixes for updating fish-site
Also check that "cd fish-site && make && make new-release" doesn't
leave behind untracked files we're not aware of.  This implies that
this script ought to refuse to run if there are untracked files,
at least in fish-site.
2025-09-12 12:49:29 +02:00
Johannes Altmanninger
7619fa316c Release 4.0.6
Created by ./build_tools/release.sh 4.0.6
2025-09-12 11:47:41 +02:00
Johannes Altmanninger
e2005c64b3 Backport release-script related changes from master
Will commit these to master momentarily (#10449).
2025-09-12 11:47:01 +02:00
Johannes Altmanninger
f9dbb4d419 github workflows: actually include the tarballs in the release 2025-09-12 11:46:24 +02:00
Johannes Altmanninger
5e658bf4e9 Release automation script
Things that are not currently happening in this workflow:
- No GPG-signature on the Git tag
- No *.asc signature file for the tarball (or for any other release assets)
- No GPG-signed Debian and other OBS packages

To-do:
- remove the corresponding entries from
  https://github.com/fish-shell/fish-shell/wiki/Release-checklist
  and link to this workflow.
- Maybe add some testing (for the Linux packages)?.
- Let's hope that this doesn't cause security issues.

Usage:
1. run "build_tools/release.sh $version"; this will create and push
   a tag, which kicks off .github/workflows/release.yml
2. wait for the draft release to be created at
   https://github.com/fish-shell/fish-shell/releases/tags/$version
3. publish the draft (manually, for now). This should unblock the
   last part of the workflow (website updates).

Closes #10449

Incremental usage example:

	version=4.0.3
	repository_owner=fish-shell
	remote=origin
	cd ../fish-shell-secondary-worktree
	git tag -d $version ||:
	git push $remote :$version ||:
	git reset --hard origin/Integration_$version
	for d in .github build_tools; do {
		rm -rf $d
		cp -r ../fish-shell/$d .
		git add $d
	} done
	git commit -m 'Backport CI/CD'
	echo "See https://github.com/$repository_owner/fish-shell/actions"
	echo "See the draft release at https://github.com/$repository_owner/fish-shell/releases/$version"
	../fish-shell/build_tools/release.sh $version $repository_owner $remote
2025-09-12 11:42:59 +02:00
Johannes Altmanninger
9ada3e6c16 Group changelog entries 2025-09-12 11:14:52 +02:00
Johannes Altmanninger
0c7e7e3fd9 Add sphinx-markdown-builder for generating release notes
Without this, Sphinx refuses to use the "-b markdown" builder (see next commit).
2025-09-12 10:48:21 +02:00
Johannes Altmanninger
ebcb2eac68 github workflows staticbuild: use stable Rust on Linux
We use the MSRV for CI checks, and for deploying to old macOS.
But for static Linux builds , there should be no reason to use an
old Rust version.  Let's track stable.
2025-09-12 10:48:21 +02:00
Johannes Altmanninger
a7d50c1a62 CHANGELOG: minor updates 2025-09-12 10:48:21 +02:00
Johannes Altmanninger
6056b54ddb Rename build_tools/make_pkg.sh
pkg is a pretty subtle name?
2025-09-11 14:17:40 +02:00
Johannes Altmanninger
bdba2c227d CHANGELOG: update 2025-09-11 13:55:30 +02:00
Johannes Altmanninger
2563adfee1 github workflows: mac_codesign: clean up 2025-09-10 12:41:51 +02:00
Johannes Altmanninger
acad6e6a92 github workflows autolabel: remove stale milestone code
We look for a milestone that no longer exists.
Remove this until we find a solution.
2025-09-10 12:41:51 +02:00
Johannes Altmanninger
9faf78d269 github actions: fix warning about unexpected inputs
CI runs show warnings like

	ubuntu-32bit-static-pcre2
	Unexpected input(s) 'targets', valid inputs are ['']

This is about the rust-toolchain action, which is a composite action, see
https://docs.github.com/en/actions/tutorials/create-actions/create-a-composite-action
not a full workflow
https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows

Looks like composite actions specify inputs at top level.
Also they should not need «on: ["workflow_call"]».

The unexpected inputs are still forwared, so it happens to work.
Fix the warnings.
2025-09-10 12:41:51 +02:00
Johannes Altmanninger
201882e72a CHANGELOG: fix inline literal RST syntax 2025-09-09 07:46:31 +02:00
The0x539
b0565edf85 reader: add case-insensitive history autosuggest
Resolves issue #3126

To match what I've been able to figure out about the existing design
philosophy, case-sensitive matches still always take priority,
but case-insensitive history suggestions precede case-insensitive
completion suggestions.
2025-09-08 22:26:02 -05:00
Johannes Altmanninger
80fff4439f Merge pull request #11784 2025-09-08 11:11:21 +02:00
Johannes Altmanninger
54c48e20d3 completions/ansible: update translations 2025-09-08 11:11:21 +02:00
Johannes Altmanninger
c1af3f2a8f Merge pull request #11783 2025-09-08 11:11:21 +02:00
Johannes Altmanninger
01d7f93917 Merge pull request #11782 2025-09-08 11:08:31 +02:00
Johannes Altmanninger
a9be7b0298 Merge pull request #11781 2025-09-08 11:07:56 +02:00
ookami
5d66e02412 create_manpage_completions.py: Fix options_parts_regex
Escape the dot before "RE".

Fix matching options containing "RE", e.g. ADDRESS.
2025-09-08 10:14:21 +08:00
Vincent Rischmann
18ed4f5f10 Add completion for become-password-file option 2025-09-07 00:51:36 +02:00
Lucas Garron
0f609e7054 build_tools/update_translations.fish --no-mo 2025-09-05 21:07:13 -07:00
Lucas Garron
b77ea98ee0 npm install completions: add --save-peer flag
It's unclear if there is a short flag, since `npm install --help` does not list all short flags.
2025-09-05 18:46:53 -07:00
Johannes Altmanninger
1db0ff9f77 Allow overriding __fish_update_cwd_osc to work around terminal bugs
See #11777

While at it, pull in the TERM=dumb check from master.

(cherry picked from commit 898cc3242b)
2025-09-05 09:39:57 +02:00
Johannes Altmanninger
898cc3242b Allow overriding __fish_update_cwd_osc to work around terminal bugs
See #11777
2025-09-05 09:38:25 +02:00
Nathan Chancellor
66940e8369 completions/systemctl: Handle --boot-loader-entry and --boot-loader-menu
systemd 242 added two new options to halt, poweroff, and reboot:

  --boot-loader-entry: Reboot to a specific boot loader entry
  --boot-loader-menu: Reboot into boot loader menu with specified
                      timeout

Add these to the systemctl completion so that it is easy to
interactively select available entries.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
2025-09-04 19:25:56 -07:00
Johannes Altmanninger
f98bf3d520 functions/man: use "command man", skipping functions
As reported in
https://github.com/fish-shell/fish-shell/issues/11767#issuecomment-3240198608,
the new "man" function uses "rm" which is sometimes overidden to do
"rm -i".

Same as d3dd9400e3 (Make sure the rm command and not a wrapper
function that could change its behaviour is used. 2006-12-12)

While at it, make sure that all users of __fish_mktemp_relative
1. return if mktemp fails
2. actually clean up their temporary directory -- except for help.fish
   which spawns an asynchronous browser window.
2025-08-31 17:33:24 +02:00
Johannes Altmanninger
90862c5c57 edit_command_buffer: remove dead code 2025-08-31 17:29:07 +02:00
Johannes Altmanninger
4abdc8716b share/functions/__fish_mktemp_relative: adopt argparse -u 2025-08-29 22:23:53 +02:00
Johannes Altmanninger
4ba070645d Merge pull request #11763 2025-08-29 22:23:53 +02:00
Johannes Altmanninger
4a12d57711 Merge pull request #11698 2025-08-29 22:23:52 +02:00
Johannes Altmanninger
8741e201de Install fish-terminal-compatibility man page
Not sure about whether "man fish-terminal-compatibility"; it's not
really meant for end-users, but it also doesn't hurt raise awareness
of the existence of this doc.

Either way, we should be consistent with embedded builds, where this
works since the parent commit.
2025-08-29 22:23:52 +02:00
Johannes Altmanninger
c3c3a9518c functions/man: fix for embedded fish-* man pages
"man abbr" works in embed-data builds,
but "man fish-faq" doesn't.

This is because it delegates to

	__fish_print_help fish-faq

which skips all lines until the NAME section:

	contains -- $name NAME; and set have_name 1

but the NAME section doesn't exist for this man pages, it only exists
for docs from doc_src/cmds/*.rst.

Let's use the "man" utility instead; this is also what the user
asked for.  Unfortunately we can't use "status get-file | man -l -"
because that's not supported on BSD man.  Note that man displays the
basename of the file, so make sure it looks good.
2025-08-29 22:23:52 +02:00
Johannes Altmanninger
0ebd41eb9f Extract function for calling mktemp
BSD mktemp doesn't support GNU mktemp's -t or --tmpdir option, so when
we want a named temporary file, we need to compute ${TMPDIR:-/tmp}
ourselves, see 5accc7c6c5 (Fix funced's tmpfile generation on OSX,
2016-05-23).

While at it, use template like "fish.XXXXXX"; seems like a good idea?

Take care to have edit_command_buffer use a pretty filename.
2025-08-29 22:23:27 +02:00
Johannes Altmanninger
35733a0f8d functions/man: allow "man !"
Analogous to the "! -h" code path.
2025-08-29 22:00:25 +02:00
Johannes Altmanninger
c1f6e0c03e CONTRIBUTING: mention sourcehut mailing list 2025-08-29 21:11:24 +02:00
Johannes Altmanninger
c36e7967e2 CONTRIBUTING: recommend build_tools/check.sh 2025-08-29 20:32:58 +02:00
Johannes Altmanninger
7f91e029fb CONTRIBUTING: remove mention of Coverity
Seems stale?
2025-08-29 20:32:58 +02:00
Johannes Altmanninger
ca131f7440 README: mention Python version also in build dependencies 2025-08-29 20:32:58 +02:00
Johannes Altmanninger
df3fc48a21 README: mention /bin/sh dependency
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$39FQId4CHJ6yT8B4S4smD4MDbxp4pT8Eio-cGP0KoEU
we currently require "sh -c" for some background tasks.  Document this.
2025-08-29 20:32:58 +02:00
Johannes Altmanninger
9258275fe6 config_paths: fix compiled-in locale dir for installed, non-embed builds
Commit bf65b9e3a7 (Change `gettext` paths to be relocatable (#11195),
2025-03-30) broke the locale path.

Commit c3740b85be (config_paths: fix compiled-in locale dir,
2025-06-12) fixed what it calls "case 4", but "case 2" is also
affected; fix that. Before/after:

	$ ~/.local/opt/fish/bin/fish -d config
	paths.locale: /home/johannes/.local/opt/fish/share/fish/locale
	$ ~/.local/opt/fish/bin/fish -d config
	paths.locale: /home/johannes/.local/opt/fish/share/locale

See https://github.com/fish-shell/fish-shell/issues/11683#issuecomment-3218190662

(cherry picked from commit 21a07f08a3)
2025-08-29 19:29:03 +02:00
Isaac Oscar Gariano
6149ac4e40 Added a -C/--center option to string pad.
The --center option does exactly what you'd expect. When a
perfectly centred result is not possible, this adds extra padding to
the left. If the --right option is also given, the extra padding is
added to the right.
2025-08-30 02:57:01 +10:00
Isaac Oscar Gariano
d82442991b Fix argparse documentation to make it clear that -n takes an argument. 2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
944cfd181e Added a -v/--validate option to fish_opt
This new flag causes fish_opt to generrate an option spec with !
(e.g. "fish_opt -s s -rv some code" will output "s=!some code").

Such validation scripts are not particular useful (they are highly limited as
they cannot access the values for other options, and must be quoted
appropriately so they can be passed to argparse). I merely added the option to
fish_opt so that it can now generate any valid option spec.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
007edac145 Make argparse reject supplying a validator for boolean flags
Specifically, this commit simply makes argparse issue an error if you use the !
syntax to define a validation script on an option that does not take any
arguments. For example, "argparse foo!exit -- --foo" is now an error. This was
previously accepted, despite that fact that the code after ! would never be
executed (the ! code is only executed when an option is given a value).

Alternatively, ! validation scripts could be made to execute even when no value
was provided, but this break existing code that uses them with flags that take
optional values.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
c403822fac Modified argparse to support one character long only options.
This fixes an issue noticed in the previous commit (the made the -s/--short
option optional to fish_opt): it was impossible to define a single character
long flag, unless you also provided a single-character short flag equivalent.

This commit works by allowing an option spec to start with a '/', treating the
subsequent alpha-numeric characters as a long flag name.

In detail, consider the following:
- s defines a -s short flag
- ss defines an --ss long flag
- /ss (new) also defines a --ss long flag
- s/s defines a -s short flag and an --s long flag
- s-s defines a --s long flag (if there's already an -s short flag, you'd have
    to change the first s, e.g. S-s)
- /s (new) defines a --s long flag
- s/ is an error (a long flag name must follow the /)

Note that without using --strict-longopts, a long flag --s can always be
abbreviated as -s, provided that -s isn't defined as a separate short flag.

This 'issue' fixed by this commit is relatively trivial, however it does allow
simplifying the documentation for fish_opt (since it no longer needs to mention
the restriction). In particular, this commit makes the --long-only flag to
fish_opt completely unnecessary (but it is kept for backwards compatibility).
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
663430a925 Added support to fish_opt for defining a long flag with no short flag.
Specifically, this now makes the -s/--short option to fish_opt optional when the
-l/--long option is given. This commit does not modify argparse, as it already
supports defining long flags without a corresponding short flag, however
fish_opt would never take advantage of this feature.

Note that due to a limitation in argparse, fish_opt will give an error if you
try to define a one-character --long flag without also providing a --short
option.

For backwards compatibility, the --long-only flag is still included with
fish_opt, and when used with -s/--short, will behave as before (the short flag
is still defined, but argparse will fail if it is actually used by the parsed
arguments, moreover the _flag_ option variables will not be defined). This can
however be used to define a one character long flag.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
4db61ee117 Added argparse support for arguments with multiple optional values.
This commit fixes #8432 by adding put =* in an option spec to indicate that the
option takes an optional value, where subsequent uses of the option accumulate
the value (so the parsing behaviour is like =?, but the _flag_ variables are
appended to like =+). If the option didn't have a value, it appends an empty
string. As an example,. long=* -- --long=1 --long will execute
set -l _flag_long 1 '' (i.e. count $_flag_long is 2), whereas with =? instead,
you'd get set -l _flag_long (i.e. count $_flag_long is 0).

As a use case, I'm aware of git clone which has a
--recurse-submodules=[<pathspec>]: if you use it without a value, it operates on
all submodules, with a value, it operates on the given submodule.

The fish_opt function will generate an =* option spec when given both the
--optional-val and --multiple-vals options (previously, doing so was an error).
fish_opt now also accepts -m as an abbreviation for --multiple-vals, to go with
the pre-existing -o and -r abbreviations for --optional-val and --required-val.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
9d56cdbcbc Added a -U/--unknown-arguments option to argparse
The new -U/--unknown-arguments option takes either 'optional', 'required', or
'none', indicating how many arguments unknown options are assumed to take.
The default is optional, the same behaviour as before this commit, despite
most options in practice taking not taking any arguments. Using
--unknown-arguments=required and --unknown-arguments=none (but not
--unknown-arguments=optional) can give you parse errors if, respectively,
an unknown option has no argument (because it the option is at the end of the
argument list), or is given an argument (with the `--flag=<value> syntax).
See doc_src/cmds/argparse.rst for more details (specifically, the descritpion
of the --unknown-arguments flag and the example at the end
of the examples section).

As a convenience, -U/--unknown-arguments implies -u/--move-unknown.
However you can use it the deprecated -i/--ignore-unknown if you really want to.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
8ae685cf27 Refactored argparse code by removing ArgCardinality type.
This just uses an ArgType and 'accumulate_args' bool in place of the old
ArgCardinality. Curently only one of the three kinds of an ArgType can
have both a true and false accumulate_args. But this will be extended to
two of three in a future commit.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
24eeed65a2 Added an -S/--strict-longopts option to argparse.
This flag disables a very surprising and confusing feature I found in the code
of wgetopt.rs: the ability to abbreviate the names of long options and the
ability to parse long options with a single "-". This commit addresses #7341,
but unlike pull request #11220, it does so in a backwards compatible way: one
must use the new -S/--strict-longotps flag to disable the old legacy behaviour.

Unlike pull request #11220 however, this flag only applies to ``argparse``,
and not to any builtins used by fish.

Note that forcing the flag -S/--strict-longotps on (i.e. in  src/wgetopt.rs,
replacing both uses of `self.strict_long_opts` with `true`), does not cause any
of the current test cases to fail. However, third-party fish scripts may be
depending on the current behaviour.
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
70dca1e136 Give a more helpful error when a boolean option has an argument.
This fixes an issue very similar to #6483,
For example, fish --login=root used to print this:
    fish: --login=root: unknown option
But `--login` is a valid option to fish.
So the above now prints:
    fish: --login=root: option does not take an argument

This is done by modifying WGetOpter so that it returns a ';' if it encountered
an option with an argument, but the option was not declared as taking an option
(this is only possible with the --long=value or legacy -long=value syntax).
All uses of WGetOpter (except echo, fish_indent, and some tests) are modified to
then print an appropriate error message when ';' is returned.
echo doesn't have any long options, so it will panic if gets a ';'.
fish_indent doesn't print any error messages for invalid options anyway, and I
wasn't sure if this was intentional or not.

Moreover, WGetOpter now always returns a ':' for options that are missing an
argument. And you can no longer prefix a your option spec with a ':' to enable
this (since every use of WGetOpter was doing this anyway, except
wgetopt::test_exchange and tests::wgetopt::test_wgetopt).
2025-08-30 01:55:56 +10:00
Isaac Oscar Gariano
c94eddaf4b Replaced all uses of argparse -i with argparse -u
This removes the functions/completions that were using the deprecated
--ignore-unknown option and replaces it with the new --move-unknown.

Although some of the code is now more verbose, it has improved the
functionality of two completions:
    the iwctl completion will now skip over options when detecting
        what subcommand is being used
    the ninja completion wil now handle -- correctly: if the completion
        internally invokes ninja, it will correctly interpret the users
        arguments as being arguments if they start with a - and occur
        after the --.
2025-08-30 01:10:03 +10:00
Isaac Oscar Gariano
51d16f017d Added a -u/--move-unknown option to argparse.
--move-unknown is like --ignore-unknown, but unknown options are instead moved
from $argv to $argv_opts, just like known ones. This allows unambiguously
parsing non-option arguments to other commands. For example if $argv contains
`--opt -- --file`, and we execute `argparse --move-unknown -- $argv`, we can
then call `cmd $argv_opts -- --another-file $argv`, which will correctly
interpret `--opt` as an option, but `--file` and `--some-file` as an argument.
This makes `--move-unknown` a better alternative to `--ignore-unknown`, so the
latter has been marked as deprecated, but kept for backwards compatibility.
2025-08-29 23:10:02 +10:00
Isaac Oscar Gariano
5a7e5dc743 Make argparse separate known and unknown options that occur in a group together.
For example, argparse --ignore-unknown h -- -ho will now set set $argv to -o and
$argv_opts to -h (i.e. -ho is split into -h and -o). Previously, it would set
$argv to -ho, and $argv_opts to empty. With this change, the "Limitations"
section of argparse's man page has been removed, and the examples merged into
the description of the -i/--ignore-unknown option. (Note: there was another
'limitation' mentioned in the 'limitations' section: that everything occuring
after an unknown option in a group was considered an argument to an option; the
documentation has been reworded to make it clear that this is intended
behaviour, as unknown options are always treated as taking optional arguments,
and modifying that behaviour would be a breaking change and not a bug fix).
2025-08-29 23:10:02 +10:00
Isaac Oscar Gariano
f780b01ac9 Added way to tell argparse to delete an option from $argv_opts.
The intention is that if you want to parse some of your options verbatim to
another command, but you want to modfy other options (e.g. change their value,
convert them to other options, or delete them entirely), you mark the options
you want to modify with an &, and argparse will not add them to argv_opts. You
can then call the other command with argv_opts together with any new/modified
options, ensuring that the other command doesn't set the pre-modified options.
As with other known options, & options will be removed from $argv, and have
their $_flag_ variables set.

The `&` goes at the end of the option spec, or if the option spec contains a
validation script, immediately before the `!`. There is also now a -d/--delete
flag to fish_opt that will generate such an option spec.

See the changes in doc_src/cmds/argparse.rst for more details and an example use
case.
2025-08-29 23:10:02 +10:00
Isaac Oscar Gariano
ddcb1813a7 Clarified & fixed documentation for fish_opt options.
The previous fish_opt synopsis was hard to parse, and was incorrect:
- it indicated that -s is optional
- it indicated that only one option could be provided
- it indicated that every option took a value
2025-08-29 23:10:02 +10:00
Isaac Oscar Gariano
e62abc460d Make argparse save parsed options in $argv_opts. (Fixes #6466)
Specifically, every argument (other than the first --, if any) that argparse
doesn't add to $argv is now added to a new local variable $argv_opts. This
allows you to make wrapper commands that modify non-option arguments, and then
forwards all arguments to another command. See the new example at the end of
doc_src/cmds/argparse.rst for a use case for this new variable.
2025-08-29 23:10:02 +10:00
Isaac Oscar Gariano
e6b4f0a696 Stopped argparse tests from leaking local variables.
By wrapping the various argparse tests in begin ... end blocs, it makes it much
easier to debug test failures and add new tests. In particular, each block is
independent, and shouldn't affect any subsequent tests. There's also now a check
at the end of the test file to ensure that the tests are no longer leaking local
variables.
2025-08-29 23:10:02 +10:00
Johannes Altmanninger
c0c9245d99 completions/java_home: fix version completion due to change of osascript default output
Apparently the last expression outputs to stdout.

Closes #11743
2025-08-27 10:01:51 +02:00
Isaac Oscar Gariano
f843d5bd34 Disable editor hard wrapping for .rst and .md files.
The .md and .rst files allready present do not hard wrap lines (the
style seems to be one line per paragraph, which could be a few hundred
characters long). So this makes those files have no line length limit,
instead of 100.
2025-08-27 10:01:51 +02:00
Johannes Altmanninger
6900b89c82 Add mark-prompt feature flag
So far, terminals that fail to parse OSC sequences are the only reason
for wanting to turn off OSC 133.  Let's allow to work around it by
adding a feature flag (which is implied to be temporary).

To use it, run this once, and restart fish:

    set -Ua fish_features no-mark-prompt

Tested with

    fish -i | string escape | grep 133 &&
    ! fish_features=no-mark-prompt fish -i | string escape | grep 133

See #11749
Also #11609
2025-08-27 09:17:35 +02:00
Johannes Altmanninger
4a9fd1bbbb completions/loginctl: accept alphabetic session names
systemd's session_id_valid accepts [a-zA-Z0-9], so allowing only
numbers is wrong.

Fixes #11754

While at it, correct the description; instead of
showing the leader PID, show the seat, which is probably
2025-08-27 08:34:16 +02:00
Daniel Rainer
7b8efe3105 Remove Optional annotation
The is inconsistent with the type annotation of `TestPass.duration_ms`.
The function is only called with `duration_ms` as an int, so there is no
need to declare it `Optional`.
2025-08-26 20:54:02 +08:00
Daniel Rainer
425d487de9 Remove redundant clones 2025-08-25 10:24:03 +02:00
Johannes Altmanninger
21a07f08a3 config_paths: fix compiled-in locale dir for installed, non-embed builds
Commit bf65b9e3a7 (Change `gettext` paths to be relocatable (#11195),
2025-03-30) broke the locale path.

Commit c3740b85be (config_paths: fix compiled-in locale dir,
2025-06-12) fixed what it calls "case 4", but "case 2" is also
affected; fix that. Before/after:

	$ ~/.local/opt/fish/bin/fish -d config
	paths.locale: /home/johannes/.local/opt/fish/share/fish/locale
	$ ~/.local/opt/fish/bin/fish -d config
	paths.locale: /home/johannes/.local/opt/fish/share/locale

Fixes https://github.com/fish-shell/fish-shell/issues/11683#issuecomment-3218190662
2025-08-25 10:11:01 +02:00
David Adam
67e8657109 debian packaging: don't remove Cargo.toml.orig files
Newer versions of cargo include the Cargo.toml.orig file when vendoring,
but dh_clean removes those by default. Try to disable this to fix the
package builds again.
2025-08-23 19:40:53 +08:00
Daniel Rainer
e96300b08e Build man pages in separate crate
Building man pages takes significant time due to Sphinx running for several
seconds, even when no updates are required. Previously, we added custom logic to
avoid calling `sphinx-build` if the inputs to `sphinx-build` had not changed
since a cached timestamp.

By moving this into its own crate, we can tell cargo to rebuild when the input
files changed and unrelated changes will have no effect on this crate. This
allows us to get rid of the custom code for tracking whether to recompile, while
keeping the effect of only calling `sphinx-build` when appropriate.

In order to avoid code duplication, a new `build-helper` crate is added,
which contains some functionality for use in `build.rs`.

Closes #11737
2025-08-22 09:14:56 +02:00
Daniel Rainer
32e5fa0c03 Stop depending on fish_indent for man pages
This allows building man pages without having `fish_indent` available, which is
useful because building man pages can happen during compilation of the fish
binaries, including `fish_indent`, resulting in an annoying cyclic dependency.

This change does not affect the generated man pages, at least with the current
config.
2025-08-22 09:12:10 +02:00
Daniel Rainer
e895f96f8a Do not rely on fish_indent for version in Sphinx
Depending on `fish_indent` when building docs is problematic because the docs
might get built before `fish_indent` is available. Furthermore, a version of
`fish_indent` which does not correspond to the current build might be used,
which would result in incorrect version information.

Use the `git_version_gen.sh` script instead to ensure up-to-date version
information without depending on build output.
2025-08-22 09:12:10 +02:00
Johannes Altmanninger
92f7063acb Use version=0.0.0 for unpublished crates
As discussed in #11737
2025-08-22 09:12:10 +02:00
Daniel Rainer
cd71801360 Use workspace dependencies exclusively
This allows us to track all dependencies in a single place and
automatically avoids using different versions of the same dependency in
different crates.

Sort dependencies alphabetically.

Closes #11751
2025-08-22 09:12:10 +02:00
Daniel Rainer
24898c61af Sync dependency versions of crates
This is done to allow merging all dependencies into workspace
dependencies.
2025-08-21 21:39:35 +02:00
Johannes Altmanninger
62b7c81052 Merge pull request #11742 2025-08-21 20:40:33 +02:00
Daniel Rainer
d32ce89889 Remove unnecessary rebuild paths
Cargo tracks normal Rust dependencies and automatically figures out if changes
to Rust source files, `Cargo.{toml,lock}`, and `build.rs` necessitate a rebuild,
and if so of what. In some cases these checks are smarter than just comparing
file modification times, so not specifying such paths explicitly can reduce the
amount of rebuilding which happens, without skipping necessary rebuilding.

ja: this reverts b2aaf1db52 (Rebuild if src changed, 2025-03-28) and
460b93a (Rebuild on changes relevant to build artifacts, 2025-03-30)
which tried to fix #11332 ("moving Git HEAD does not invalidate cargo
build results").  But that expectation is overbearing.  It's better
to only rebuild if something else of relevance to the build output
has changed.

Closes #11736
2025-08-21 20:40:33 +02:00
Henrik Hørlück Berg
16119377c3 Document --allow-empty, specify -r is only useful w/ -m
As noted in #11744
2025-08-21 00:06:24 +02:00
Kevin F. Konrad
5a45fec730 add completions for stackit CLI 2025-08-20 11:54:57 +02:00
Johannes Altmanninger
d26fd90efd Merge pull request #11741, closes #11741 2025-08-20 10:16:19 +02:00
Daniel Rainer
1c654f23af Put local dependencies in crates directory
With an increasing number of local dependencies, the repo root is getting
somewhat bloated. This commit moves the two current local dependencies into the
newly created `crates` directory, with the intention of using it for all future
local dependencies as well.

Some dependencies which are introduced by currently in-progress pull requests
will need modifications in order for relative paths to work correctly.
2025-08-20 10:16:19 +02:00
Johannes Altmanninger
b828822385 Merge pull request #11695 2025-08-20 10:14:34 +02:00
Johannes Altmanninger
e795ed4061 Merge pull request #11738 2025-08-20 10:14:27 +02:00
Johannes Altmanninger
3363d55ec4 staticbuild.yml: break up long line 2025-08-20 10:14:08 +02:00
Johannes Altmanninger
f8bfb7cb6b editorconfig: commit message line length is 72, not 80
This is more standard. Not sure how many people use editorconfig though.
2025-08-20 10:14:08 +02:00
Daniel Rainer
ce7733c75f Remove unnecessary parentheses
This was spotted by a lint on nightly Rust.
2025-08-19 00:26:21 +02:00
Johannes Altmanninger
feaec20de6 Run update_translations.fish 2025-08-18 14:10:46 +02:00
Daniel Rainer
514d34cc52 Add cargo feature for enabling gettext extraction
This allows having the proc macro crate as an optional dependency and speeds up
compilation in situations where `FISH_GETTEXT_EXTRACTION_FILE` changes, such as
the `build_tools/check.sh` script. Because we don't need to recompile on changes
to the environment variable when the feature is disabled, cargo can reuse
earlier compilation results instead of recompiling everything.
This speeds up the compilation work in `build_tools/check.sh` when no changes
were made which necessitate recompilation.
For such runs of `build_tools/check.sh`, these changes reduce the runtime on my
system by about 10 seconds, from 70 to 60, approximately.
The difference comes from the following two commands recompiling code without
the changes in this commit, but not with them:
- `cargo test --doc --workspace`
- `cargo doc --workspace`
2025-08-18 10:37:59 +02:00
Daniel Rainer
367696b346 Remove unnecessary into_iter call
Starting with Rust 1.90, this `into_iter` call triggers the
`clippy::useless_conversion` lint.
2025-08-17 20:20:09 -07:00
Daniel Rainer
70a9327858 Do not unwrap after checking with is_err
Doing so results in the `clippy::unnecessary_unwrap` lint starting with Rust
1.90 (in beta at the moment).
2025-08-17 20:20:09 -07:00
idealseal
a766c44a18 feat(comp): update networkctl completions 2025-08-17 20:17:00 -07:00
Peter Ammon
13d9aa0002 Changelog PR 11729 2025-08-16 11:22:45 -07:00
Bryce Berger
9273f352a0 allow psub --fifo --suffix ... 2025-08-15 15:02:44 -04:00
Johannes Altmanninger
79135c6c82 Merge pull request #11713, closes #11713 2025-08-15 18:11:07 +02:00
Daniel Rainer
5de43a4e86 Call fsync after appending to history file
This is an attempt to eliminate history file corruption as described in
https://github.com/fish-shell/fish-shell/issues/10300.
In particular, issues raised in
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2567063654
can benefit from such synchronization.
2025-08-15 18:10:20 +02:00
Daniel Rainer
188282a27b Don't redundantly unlink() temporary file after renaming
There is an unlikely issue if two shells are concurrently rewriting the
history file:
- fish A runs rename("fish_history.DEADBEEF") (rewriting a history file with)
- fish B starts rewriting the history file; since "fish_history.DEADBEEF" no longer exists, it can in theory use that filename
- fish A runs wunlink("fish_history.DEADBEEF"), destroying fish B's work

Fix this by not calling wunlink() iff we successfully rename it.

[ja: add commit message and fix "!do_save" case]
2025-08-15 17:50:04 +02:00
Johannes Altmanninger
f59e5884bf Merge pull request #11714
Closes #11714
2025-08-15 17:37:34 +02:00
Johannes Altmanninger
51dcadf7c6 completions/makepkg: remove stale --pkg option
Closes #11724
2025-08-15 17:24:18 +02:00
Daniel Rainer
ba2500211b Call fsync and close tmpfile before rename
This is another attempt at eliminating file corruption, primarily in connection
to the history file, as observed in
https://github.com/fish-shell/fish-shell/issues/10300.

Calling `fsync` and closing the tmpfile should ensure that when the renaming
happens, the file content and metadata are already in persistent storage.

Some background can be found in the following links, which were pointed out in
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2567063654:
https://www.comp.nus.edu.sg/~lijl/papers/ferrite-asplos16.pdf
https://archive.kernel.org/oldwiki/btrfs.wiki.kernel.org/index.php/FAQ.html#What_are_the_crash_guarantees_of_overwrite-by-rename.3F
2025-08-15 17:24:02 +02:00
Johannes Altmanninger
491ffb356b Merge pull request #11727 2025-08-15 16:48:34 +02:00
Daniel Rainer
b0ae11e769 Write only once when appending items
Building a buffer in advance and writing it once all items are serialized into
the buffer makes for simpler code, makes it easier to ensure that
`self.first_unwritten_new_item_index` is only updated if writing succeeded, and
it actually matches the previous behavior of the code in most realistic cases,
since previously there was only more than one `write_all` call if the serialized
items took up more than `HISTORY_OUTPUT_BUFFER_SIZE` bytes (64 * 1024), which
seems unlikely to occur during normal use, where mostly just a single item will
be appended.
2025-08-15 16:26:52 +02:00
Daniel Rainer
20e268a75c Clear file state earlier
This should not result in behavioral changes in the code, but it eliminates some
redundant variables and is a step in refactoring the function such that early
returns via `?` become sound.

Remove the `drop` since the lock will be dropped at this point anyway, there is
no need to be explicit about it.
2025-08-15 16:26:03 +02:00
Daniel Rainer
9c4c28da9d Use updated file id
This restores behavior from before f438e80f9b.
The file id changes when data is written to the file, so it needs to be updated
with data obtained after the updates to the file are completed.
2025-08-15 16:26:03 +02:00
Johannes Altmanninger
8219dd8af6 Merge pull request #11715 2025-08-15 16:19:03 +02:00
Johannes Altmanninger
781791c00c Revert "Add rust-toolchain.toml"
By default, we make every rustup user use our pinned version.  This might
not be ideal at this point, for a few reasons:
1. we don't have automatic Rust updates yet (see the parent commit),
   so this might unnecessarily install an old version. As a contributor,
   this feels irritating (newer versions are usually strictly better).
2. it will use more bandwidth and perhaps other resources during "git-bisect"
   scenarios
3. somehow rustup will download things redundantly; it will download "1.89.0"
   and "stable" even if they are identical. The user will need to clean
   those up at some point, even if they didn't add them explicitly.

See also
https://github.com/fish-shell/fish-shell/pull/11712#issuecomment-3165388330

Part of the motivation for rust-toolchain.toml is probably the regular
(every 6 weeks) failures due to the update check, but that failure has been
removed in the parent commit.

The other motivation ("fix the issue of local compiles running into lint
warnings from newer compilers") is a fair point but I think we should rather
fix warnings quickly.

Let's remove rust-toolchain.toml again until we have more agreement on what
we should do.

This reverts commits
* f806d35af8 (Ignore rust-toolchain.toml in CI, 2025-08-07)
* 9714b98262 (Explicitly use fully qualified rust version numbers, 2025-08-07)
* 921aaa0786 (Add rust-toolchain.toml, 2025-08-07)

Closes #11718
2025-08-15 16:10:18 +02:00
Johannes Altmanninger
d93fc5eded Revert "build_tools/check.sh: check that stable rust is up-to-date"
As reported in #11711 and #11712, the update-checks make check.sh automatically
fail every 6 weeks, so it pressures people into updating Rust, and (what's
worse), updating fish's pinned Rust version, even when that's not relevant
to their intent (which is to run `clippy -Dwarnings` and all other checks).

The update-checks were added as a "temporary" solution to make sure that
our pinned version doesn't lag too far behind stable, which gives us an
opportunity to fix new warnings before most contributors see them.

As suggested in #11584, reasonable solutions might be either of:
1. stop pinning stable Rust and rely on beta-nightlies to fix CI failures early
2. use renovatebot or similar to automate Rust updates

Until then, remove the update check to reduce friction.
I'll still run it on my machine.

This reverts commit 6d061daa91.
2025-08-15 15:08:48 +02:00
Daniel Rainer
b2dfb3fd6e Add completions for single-letter cargo aliases 2025-08-15 03:09:28 +02:00
Daniel Rainer
55122b127c Wrap renaming code in function
These changes are not intended to change any behavior. They are done to
facilitate closing the tmpfile before renaming, which is required for
correctness on some filesystems (at least btrfs). Using a `ScopeGuard` which
unlinks when the file is closed/dropped does not work in this context, so the
relevant code is wrapped in a function and the tmpfile is unlinked after the
function returns.
2025-08-12 19:50:53 +02:00
brennenputh
0adcbfa2ac Resolve review comments 2025-08-11 20:32:16 -04:00
Johannes Altmanninger
51fd00c98f Merge pull request #11717 2025-08-10 18:59:30 +02:00
Johannes Altmanninger
c123c4e866 Merge pull request #11691 2025-08-10 18:40:01 +02:00
Johannes Altmanninger
9003835452 Merge pull request #11701 2025-08-10 17:12:50 +02:00
Trevor Bender
cf044038e0 fix typo in completions.rst 2025-08-10 07:49:10 -04:00
brennenputh
6561a1d6ba Add distrobox completion script 2025-08-08 20:48:20 -04:00
Xiretza
894d4ecc53 Update to Rust 1.89, address newly added lints 2025-08-07 21:48:17 +00:00
Xiretza
f806d35af8 Ignore rust-toolchain.toml in CI
We set a specific default toolchain with dtolnay/rust-toolchain, we don't want
it to be overridden by the config intended for devs.
2025-08-07 21:47:36 +00:00
Xiretza
9714b98262 Explicitly use fully qualified rust version numbers
The action expands these internally, but then rust-toolchain.toml is interpreted
literally, and 1.88 is technically a different toolchain from 1.88.0.
2025-08-07 21:28:34 +00:00
Xiretza
921aaa0786 Add rust-toolchain.toml
This ensures that, by default, developers use the toolchain that is also tested
in CI, avoiding spurious warnings from lints added in new compiler versions.
2025-08-07 21:13:32 +00:00
Saeed M Rad
45bb8f535b funced: pretend copied functions are defined interactively
After #9542, the format for `functions -Dv` was changed for copied
functions.

```diff
-stdin
-n/a
+[path to copy location]
+[path to original definition]
 [and a few more lines]
```

Some components were (and perhaps are) still expecting the old format,
however. After a search, it looks like `funced` and `fish_config` are
the only two functions using `functions -D` and `functions -Dv` in this
repo (none are using `type -p`).

As noted in issue #11614, `funced` currently edits the file which
copies the given copied function. Another option was to make `funced`
edit the file which originally defined the function. Since the copied
function would not have been updated either way, I modified `funced` so
it would pretend that the copied function was defined interactively,
like it was before.

I did not modify `fish_config`, since it was only used for preset
prompts in the web config, none of which used `functions --copy`.
(Moreover, I believe it would have behaved correctly, since the preset
would not have had to define the function, only copy it.)

Fixes issue #11614
2025-08-07 10:19:42 +00:00
Bacal Mesfin
fa68770c16 Fix missed bottom right artifact 2025-08-04 13:01:19 -04:00
Bacal Mesfin
4b736fd92b Fix fish.png artifacts
The fish.png doc image has grey pixel artifacts in the
top-left, top-right, and bottom-right corners.

This patch takes the original image from 3a5b096
removes the artifacts, and compresses it with squoosh
to a similar file size.
2025-08-03 07:06:42 -04:00
Johannes Altmanninger
54e8ad7e90 Merge pull request #11623 2025-08-03 08:00:18 +02:00
Kid
944da7dba9 Fix copy paste error 2025-08-02 19:39:54 +08:00
Kid
c9945f3439 Use __fish_cache_sourced_completions 2025-08-02 18:05:46 +08:00
Kid
e8b2767dcc Add completion for pnpm 2025-08-02 18:00:23 +08:00
Johannes Altmanninger
5c216f48a3 Attempt to fix Opensuse Leap 15.6 nightlies
This has been failing because it uses Python 3.6.  Until we have figured
out when we can roll platform off (#11679), let's try to fix this.  Untested.
2025-08-02 11:07:22 +02:00
Johannes Altmanninger
320b8235ed Update README to reflect regained Cygwin/Msys2 support 2025-08-02 11:07:22 +02:00
Johannes Altmanninger
9c0086b7af Backport default alt-delete binding
This is standard on macOS and in chrome/firefox.

On master, this was sneakily added in
2bb5cbc959 (Default bindings for token movements v2, 2025-03-04)
and before that in
6af96a81a8 (Default bindings for token movement commands, 2024-10-05)

Ref: https://lobste.rs/s/ndlwoh/wizard_his_shell#c_qvhnvd
2025-08-02 09:53:22 +02:00
Johannes Altmanninger
f218cf2f38 Merge pull request #11686 2025-08-02 09:19:48 +02:00
Johannes Altmanninger
8158c227c3 Merge pull request #11672 2025-08-02 09:19:48 +02:00
Johannes Altmanninger
2549334bae Merge pull request #11693 2025-08-02 09:19:48 +02:00
ndrew222
ec60bf1898 added completions for glow 2025-07-30 13:25:12 +08:00
JJ
17e0f3d96f Add example of string manipulation to prompt_pwd 2025-07-28 19:55:18 -07:00
Branch Vincent
b4b0fc08da completions: add container 2025-07-26 12:13:05 -07:00
Johannes Altmanninger
e200abe39c __fish_seen_subcommand_from: fix regression causing false negatives given multiple arguments
Fixes 2bfa7db7bc (Restructure __fish_seen_subcommand_from, 2024-07-07)
Fixes #11685

(cherry picked from commit 4412164fd4)
2025-07-26 20:36:53 +02:00
Johannes Altmanninger
6d061daa91 build_tools/check.sh: check that stable rust is up-to-date
As suggested in
https://github.com/fish-shell/fish-shell/discussions/11584#discussioncomment-13674983
In future, we should probably make updates automatic again.
2025-07-26 20:36:03 +02:00
Johannes Altmanninger
4412164fd4 __fish_seen_subcommand_from: fix regression causing false negatives given multiple arguments
Fixes 2bfa7db7bc (Restructure __fish_seen_subcommand_from, 2024-07-07)
Fixes #11685
2025-07-26 17:08:15 +02:00
Johannes Altmanninger
0c8f1f4220 Fix async-signal safety in SIGTERM handler
Cherry-picked from
- 941701da3d (Restore some async-signal discipline to SIGTERM, 2025-06-15)
- 81d45caa76e (Restore terminal state on SIGTERM again, 2025-06-21)

Also, be more careful in terminal_protocols_disable_ifn about accessing
reader_current_data(), as pointed out in 65a4cb5245 (Revert "Restore terminal
state on SIGTERM again", 2025-07-19).

See #11597
2025-07-26 13:09:18 +02:00
Johannes Altmanninger
e593da1c2e Increase timeout when reading escape sequences inside paste/kitty kbd
Historically, fish has treated input bytes [0x1b, 'b'] as alt-b (rather than
"escape,b") if the second byte arrives within 30ms of the first.

Since we made builtin bind match key events instead of raw byte sequences,
we have another place where we do similar disambiguation: when we read keys
such as alt-left ("\e[1;3D"), we only consider bytes to be part of this
sequence if stdin is immediately readable (actually "readable after a 1ms
timeout" since e1be842 (Work around torn byte sequences in qemu kbd input
with 1ms timeout, 2025-03-04)).

This is technically wrong but has worked in practice (for Kakoune etc.).

Issue #11668 reports two issues on some Windows terminals feeding a remote
fish shell:
- the "bracketed paste finished" sequence may be split into multiple packets,
  which causes a delay of > 1ms between individual bytes being readable.
- AutoHotKey scripts simulating seven "left" keys result in sequence tearing
  as well.

Try to fix the paste case by increasing the timeout when parsing escape
sequences.

Also increase the timeout for terminals that support the kitty keyboard
protocol.  The user should only notice this new delay after pressing one of
escape,O, escape,P, escape,[, or escape,] **while the kitty keyboard protocol
is disabled** (e.g. while an external command is running).  In this case,
the fish_escape_delay_ms is also virtually increased; hopefully this edge
case is not ever relevant.

Part of #11668

(cherry picked from commit 30ff3710a0)
2025-07-25 18:29:19 +02:00
Johannes Altmanninger
30ff3710a0 Increase timeout when reading escape sequences inside paste/kitty kbd
Historically, fish has treated input bytes [0x1b, 'b'] as alt-b (rather than
"escape,b") if the second byte arrives within 30ms of the first.

Since we made builtin bind match key events instead of raw byte sequences,
we have another place where we do similar disambiguation: when we read keys
such as alt-left ("\e[1;3D"), we only consider bytes to be part of this
sequence if stdin is immediately readable (actually "readable after a 1ms
timeout" since e1be842 (Work around torn byte sequences in qemu kbd input
with 1ms timeout, 2025-03-04)).

This is technically wrong but has worked in practice (for Kakoune etc.).

Issue #11668 reports two issues on some Windows terminals feeding a remote
fish shell:
- the "bracketed paste finished" sequence may be split into multiple packets,
  which causes a delay of > 1ms between individual bytes being readable.
- AutoHotKey scripts simulating seven "left" keys result in sequence tearing
  as well.

Try to fix the paste case by increasing the timeout when parsing escape
sequences.

Also increase the timeout for terminals that support the kitty keyboard
protocol.  The user should only notice this new delay after pressing one of
escape,O, escape,P, escape,[, or escape,] **while the kitty keyboard protocol
is disabled** (e.g. while an external command is running).  In this case,
the fish_escape_delay_ms is also virtually increased; hopefully this edge
case is not ever relevant.

Part of #11668
2025-07-25 18:28:21 +02:00
Johannes Altmanninger
6666c8f1cd Block interrupts and uvar events while decoding key
readb() has only one caller that passes blocking=false: try_readb().
This function is used while decoding keys; anything but a successful read
is treated as "end of input sequence".

This means that key input sequences such as \e[1;3D
can be torn apart by
- signals (EINTR) which is more likely since e1be842 (Work around torn byte
  sequences in qemu kbd input with 1ms timeout, 2025-03-04).
- universal variable notifications (from other fish processes)

Fix this by blocking signals and not listening on the uvar fd.  We do something
similar when matching key sequences against bindings, so extract a function
and use it for key decoding too.

Ref: https://github.com/fish-shell/fish-shell/issues/11668#issuecomment-3101341081
(cherry picked from commit da96172739)
2025-07-25 18:21:27 +02:00
Johannes Altmanninger
3e61036911 Revert "Change readch() into try_readch()"
try_readch() was added to help a fuzzing harness, specifically to avoid a
call to `unreachable!()` in the NothingToRead case.  I don't know much about
that but it seems like we should find a better way to tell the fuzzer that
this can't happen.

Fortunately the next commit will get rid of readb()'s "blocking" argument,
along the NothingToRead enum variant. So we'll no longer need this.

This reverts commit b92830cb17.

(cherry picked from commit fb7ee0db74)
2025-07-25 18:21:27 +02:00
Johannes Altmanninger
f23a479b81 Reduce MaybeUninit lifetime
(cherry picked from commit 137f220225)
2025-07-25 18:21:27 +02:00
王宇逸
e274ff41d0 Use uninit instead of zeroed (src/input_common.rs)
(cherry picked from commit 7c2c7f5874)
2025-07-25 18:21:27 +02:00
Johannes Altmanninger
d2af306f3d Fix some unused-ControlFlow warnings 2025-07-25 18:11:04 +02:00
Johannes Altmanninger
da96172739 Block interrupts and uvar events while decoding key
readb() has only one caller that passes blocking=false: try_readb().
This function is used while decoding keys; anything but a successful read
is treated as "end of input sequence".

This means that key input sequences such as \e[1;3D
can be torn apart by
- signals (EINTR) which is more likely since e1be842 (Work around torn byte
  sequences in qemu kbd input with 1ms timeout, 2025-03-04).
- universal variable notifications (from other fish processes)

Fix this by blocking signals and not listening on the uvar fd.  We do something
similar when matching key sequences against bindings, so extract a function
and use it for key decoding too.

Ref: https://github.com/fish-shell/fish-shell/issues/11668#issuecomment-3101341081
2025-07-25 17:56:49 +02:00
Johannes Altmanninger
fb7ee0db74 Revert "Change readch() into try_readch()"
try_readch() was added to help a fuzzing harness, specifically to avoid a
call to `unreachable!()` in the NothingToRead case.  I don't know much about
that but it seems like we should find a better way to tell the fuzzer that
this can't happen.

Fortunately the next commit will get rid of readb()'s "blocking" argument,
along the NothingToRead enum variant. So we'll no longer need this.

This reverts commit b92830cb17.
2025-07-25 17:56:49 +02:00
Johannes Altmanninger
137f220225 Reduce MaybeUninit lifetime 2025-07-25 17:56:49 +02:00
Johannes Altmanninger
f8b9fa19e8 Merge pull request #11681 2025-07-25 17:56:39 +02:00
A2uria
4508b5b0db Handle cygwin select() returning -1 with errno 0 2025-07-25 22:45:01 +08:00
A2uria
d8e5821a3b Use \n as end of line on windows 2025-07-25 18:44:42 +08:00
A2uria
4162e0efad Fix path_remoteness on cygwin 2025-07-25 18:41:40 +08:00
Johannes Altmanninger
0e7c7f1745 Remove unused import
(cherry picked from commit 07ff4e7df0)
2025-07-25 11:57:21 +02:00
Johannes Altmanninger
07ff4e7df0 Remove unused import 2025-07-25 11:55:10 +02:00
Johannes Altmanninger
3fada80553 Fix regression causing \e[ to be interpreted as ctrl-[
Fixes 3201cb9f01 (Stop parsing invalid CSI/SS3 sequences as alt-[/alt-o,
2024-12-30).

(cherry picked from commit 43d583d991)
2025-07-25 11:49:07 +02:00
Johannes Altmanninger
43d583d991 Fix regression causing \e[ to be interpreted as ctrl-[
Fixes 3201cb9f01 (Stop parsing invalid CSI/SS3 sequences as alt-[/alt-o,
2024-12-30).
2025-07-25 11:47:18 +02:00
Johannes Altmanninger
d69886efe0 completions/protontricks: coding style, translations 2025-07-25 11:15:05 +02:00
Johannes Altmanninger
bd8cc6d317 Merge pull request #11375 2025-07-25 11:10:38 +02:00
Johannes Altmanninger
9c5b3f3d57 Merge pull request #11674 2025-07-25 11:03:53 +02:00
Johannes Altmanninger
5970f34a60 Retry some writes on EINTR again
I guess?
Fixes f0e007c439 (Relocate tty metadata and protocols and clean it up,
2025-06-19).
2025-07-25 10:23:48 +02:00
Johannes Altmanninger
eaa837effa Refresh TTY timestamps again in most cases
See commit 081c3282b7 (Refresh TTY timestamps also in some rare cases,
2025-01-15) and others.
Fixes d27f5a5293 (Adopt TtyHandoff in remaining places, 2025-06-21)
Fixes #11671
2025-07-25 10:23:48 +02:00
Johannes Altmanninger
e52cf2f6a7 Try to restore TTY protocols more reliably after SIGTERM
We might
1. set TTY_PROTOCOLS_ACTIVE to false
2. receive `SIGTERM`
3. due to 1 fail to disable TTY protocols

Fix this by making sure that the disabling of protocols happens-before we
set TTY_PROTOCOLS_ACTIVE to false.

See 37c04745e6 (Avoid potential contention on SIGTERM while enabling terminal
protocols, 2024-10-08).
Fixes d27f5a5293 (Adopt TtyHandoff in remaining places, 2025-06-21)
2025-07-25 10:23:48 +02:00
Johannes Altmanninger
8c7568c0cb Reapply "Disable focus reporting on non-tmux again for now" 2024-04-18
Reapply bdd478bbd0. Amendment to f0e007c439 (Relocate tty metadata and
protocols and clean it up, 2025-06-19).
2025-07-25 10:23:48 +02:00
Johannes Altmanninger
07979782a6 Fix iTerm2 detection on non-iTerm2 terminals
Fixes f0e007c439 (Relocate tty metadata and protocols and clean it up,
2025-06-19).
2025-07-25 10:23:48 +02:00
Johannes Altmanninger
59b43986e9 build_tools/style.fish: fail if formatters are not available
build_tools/check.sh is supposed to fail on formatting violations.  I don't
think we have a good reason for running build_tools/style.fish outside
check.sh.

black is the only formatter not versioned in CI -- but we can probably
satisfy all realistic versions.

Ref: https://github.com/fish-shell/fish-shell/pull/11608#discussion_r2173176621
2025-07-25 10:23:48 +02:00
phisonate
51f3722e02 Fix funced to not expand or execute function name when interactive
Due to unnecessary quotes in the prompt command given to `read` by `funced` when
editing a function interactively (using `-i`), the name of the function to edit
would be evaluated, expanded and even executed (when using command substitution
for example), which is at least annoying when using unusual but valid and
allowed function names like '*' or 'head (cat)'. This commit delays the function
name expansion so that this should no longer happen.
2025-07-24 01:03:02 +02:00
Daniel Rainer
2c11bfa532 Avoid running sphinx-build if possible
Despite the caching in `sphinx-build`, it takes several seconds to run
`sphinx-build` when no rebuilding is necessary, which slows down build times
significantly.

Add custom logic to `build.rs` to avoid calling `sphinx-build` if deemed
unnecessary based on the mtime of the source files.
This is done by writing the most recent timestamp of the source files into a
dedicated file, and only calling `sphinx-build` (and updating the timestamp)
when a cached timestamp is older than the most recent source file mtime.
2025-07-23 18:37:07 +02:00
Daniel Rainer
eae633c4af Extract SPHINX_DOC_SOURCES and handle rebuilds
The sources for Sphinx documentation builds include `CHANGELOG.rst` and
`CONTRIBUTING.rst`. Use `SPHINX_DOC_SOURCES` to clarify this and avoid
repetition.

Rebuilds should happen for debug builds as well, since rebuilding is required
for updating the man files.
2025-07-23 18:28:54 +02:00
Daniel Rainer
ecc004a122 Rebuild if gettext-extraction changed 2025-07-23 18:28:54 +02:00
Peter Ammon
db0f9c1d53 Minor refactoring of make_wait_handle 2025-07-20 13:40:22 -07:00
Peter Ammon
c9901398ed Switch DISOWNED_PIDS from MainThread to Mutex
Preparation for concurrent execution. These can be reaped on any thread.
2025-07-19 17:56:58 -07:00
Peter Ammon
6181ba3b56 Fix an 1.70 clippy 2025-07-19 16:49:51 -07:00
Peter Ammon
d27f5a5293 Adopt TtyHandoff in remaining places
This adopts the tty handoff in remaining places. The idea is to rationalize
when we enable and disable tty protocols (such as CSI-U).

In particular this removes the tty protocol disabling in Parser::eval_node
- that is intended to execute pure fish script and should not be talking to
the tty.
2025-07-19 16:04:13 -07:00
Peter Ammon
c1d165de9d Adopt TtyHandoff in fish_key_reader
Prepare to remove terminal_protocols_enable/disable_ifn
2025-07-19 16:04:13 -07:00
Peter Ammon
f0e007c439 Relocate tty metadata and protocols and clean it up
fish-shell attempts to set up certain terminal protocols (bracketed paste,
CSI-U) while it is in control of the tty, and disable these when passing
off the tty to other processes. These terminal protocols are enabled or
disabled by emitting certain control sequences to the tty.

Today fish-shell does this in a somewhat haphazard way, tracking whether
the protocols are enabled or disabled. Functions like `Parser::exec_node`
then just toggle these, causing data to be written to the terminal in
unexpected places. In particular this is very bad for concurrent execution:
we don't want random threads talking to the tty.

Fortunately we have a controlled place where we can muck with the tty:
`TtyTransfer` which controls handoff of ownership to child processes (via
`tcsetpgrp`). Let's centralize logic around enabling and disabling terminal
protocols there. Put it in a new module and rename it to `TtyHandoff` which is a
little nicer.

This commit moves code around and does some cleanup; it doesn't actually
pull the trigger on centralizing the logic though. Next commit will do that.
2025-07-19 16:04:13 -07:00
Peter Ammon
65a4cb5245 Revert "Restore terminal state on SIGTERM again"
This reverts commit 1d6fa258f6.

This reintroduces commit 941701da3d, which was then reverted in
941701da3d8; this commit reverts the revert to reintroduce 941701da3d.

The reason is that the existing logic in terminal_protocols_disable_ifn does a
bunch of stuff for which nobody has thought about its signal safety, such as
accessing the reader stack (clearly not async signal safe).
Even functions which happen to be safe now may become unsafe in the future.

This is just the nature of signal handling code. We must ensure that only
async-signal safe syscalls are run, and only functions which are themselves
async-signal safe, which we (try) to designate with the "safe_" prefix.
2025-07-19 15:37:00 -07:00
rosavi
c7262d6c05 Add completions for cpan and t-rec
Closes #11647
2025-07-19 22:15:24 +02:00
Johannes Altmanninger
f3c264722d Merge pull request #11666 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
39742cafa0 Merge pull request #11663 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
295d2bd218 update translations for completions/fish_indent 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
3588b41744 Merge pull request #11662 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
82e3311756 Merge pull request #11659 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
b611c96cdd Merge pull request #11654 2025-07-19 22:15:24 +02:00
Johannes Altmanninger
1d6fa258f6 Restore terminal state on SIGTERM again
Commit 941701da3d (Restore some async-signal discipline to SIGTERM,
2025-06-15) made two changes
1. removed a mutex lock in signal handler (regression from 55fd43d86c
   (Port reader, 2023-12-22))
2. removed some SIGTERM cleanup

I'm not sure what's the reason for 2, so let's revert it I guess.  This code
path already uses FLOG_SAFE for async-signal safety.

There is an avoidable panic when `Outputter::stdoutput()` is already
borrowed. Fix that.

Closes #11597
2025-07-19 22:15:24 +02:00
Johannes Altmanninger
6312b1dbd8 Format test_driver.py 2025-07-19 22:15:24 +02:00
Peter Ammon
5fa2f62536 test_driver: increase open file limit
Prevent failures due to file handle exhaustion.
2025-07-19 11:14:37 -07:00
Peter Ammon
bbf7568ebd test_driver.py: Properly report exceptions
If a test fails by throwing an exception (in this case, "Too many open files")
then that exception would propagate, be uncaught, and then the remaining tests
would not be await'ed, leading to a hang.

Fix this by properly catching and reporting exceptions.
2025-07-19 11:01:48 -07:00
Rhidian De Wit
72347517b2 Fix missing bool to string cast causing errors 2025-07-17 20:17:52 +02:00
may
95475c35ff update translation files 2025-07-16 16:36:09 +02:00
may
560d21cd86 complete git rebase --keep-base 2025-07-16 15:49:38 +02:00
nick
bef453f69b fish_indent -c/--check completions
Manpage `fish_indent(1)` documents the `-c/--check` option, which checks
if a file is already indented as `fish_indent` would. This option is now
included in the completions for `fish_indent`.
2025-07-15 15:44:36 -05:00
vcalv
fa832ead65 add suspend-then-hibernate to systemctl.fish
suspend-then-hibernate was missing
2025-07-14 18:09:32 -04:00
Azamat Dinaev
eb7afd2a9c Update __fish_print_hostnames.fish
There was an issue in autocomplete of ssh. 

When you put in ~/.ssh/config line like this:

"Include Include ${HRL_SSH}/onprem_config"

and then trying to use fish complete for ssh, for example:

"ssh -J" and press key <Tab> it throughs an error that fish cannot understand ${HRL_SSH} with brackets.
2025-07-12 14:18:43 +03:00
Johannes Altmanninger
f4ddcfa694 Merge pull request #11652 2025-07-11 12:11:17 +02:00
Johannes Altmanninger
1605d8d6ce Merge pull request #11644 2025-07-11 12:10:49 +02:00
Johannes Altmanninger
a7559a62c4 completions/cjpm: format with fish_indent 2025-07-11 12:09:58 +02:00
Johannes Altmanninger
e9327d234d Merge pull request #11641 2025-07-11 12:08:37 +02:00
Daniel Rainer
a3d03fc0fb Avoid duplicate flag values
Both `SKIP_CMDSUBST` and `NO_SPACE_FOR_UNCLOSED_BRACE` used `1 << 14` as their
value accidentally, resulting from `SKIP_CMDSUBST` not being sorted correctly.
Resolve this by using the next (and last in u16) unused bit for `SKIP_CMDSUBST`
and moving it to the end.

Fixes #11651.
2025-07-10 18:52:10 +02:00
Daniel Rainer
1e981a9827 Support upper/lower casing selection
Fixes #11639.
2025-07-10 16:57:17 +02:00
Daniel Rainer
770f4ce6d1 Add docs for casing shortcuts in normal mode 2025-07-06 20:15:25 +02:00
Daniel Rainer
aa782bdad7 Fix vi mode docs for moving to beginning of line 2025-07-06 20:10:21 +02:00
Jiangqiu Shen
e4c55131c7 Update translation 2025-07-04 18:31:39 -04:00
Jiangqiu Shen
e6ad78cda7 update 2025-07-04 00:30:28 -04:00
Jiangqiu Shen
578e162f35 Add completion for Cangjie programing language
add completion of cjpm
2025-07-04 00:29:11 -04:00
Johannes Altmanninger
e9bb150a41 Merge pull request #11633 2025-07-03 15:19:51 +02:00
Johannes Altmanninger
b5eccdf9f6 Merge pull request #11632 2025-07-03 15:19:51 +02:00
Johannes Altmanninger
75716bd6b0 Merge pull request #11631 2025-07-03 15:19:51 +02:00
Johannes Altmanninger
9e628995da Merge pull request #11629 ("Add completions for tmuxp") 2025-07-03 15:19:51 +02:00
Daniel Müller
5b39efc96d Support incrementing/decrementing the number below the cursor
Vim supports incrementing & decrementing the number below the cursor (or
after it) via Ctrl-a and Ctrl-x, respectively. Given fish's Vi mode
support, it makes sense to provide similar functionality when working on
the command line, to provide a more natural environment for Vim users.
With this change we add the necessary functionality.

Closes: #8320
Closes #11570
2025-07-03 14:38:42 +02:00
Johannes Altmanninger
b5bb50d742 builtin commandline: apply commandline+cursor to first top-level reader
Historically, `fish -C "commandline echo"` was silently ignored.  Make it do
the expected thing.  This won't affect subsequent readers because we only do
it for top-level ones, and reader_pop() will clear the commandline state again.

This improves consistency with the parent commit.  We probably don't want to
support arbitrary readline commands before the first reader is initialized,
but setting the initial commandline seems useful: first, it would have helped
me in the past for debugging fish.  Second, it would allow one to rewrite
an application launcher:

	 foot --app-id my-foot-launcher -e fish -C '
	 	set fish_history launcher
	 	bind escape exit
	 	bind ctrl-\[ exit
	-	function fish_should_add_to_history
	-		false
	-	end
	-	for enter in enter ctrl-j
	-		bind $enter '\''
	-			history append -- "$(commandline)"
	-			commandline "setsid $(commandline) </dev/null >/dev/null 2>&1 & disown && exit"
	-			commandline -f execute
	-		'\''
	-	end
	+	commandline "setsid  </dev/null >/dev/null 2>&1 & disown && exit"
	+	commandline --cursor $(string length "setsid ")
	 '

which is probably not desirable today because it will disable autosuggestions.
Though that could be fixed eventually by making autosuggestions smarter.

If we find a generally-useful use case, we should mention this in the changelog.

Ref: https://github.com/fish-shell/fish-shell/pull/11570#discussion_r2144544053
2025-07-03 14:38:42 +02:00
Daniel Müller
32c36aa5f8 builtins commandline/complete: allow handling commandline before reader initialization
Commands like "commandline foo" silently fail, and "complete -C" fails with
a weird "option requires an argument" error.

I think at least the first one can be useful in edge cases, e.g. to test
code that does not separate the `commandline` input and output (#11570),
and to set fish's initial commandline, see the next commit.

I don't think there are super strong reasons to allow these, but if the
existing state is merely due to "no one has ever thought of doing this",
then we should try changing it.

For consistency, also allow "complete -C". I guess an argument for that is
that it's weird to make a command behave differently in non-interactive shells.

For now, keep the historical behavior of disabling access to the command
line in non-interactive shells. If we find a good reason for allowing that
(which seems unlikely), we can.

Ref: https://github.com/fish-shell/fish-shell/pull/11570#discussion_r2144544053

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
2025-07-03 14:16:18 +02:00
merceyz
fc37d8d5a8 feat: add completions for volta 2025-06-29 16:23:49 +02:00
merceyz
8d361b4290 feat: add completions for k9s 2025-06-29 16:18:41 +02:00
merceyz
9789e6b731 feat: add completions for cilium and hubble 2025-06-29 16:09:27 +02:00
Johannes Altmanninger
c7d4acbef8 Update changelog 2025-06-29 16:01:44 +02:00
Johannes Altmanninger
e204a4c126 Add ctrl-alt-h compatibility binding
Historically, ctrl-i sends the same code as tab, ctrl-h sends backspace and
ctrl-j and ctrl-m behave like enter.

Even for terminals that send unambiguous encodings (via the kitty keyboard
protocol), we have kept bindings like ctrl-h, to support existing habits.

We forgot that pressing alt-ctrl-h would behave like alt-backspace (and can
be easier to reach) so maybe we should add that as well.

Don't add ctrl-shift-i because at least on Linux, that's usually intercepted
by the terminal emulator.

Technically there are some more such as "ctrl-2" (which used to do the same as
"ctrl-space") but I don't think anyone uses that over "ctrl-space".

Closes #https://github.com/fish-shell/fish-shell/discussions/11548

(cherry picked from commit 4d67ca7c58)
2025-06-28 14:20:03 +02:00
Johannes Altmanninger
4d67ca7c58 Add ctrl-alt-h compatibility binding
Historically, ctrl-i sends the same code as tab, ctrl-h sends backspace and
ctrl-j and ctrl-m behave like enter.

Even for terminals that send unambiguous encodings (via the kitty keyboard
protocol), we have kept bindings like ctrl-h, to support existing habits.

We forgot that pressing alt-ctrl-h would behave like alt-backspace (and can
be easier to reach) so maybe we should add that as well.

Don't add ctrl-shift-i because at least on Linux, that's usually intercepted
by the terminal emulator.

Technically there are some more such as "ctrl-2" (which used to do the same as
"ctrl-space") but I don't think anyone uses that over "ctrl-space".

Closes #https://github.com/fish-shell/fish-shell/discussions/11548
2025-06-28 14:19:10 +02:00
Patryk Bratkowski
fbe5a53dc9 Add completions for tmuxp 2025-06-28 14:58:37 +03:00
Johannes Altmanninger
dcd93e4c52 Fix compatibility with Python 3.6 for OpenSUSE Leap 15.6
Nightlies for opensuse/leap:15.6 are failing because their /bin/python3
is Python 3.6 (the "python311" package creates only /bin/python311).
Python3.6 has been EOL for 3.5 years but OpenSuse leap is not even EOL.
Given that we don't write a lot of Python, let's support this for now.
2025-06-28 13:36:31 +02:00
Johannes Altmanninger
7acd20dc7e Fix opensuse docker file file extension 2025-06-28 13:27:30 +02:00
Johannes Altmanninger
9af33802ec Use statvfs on NetBSD again to fix build
From commit ba00d721f4 (Correct statvfs call to statfs, 2025-06-19):

> This was missed in the Rust port

To elaborate:

- ec176dc07e (Port path.h, 2023-04-09) didn't change this (as before,
 `statvfs` used `ST_LOCAL` and `statfs` used `MNT_LOCAL`)
- 6877773fdd (Fix build on NetBSD (#10270), 2024-01-28) changed the `statvfs`
  call to `statfs`, presumably due to the libc-wrapper for
  `statvfs` being missing on NetBSD.  This change happens
  to work fine on NetBSD because they do [`#define ST_LOCAL
  MNT_LOCAL`](https://github.com/fish-shell/fish-shell/pull/11486#discussion_r2092408952)
  But it was wrong on others like macOS and FreeBSD, which was fixed by
  ba00d721f4 (but that broke the build on NetBSD).
- 7228cb15bf (Include sys/statvfs.h for the definition of ST_LOCAL (Rust
  port regression), 2025-05-16)
  fixed a code clone left behind by the above commit (incorrectly assuming
  that the clone had always existed.)

Fix the NetBSD build specifically by using statfs on that platform.

Note that this still doesn't make the behavior equivalent to commit LastC++11.
That one used ST_LOCAL if defined, and otherwise MNT_LOCAL if defined.

If we want perfect equivalence, we could detect both flags in `src/build.rs`.
Then we would also build on operating systems that define neither. Not sure.

Closes #11596

(cherry picked from commit 6644cc9b0e)
2025-06-28 11:46:25 +02:00
王宇逸
eecf0814a1 Use uninit instead of zeroed (cherry-pikcked only the change to src/path.rs)
(cherry picked from commit 7c2c7f5874)
2025-06-28 11:46:25 +02:00
Johannes Altmanninger
1d893b77d3 Also flag MSRV rustc/clippy warnings in CI 2025-06-28 11:04:29 +02:00
Johannes Altmanninger
b451650faa Flag stable rustc/clippy warnings in CI
Today, when a change introduces warnings, the change author might not see
them. Fix that by making clippy fail on warnings.

AFAICT, "clippy --deny-warnings" will also fail on rustc warnings.
I'd imagine this is what most respectable Rust projects do.

Pin stable rust so we won't get unrelated failures. Alternatively, we could
keep using "dtolnay/rust-toolchain@stable", that should be fine too (as long
as we have the capacity to quickly silence/iron out clippy failures).

While at it, remove some unneeded dependencies. Keep gettext because that
one might enable some cfg-directives (?).
Other cfgs like feature="benchmark" and target_os != "linux" are not yet checked in CI.

See #11584
2025-06-28 11:02:19 +02:00
Johannes Altmanninger
3e0a53ae4f Resolve an uninlined_format_args warning 2025-06-28 11:02:19 +02:00
Johannes Altmanninger
e01aafab1c Extract github actions for interesting rust toolchain versions
Extract a github action to reduce the number of references to our MSRV and
stable (to be pinned in the next commit).

While at it, use the MSRV for macOS builds; this means that we'll be less
like accidentally to break the macOS build when bumping the MSRV.  I don't
think there is a reason for using 1.73 specifically, other than "it's the
highest we can use on old macOS", so using an even older one should be fine.
2025-06-28 09:50:18 +02:00
Johannes Altmanninger
fd0fba83b9 Fix inconsistency in docker file lint override 2025-06-28 09:50:18 +02:00
Johannes Altmanninger
6644cc9b0e Use statvfs on NetBSD again to fix build
From commit ba00d721f4 (Correct statvfs call to statfs, 2025-06-19):

> This was missed in the Rust port

To elaborate:

- ec176dc07e (Port path.h, 2023-04-09) didn't change this (as before,
 `statvfs` used `ST_LOCAL` and `statfs` used `MNT_LOCAL`)
- 6877773fdd (Fix build on NetBSD (#10270), 2024-01-28) changed the `statvfs`
  call to `statfs`, presumably due to the libc-wrapper for
  `statvfs` being missing on NetBSD.  This change happens
  to work fine on NetBSD because they do [`#define ST_LOCAL
  MNT_LOCAL`](https://github.com/fish-shell/fish-shell/pull/11486#discussion_r2092408952)
  But it was wrong on others like macOS and FreeBSD, which was fixed by
  ba00d721f4 (but that broke the build on NetBSD).
- 7228cb15bf (Include sys/statvfs.h for the definition of ST_LOCAL (Rust
  port regression), 2025-05-16)
  fixed a code clone left behind by the above commit (incorrectly assuming
  that the clone had always existed.)

Fix the NetBSD build specifically by using statfs on that platform.

Note that this still doesn't make the behavior equivalent to commit LastC++11.
That one used ST_LOCAL if defined, and otherwise MNT_LOCAL if defined.

If we want perfect equivalence, we could detect both flags in `src/build.rs`.
Then we would also build on operating systems that define neither. Not sure.

Closes #11596
2025-06-28 09:50:18 +02:00
adamanteye
f5370e6f22 Add colorful disassembler output completion for objdump
As desribed in objdump(1), --disassembler-color can be applied to
enable or disable the use of syntax highlighting in disassembly
output.

The options are:

--disassembler-color=off
--disassembler-color=terminal
--disassembler-color=on|color|colour
--disassembler-color=extened|extended-color|extened-colour

Signed-off-by: adamanteye <ada@adamanteye.cc>

Closes #11615
2025-06-28 09:50:18 +02:00
Patryk Bratkowski
d62fb9cc74 Add 'ollama stop' completions.
- Added the '__fish_ollama_ps' function to list running models.
- Added the 'stop' subcommand to ollama completions.
- Added running models as arguments to 'stop'.
2025-06-28 09:50:18 +02:00
Johannes Altmanninger
88ab024d7d Merge pull request #11627 2025-06-28 09:29:11 +02:00
Johannes Altmanninger
1cc900ab7f Merge pull request #11625 2025-06-28 09:28:58 +02:00
Dezhi Wu
144725e947 fix(echo): handle overflow in octal/hex escape parsing
Use wrapping arithmetic when parsing octal and hex escapes in echo to
prevent panics on overflow and ensure consistent behavior with other
shells. This change allows echo to process escape sequences like \5555
without crashing, keeping the same behavior as 3.7.1.

```
$ ./fish --version
fish, version 3.7.1
$ ./fish -c 'echo -e "\5555"'
m5
```
2025-06-28 11:15:42 +08:00
Dezhi Wu
d969577f0b fix(fmt): Resolve Rust 1.88 clippy warnings
Update formatting macros to use the new inline variable syntax as
recommended by Rust 1.88 clippy.
2025-06-28 09:10:27 +08:00
Johannes Altmanninger
1ceebdf580 Fix some CSI commands being sent to old midnight commander
Commit 97581ed20f (Do send bracketed paste inside midnight commander,
2024-10-12) accidentally started sending CSI commands such as "CSI >5;0m",
which we intentionally didn't do for some old versions of Midnight Commander,
which fail to parse them. Fix that.

Fixes #11617
2025-06-25 13:36:03 +02:00
Johannes Altmanninger
3e098249a5 docker/fish_run_tests.sh: add check command to bash history
Closes #11600
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
7cd7f31a93 build_tools/check.sh: ignore modifications to the running script
I sometimes want to run this script in multiple docker containers concurrently,
and possibly modify it while another instance is already running.  The behavior
after modification is unpredictable; let's change it to read the whole script
up-front (like Python/fish do).
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
5e12d4e99c Use sync::OnceCell for terminal modes, fixing memory leak
My

    $ sudo docker/docker_run_tests.sh --shell-after docker/jammy-asan.Dockerfile

shows a lot of complaints about

    Direct leak of 60 byte(s) in 1 object(s) allocated from:

because some unit tests call reader_init() and reader_deinit().  Work around
this by initializing this value only once.  AFAICT, OnceCell is async-signal
safe (unlike Mutex), although I don't think documentation promises that.

It doesn't feel great to change implementation code to accomodate tests but
I think for this specific issue that's what we usually do.  Alternatively,
we could add to lsan_suppressions.txt.
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
f98d1779dd build_tools/check.sh: respect inherited RUSTFLAGS/RUSTDOCFLAGS
No particular motivation. Seems better?
Also, use long options I guess.
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
6f18a1b314 Also namespace target/man -> target/fish-man
If cargo ever wants to write to "target/man", it would collide with our
use of this path.  Let's make this less likely by prefixing the name with
"fish-".  This also makes it more obvious that this is fish's invention.
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
8b102f2571 Stop using Cargo's OUT_DIR
(Note: this commit should technically have preceded the "Fix config paths
for disjoint build-dirs and in-tree installs" one, to make that one easier
to follow, but I wasn't 100% sure if this commit is right.)

From https://doc.rust-lang.org/cargo/reference/environment-variables.html

> OUT_DIR — If the package has a build script, this is set to the folder
> where the build script should place its output. See below for more
> information. (Only set during compilation.)

so OUT_DIR is something like "target/debug/build/fish-41da27d587f48978".
Whenever build.rs is re-run, we get a new one.

I don't think we need this flexibility anywhere.  It wouldn't protect
concurrent "cargo test" from interfering with each other - that's handled
by a file lock taken by Cargo.

Use "target/" instead (or CMAKE_BINARY_DIR if set).
Namespace the files better, so we don't create weird paths like

	target/test/complete_test/...
	target/fish_root/
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
514eebb002 build_tools/update_translations.fish: move po/template.po to /tmp
With the upcoming tests/checks/gettext.fish test from #11583, my

	sudo docker/docker_run_tests.sh --shell-after docker/focal.Dockerfile

fails writing to "po/template.po" because "/fish-source" is mounted as
read-only.  (There should be no need for tests to write to the source tree.)

Since commit 6239cba1e4 (Add dry-run mode to update_translations.fish,
2025-05-30), "build_tools/update_translations.fish" always removes that
template file when done, even without "--dry-run".

I'm not sure if we still have a need for keeping around "po/template.po".
To add a new translation, you can run "build_tools/update_translations
po/xy.po". It could serve as a cache but that would only work if we integrated
it into a build system.

Move it to /tmp, fixing the docker tests.
2025-06-24 12:52:35 +02:00
Johannes Altmanninger
41eb0a2fd0 build_tools/update_translations.fish: protect against universally-set $tmpdir 2025-06-24 12:51:17 +02:00
Johannes Altmanninger
290d957ab6 build_tools/update_translations.fish: remove forward reference
cleanup_exit references variables that are only defined later.  Fix that.
Also move the definition one block up, to help the next commit.
2025-06-24 12:33:28 +02:00
Johannes Altmanninger
08b03a733a docker_run_tests.sh: stop using cmake
Use test_driver directly instead of CMake in the docker tests.

Deal with the read-only "/fish-source" by exporting
"CARGO_TARGET_DIR=$HOME/fish-build".  It seems correct to also inject this
environment variable into the interactive debugging shells.  Add some logging
to make this override more obvious to the user.

Adopt "build_tools/check.sh", because that defines the full set of checks
that we (eventually) want to run in CI.

In particular, this will also run "tests/checks/po-files-up-to-date.fish"
which "cargo b && cargo t && tests/test_driver.py" does not, due to the
REQUIRES clause.

Since most docker images have some lints/warnings today, disable those for
now. Use "docker_run_tests.sh --lint" to override. The default may be changed
in future.
2025-06-24 12:32:42 +02:00
Johannes Altmanninger
19a17fa981 Fix docker warning by using "ENV key=value" syntax
- LegacyKeyValueFormat: "ENV key=value" should be used instead of
	legacy "ENV key value" format (line 4)
2025-06-24 12:32:42 +02:00
Johannes Altmanninger
13c00c9f79 Fix config paths for disjoint build-dirs and in-tree installs
Commit 89282fd9bc (Use CARGO_MANIFEST_DIR to see if we're running from
build dir, 2024-01-20) did

    -if exec_path.starts_with(OUT_DIR)
    +if exec_path.starts_with(CARGO_MANIFEST_DIR)

where OUT_DIR is the cmake build directory ("./build")
and CARGO_MANIFEST_DIR is our top level source tree.

This allowed "target/debug/fish" to work, but it broke
1. CMake build directories outside the source tree, e.g. "docker/docker_run_tests.sh".
   Those incorrectly fall back to the compiled-in-path (/usr/local/share etc)
2. Installations iside the source tree, e.g.
   "mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/../install".
   These installations incorrectly use "share/" etc. from the source tree.

Fix this by
1. respecting the CMake-specific FISH_BUILD_DIR, ad
2. if that's not set, use $CARGO_MANIFEST_DIR/target
2025-06-24 12:32:42 +02:00
Johannes Altmanninger
19eceff3bc bulid.rs respect CARGO_TARGET_DIR in man output 2025-06-24 12:32:42 +02:00
Johannes Altmanninger
6a4d3a59ab build.rs: extract constant for cargo manifest dir 2025-06-24 12:32:42 +02:00
Johannes Altmanninger
3b0d5c342b build.rs: extract function for canonicalizing paths
This probably means we should enable Rust backtraces.. not sure though.
2025-06-24 12:32:42 +02:00
Johannes Altmanninger
884a2d100c build.rs: remove redundant include dir
This include was added for config.h in 618834c4b5 (Port
UVAR_FILE_SET_MTIME_HACK, 2023-09-15), but that file no longer exists.
Remove it.
2025-06-24 12:04:57 +02:00
Johannes Altmanninger
a4d355634d docker_run_tests: fix failed build exiting prematurely
My bad; the "set +e" is only active inside the subshell.
The outer shell uses "set -e", which means that it will
exit upon seeing the subshell fail.
2025-06-24 12:04:57 +02:00
Johannes Altmanninger
3c620f56ee test_driver.py: fix compatibility with Python 3.8 / Ubuntu Focal 2025-06-24 12:04:57 +02:00
Johannes Altmanninger
7679be3126 test_driver.py: fix confusing help output 2025-06-24 12:02:13 +02:00
Johannes Altmanninger
49926cfbac Standardize shell script indent level
We have a mixture of 2 and 4 space indent.

    4 benchmarks/driver.sh
    2 build_tools/check.sh
    4 build_tools/git_version_gen.sh
    4 build_tools/mac_notarize.sh
    2 build_tools/make_pkg.sh
    2 build_tools/make_tarball.sh
    2 build_tools/make_vendor_tarball.sh
    4 docker/docker_run_tests.sh
    4 osx/install.sh
    2 tests/test_functions/sphinx-shared.sh

Our editorconfig file specifies 2, with no explicit reason.
Our fish and Python scripts use 4, so let's use that.
2025-06-24 12:02:13 +02:00
Johannes Altmanninger
963c3425a3 Merge pull request #11593 2025-06-24 12:02:13 +02:00
ndrew222
55bddac90a added completion for uv and uvx
Closes #11601
2025-06-24 12:02:13 +02:00
Illia Ostapyshyn
20c67692e1 completions/journalctl: Add --pager-end
Closes #11604
2025-06-24 12:02:13 +02:00
Johannes Altmanninger
1e7088fb6b Merge pull request #11605 2025-06-24 12:02:13 +02:00
Johannes Altmanninger
0f75df7c35 history: remove flush()/fsync() and don't write after each appended item
Commit 5c0fddae70 (Refactor history flushing, 2025-03-28) made three changes:
1. call fsync() when we are finished writing the history file.
2. when appending to (as opposed to vacuuming) history, call write(2)
   (followed by flush() and sync()) for each item. Previously, we'd only
   call write(2) if our 64k buffer was full, or after processing the last
   history item.
3. actually check the return value of flush() (which would retry when flushing
   fails -- but std::fs::File::flush() never fails!).

The motivation was to potentially fix #10300 which didn't succeed (see
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2876718382).

As for 1 and 2, I don't think the way we use fsync really helps, and flushing
eagerly should not make a difference.

As for 3, there are some explanations in comments, commit message and a [PR
comment](https://github.com/fish-shell/fish-shell/pull/11330#discussion_r2020171339).
To summarize, 5c0fddae70 wants to address the scenario where file.flush()
fails. Prior to that commit we would ostensibly carry on with a corrupted
"first_unwritten_new_item_index" (corrupted because it doesn't match what's
written to disk), which can cause various issues.  However this doesn't
ever happen because std::fs::File::flush() never fails because it doesn't
do anything -- std::fs::File::write() does not buffer writes, it always
delegates to write(2).

There can definitely be scenarios like the one described in
https://github.com/fish-shell/fish-shell/pull/11330#discussion_r2020171339
where the disk is full. In that case, either write(2) fails, which we
already check.  Or close(3p) fails with EIO, which we have never checked. We
should probably check that.

Undo all three changes for now.

Closes #11495
2025-06-24 12:02:13 +02:00
Asuka Minato
edb0617d13 Update git.fish
Closes #11606
2025-06-24 12:02:12 +02:00
Johannes Altmanninger
d2f7d238f3 Remove obsolete translation entries
I doubt these are very helpful; most of them won't be used again.  We can
still find them in history with "git log -Gpart.of.msgid".
2025-06-24 11:44:46 +02:00
Johannes Altmanninger
335f91babd completions/git: fix spurious error when no subcommand is in $PATH
Systems like NixOS might not have "git-receive-pack" or any other "git-*"
executable in in $PATH -- instead they patch git to use absolute paths.
This is weird. But no reason for us to fail. Silence the error.

Fixes #11590

(cherry picked from commit 4f46d369c4)
2025-06-24 11:59:57 +08:00
Volodymyr Chernetskyi
a7bed39c1e Add info on formatting fish_git_prompt output 2025-06-23 18:46:54 +02:00
Johannes Altmanninger
06646998db fixup! alias: fix indentation 2025-06-23 14:18:15 +02:00
Johannes Altmanninger
096f225579 alias: fix indentation
Fixes #11602
2025-06-23 13:53:43 +02:00
Johannes Altmanninger
ebec8c15ab Merge pull request #11599 2025-06-23 13:46:34 +02:00
Daniel Rainer
92d9646631 Simplify CMake Tests
Remove dependency on CTest. Parallel execution is handled by `test_driver.py`
internally now, so CTest is no longer relevant for performance.

This also removes CMake targets for single tests. As a replacement,
`test_driver.py` can be called directly with the path to the build directory as
the first argument and the path to the desired test as the second argument.
Ensuring that the executables in the build directory are up to date needs to be
done separately.
For a pure cargo build, an example of running a single test would be:
`cargo b && tests/test_driver.py target/debug tests/checks/abbr.fish`

The recommended way of running tests is `build_tools/check.sh`, which runs more
extensive tests and does not depend on CMake. That script does not work in CI
yet, so CMake testing is retained for now.

Update CI config to use the new `FISH_TEST_MAX_CONCURRENCY`.
Also update the FreeBSD version, since the previous one is outdated and does not
support the semaphore logic in `test_driver.py`.
2025-06-22 22:44:46 +02:00
Daniel Rainer
ab1307c63b Do not mmap with len 0
`mmap` should fail when the length argument is 0. Checking this in advance
allows returning early, without performing unnecessary syscalls.

This also fixes an issue observed on FreeBSD 13.2 where `mmap` does not always
fail when the length is 0, resulting in the `assert!(len > 0)` in
`MmapRegion::new` failing.
https://github.com/fish-shell/fish-shell/issues/11595
2025-06-21 22:19:27 +02:00
Johannes Altmanninger
ec66749369 __fish_complete_list: only unescape "$(commandline -t)"
Commit cd3da62d24 (fix(completion): unescape strings for __fish_complete_list,
2024-09-17) bravely addressed an issue that exists in a lot of completions.
It did so only for __fish_complete_list. Fair enough.

Unfortunately it unescaped more than just "$(commandline -t)".

This causes the problem described at
https://github.com/fish-shell/fish-shell/issues/11508#issuecomment-2889088934
where completion descriptions containing a backslash followed by "n" are
interpreted as newlines, breaking the completion parser.  Fix that.

(cherry picked from commit 60881f1195)
2025-06-21 18:58:33 +02:00
Johannes Altmanninger
6e9e33d81d __fish_complete_list: strip "--foo=" prefix from replacing completions
Given a command line like

	foo --foo=bar=baz=qux\=argument

(the behavior is the same if '=' is substituted with ':').

fish completes arguments starting from the last unescaped separator, i.e.

	foo --foo=bar=baz=qux\=argument
			 ^
__fish_complete_list provides completions like

	printf %s\n (commandline -t)(printf %s\n choice1 choice2 ...)

This means that completions include the "--foo=bar=baz=" prefix.

This is wrong. This wasn't a problem until commit f9febba (Fix replacing
completions with a -foo prefix, 2024-12-14), because prior to that, replacing
completions would replace the entire token.
This made it too hard to writ ecompletions like

	complete -c foo -s s -l long -xa "hello-world goodbye-friend"

that would work with "foo --long fri" as well as "foo --long=frie".
Replacing the entire token would only work if the completion included that
prefix, but the above command is supposed to just work.
So f9febba made us replace only the part after the separator.

Unfortunately that caused the earlier problem.  Work around this.  The change
is not pretty, but it's a compromise until we have a better way of telling
which character fish considers to be the separator.

Fixes #11508

(cherry picked from commit 320ebb6859)
2025-06-21 18:58:17 +02:00
Johannes Altmanninger
bebf3c129f Merge pull request #11594 2025-06-21 18:54:22 +02:00
Johannes Altmanninger
60881f1195 __fish_complete_list: only unescape "$(commandline -t)"
Commit cd3da62d24 (fix(completion): unescape strings for __fish_complete_list,
2024-09-17) bravely addressed an issue that exists in a lot of completions.
It did so only for __fish_complete_list. Fair enough.

Unfortunately it unescaped more than just "$(commandline -t)".

This causes the problem described at
https://github.com/fish-shell/fish-shell/issues/11508#issuecomment-2889088934
where completion descriptions containing a backslash followed by "n" are
interpreted as newlines, breaking the completion parser.  Fix that.
2025-06-21 18:53:50 +02:00
Johannes Altmanninger
320ebb6859 __fish_complete_list: strip "--foo=" prefix from replacing completions
Given a command line like

	foo --foo=bar=baz=qux\=argument

(the behavior is the same if '=' is substituted with ':').

fish completes arguments starting from the last unescaped separator, i.e.

	foo --foo=bar=baz=qux\=argument
			 ^
__fish_complete_list provides completions like

	printf %s\n (commandline -t)(printf %s\n choice1 choice2 ...)

This means that completions include the "--foo=bar=baz=" prefix.

This is wrong. This wasn't a problem until commit f9febba (Fix replacing
completions with a -foo prefix, 2024-12-14), because prior to that, replacing
completions would replace the entire token.
This made it too hard to writ ecompletions like

	complete -c foo -s s -l long -xa "hello-world goodbye-friend"

that would work with "foo --long fri" as well as "foo --long=frie".
Replacing the entire token would only work if the completion included that
prefix, but the above command is supposed to just work.
So f9febba made us replace only the part after the separator.

Unfortunately that caused the earlier problem.  Work around this.  The change
is not pretty, but it's a compromise until we have a better way of telling
which character fish considers to be the separator.

Fixes #11508
2025-06-21 18:53:50 +02:00
Daniel Rainer
9bf6112b60 Add option to limit concurrency of tests
The main purpose of this is avoiding timeouts in CI.

Passing `--max-concurrency=n` to `test_driver.py` will result in at most `n`
tests running concurrently, where `n` is a positive integer.
Not specifying the argument preserves the old behavior of running all tests
concurrently without a limit.
2025-06-21 02:36:06 +02:00
Daniel Rainer
ef1a6aba26 Remove unused NEVER_MMAP 2025-06-20 00:44:50 +02:00
Peter Ammon
f3ebc68d5d Correct statvfs call to statfs
This was missed in the Rust port - C++ had statfs for MNT_LOCAL and not statvfs.
The effect of this is that fish never thought its filesystem was local on macOS
or BSDs (Linux was OK). This caused history race tests to fail, and also could
in rare cases result in history items being dropped with multiple concurrent
sessions.

This fixes the history race tests under macOS and FreeBSD - we weren't locking
because we thought the history was a remote file.

Cherry-picked from ba00d721f4
2025-06-19 15:36:19 -07:00
Peter Ammon
ba00d721f4 Correct statvfs call to statfs
This was missed in the Rust port - C++ had statfs for MNT_LOCAL and not statvfs.
The effect of this is that fish never thought its filesystem was local on macOS
or BSDs (Linux was OK). This caused history race tests to fail, and also could
in rare cases result in history items being dropped with multiple concurrent
sessions.

This fixes the history race tests under macOS and FreeBSD - we weren't locking
because we thought the history was a remote file.
2025-06-19 15:30:36 -07:00
Peter Ammon
fe8909e8f2 Fix an off-by-one error in reporting dropped history items
This was introduced in the Rust port. The original C++ was pretty gnarly to be
fair.
2025-06-19 11:08:50 -07:00
Lorenzo Albano
d369614ad9 Use $GIT_COMMON_DIR for stashes detection.
Within a linked worktree, `$GIT_DIR` and `$GIT_COMMON_DIR` have different
values (see [git-worktree docs](https://git-scm.com/docs/git-worktree#_details)).
The two serve different purposes, in case of stashes `$GIT_COMMON_DIR`
should be used, this way stash detection in the git prompt works also
when inside a `git worktree`.

Closes #11591
2025-06-19 11:13:09 +02:00
Johannes Altmanninger
4f4d941760 Merge pull request #11588 2025-06-19 11:13:09 +02:00
Johannes Altmanninger
9b19db5c5f Merge pull request #11492 2025-06-19 11:13:09 +02:00
Johannes Altmanninger
4f46d369c4 completions/git: fix spurious error when no subcommand is in $PATH
Systems like NixOS might not have "git-receive-pack" or any other "git-*"
executable in in $PATH -- instead they patch git to use absolute paths.
This is weird. But no reason for us to fail. Silence the error.

Fixes #11590
2025-06-19 11:13:09 +02:00
Daniel Rainer
977459949f Obtain history file path in HistoryImpl::save
Eliminates some code duplication between the two different saving
implementations. These changes are based on
https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2149438316.

One extra change is included here, namely the early return on an empty file
name, indicating private mode. Without this, `history_path.unwrap()` fails in
some tests. Returning early is probably what we want in such situations anyway.
2025-06-18 21:05:29 +02:00
Daniel Rainer
8cbcfc0b3a Stop caching whether to lock
The cached information might become outdated. It is important that all fish
processes use the same mutual exclusion logic (either `flock`-based or the
fallback), because the two methods do not provide mutual exclusion from one
another.
Avoiding caching makes the behavior independent on previous system states,
resulting in fish instances performing file operations at the same time to use
the same locking logic.

More detailed discussion in
https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2134543447
2025-06-18 21:05:00 +02:00
Daniel Rainer
77738fd646 Remove obsolete comments
If arguments always have the same value they do not need to be arguments.
For `HistoryImpl::add`, the comments are incorrect (assuming they should
indicate the value of the argument), since both arguments can be true or false
independently.
`History::add` is only called at one location in a test with a constant value of
`false` for `pending`. This might mean that the parameter could be deleted, or
maybe even the entire function, if testing can work without it.
2025-06-18 20:54:38 +02:00
Daniel Rainer
f438e80f9b Use shared file locking logic
Both history files and universal variables files are accessed by multiple
processes, which need a way to synchronize their accesses.
This synchronization logic is mixed in with the logic for reading and updating
the files' contents, which results in messy code, duplicated locking
implementations, and inconsistencies.
Moreover, the existing implementations are flawed which has resulted in file
corruption (e.g. https://github.com/fish-shell/fish-shell/issues/10300).

The new approach separates the synchronization logic from the rest.

There are two approaches to synchronization.
- The primary one is using `flock(2)` to lock the directory containing the file
  which requires synchronized access. We do not lock the file holding the data
  directly because this file might be replaced, which can result in locking
  succeeding when it should block. Locking the directory solves this problem.
  To avoid inconsistent file states, changes are first written to a temporary
  file, which is then renamed into place while still holding the lock.
- In some situations `flock` locks are unavailable or take a long time. This
  mostly applies to remote file systems. If we think that a directory is located
  on a remote file system, we do not attempt to use `flock`.
  As a fallback, we have a lockless approach, which uses file metadata (device,
  inode, size, ctime, mtime) to identify file versions.
  We then read from the file, write the updated data to a temporary file,
  check if the file id for the path is the same as before we started reading,
  and if so we rename the temporary file such that it replaces the old file.
  Note that races are possible between the file id check and the rename syscall.
  If we detect a file id mismatch, we retry, up to a predetermined number of
  attempts.

The operations which should be performed are passed to the functions handling
synchronization as `Fn`s. Because we might have to run these operations
repeatedly when retrying, they should be executable arbitrarily often without
causing side-effects relevant to the program. This requires some changes to
functions accessing these files. In many cases, they have to work with
non-mutable references, which requires that they return the data which should be
updated in the program state, instead of directly assigning to the appropriate
location.

Locking via `O_EXLOCK`, which was used for the universal variable file, is no
longer supported. That version of locking locks the file operated on directly,
instead of its directory. According to the man pages of {Open,Free,Net}BSD
and macOS, these locks have flock semantics. So if flock is available, we can
use it, and if it is not, the `O_EXLOCK` flag does not help.
2025-06-18 20:48:27 +02:00
Daniel Rainer
ccb9c8225f Remove CHAOS_MODE
This is dead code. It is never set to true.
2025-06-18 20:31:28 +02:00
Daniel Rainer
33b651ad91 Get remoteness of correct directory
The history file is stored in the data dir, not the config dir, so the
remoteness of the former is the one which matters.
2025-06-18 20:31:28 +02:00
Daniel Rainer
a20712b51d Avoid mutable references for mmap creation
This is preparatory work for refactoring the file synchronization approach.

`read_exact` will fail if the file length does not match the expected one, which
means zero padding is useless. (On any reasonable OS it was also useless before,
because anonymous memory mapping would be zero-pages.)
2025-06-18 20:31:28 +02:00
Daniel Rainer
da426a1b03 Improve error handling in src/history/file.rs
Use `std::io::Result` instead of `Option` as the return type where appropriate,
to allow for better-informed error handling.

Remove explicit checks about the length to be mapped being 0.
From `mmap(3)`:
> If len is zero, mmap() shall fail and no mapping shall be established.
2025-06-18 20:31:28 +02:00
Daniel Rainer
fbb2fcdb06 Improve error handling in src/history.rs
This allows for more informative error handling.

In some cases, the `?` operator can now be applied sensibly instead of more
verbose local error handling.
2025-06-18 20:31:28 +02:00
Daniel Rainer
537b1c3dd5 Extract code for creating temporary files
There is no need for separate implementations for history and uvar file
handling. Having a shared implementation ensures that creating temporary files
is handled consistently and removes clutter from the source files which want to
create temporary files.
2025-06-18 20:31:28 +02:00
Daniel Rainer
b4d0538892 Reduce state mutation in load_from_file
This is another step towards making the `load_from_file` function callable
without modifying internal data of `self`. Instead, the required updates for
a successful load should be returned.

For now, `self.last_read_file_id` is still modified
within `load_from_file`, which means it still needs a mutable reference to
`self`.
2025-06-18 20:31:28 +02:00
Daniel Rainer
9222381769 Update self.vars outside of acquire_variables
This is done as a step towards enabling loading from the variables file without
affecting internal variables, such that retrying becomes possible without
issues.
2025-06-18 20:31:28 +02:00
Daniel Rainer
f2f54919af Remove unnecessary mut specifier 2025-06-18 20:31:28 +02:00
Daniel Rainer
f40e31f675 Return callbacks via return value
Callbacks are generated by
`src/env_universal_common.rs:generate_callbacks_and_update_exports`.
This function only pushes to the `Vec`, so the content of the `Vec` passed to it
does not matter within this function.
The generated callbacks are used in `src/env/environment.rs:universal_sync`,
which calls `generate_callbacks_and_update_exports` via
`EnvUniversal::sync`,
(optionally `EnvUniversal::load_from_path_narrow`),
`EnvUniversal::load_from_file`.

The only other code making use of these callbacks is in tests.
Because the only real use passes an empty `Vec`, there is no need to to pass the
`Vec` as a mutable reference to the function at all. Instead, we create the `Vec`
in `generate_callbacks_and_update_exports` and return it from there, which is
what the new code does.

This change is made because we want loading from a file to be performed without
mutating data which does not come directly from the file.
Then, we can safely retry loading from the file as many times as we want,
without worrying about side-effects on our data structures.
We want to be able to do this in the case where we cannot properly lock the file
and fall back to lockless reading, where we check file metadata before and after
reading to detect modifications, and retry if modifications are detected.

This fallback logic is not in place yet, and further changes are required for
side-effect free loading.
2025-06-18 20:31:28 +02:00
Fabio José Bohnenberger
43fbfa9a0f Extract __fish_cached function (#11526)
- extract __fish_cached function
- add cache for winetricks verb completion
2025-06-18 10:29:00 +02:00
Daniel Rainer
f6dbf17446 Decode WString in FLOG
This allows converting non-UTF-8-conforming bytes from their PUA encoding back
to the original bytes before outputting.

Due to the way Rust handles trait implementations, we cannot use
`impl<T: std::fmt::Display> FloggableDisplay for T`
anymore, as that would result in a conflicting implementation for the types
which get a custom implementation.
Instead, explicitly implement the trait for all types which need it.
2025-06-17 23:37:59 +02:00
Johannes Altmanninger
06578bd03d Merge pull request #11565 2025-06-16 12:25:08 +02:00
Johannes Altmanninger
6491518b97 Merge pull request #11571 2025-06-16 12:23:39 +02:00
Johannes Altmanninger
7e03bebf97 Merge pull request #11582 2025-06-16 12:23:21 +02:00
Peter Ammon
941701da3d Restore some async-signal discipline to SIGTERM
The changes to enable terminal protocols (CSI-U, etc) also attempts to
re-disable these when fish exits. In particular it attempts to disable these
from a SIGTERM handler.

Unfortunately none of that machinery is async-signal safe. Indeed our SIGTERM
handler has gotten rather sketchy, with taking a mutex and some other stuff.

Remove the async-signal-unsafe stuff and make SIGTERM manifestly safe.
Unfortunately this means that terminal protocols will remain set after SIGTERM
but that's probably unavoidable.
2025-06-15 19:06:47 -07:00
Peter Ammon
eb211e1d10 Bravely remove calls to redirect_tty_output
Calls to redirect_tty_output were added in many places when certain tty-syscalls
returned EIO. See commit 396bf1235d

This was intended to work around a glibc bug in wide character output, but it
was never really justifiable or tested, and we no longer use glibc wide
character output.

Bravely remove these, except in the case where we got SIGHUP and we don't want
to trigger SIGTTIN or SIGTTOU.
2025-06-15 18:09:53 -07:00
Daniel Rainer
a317a6acd9 Unconditionally include gettext message
Definitions of localizable strings should not be guarded by `cfg`, because then
they might not end up being exported, depending on the compilation config.
2025-06-15 23:43:31 +02:00
Daniel Rainer
d3f287c520 Retain attributes in localizable_consts
These attributes (such as doc comments) should be retained.
2025-06-15 23:43:31 +02:00
Daniel Rainer
80131acff2 Add PO file update check to tests
The PO file updates can now run in a normal test, eliminating the need for
special handling.

Rename the `check-translations.fish` script, to clarify which part of the checks
happens in it.
2025-06-15 23:43:31 +02:00
Daniel Rainer
85fb937a4d Add --use-existing-template argument
This is intended to allow translation updates in contexts where building within
the `fish_xgettext.fish` script is undesirable.

Specifically, this allows checking for PO file updates in the tests run by
`test_driver.py`. Because these use a tmpdir for `$HOME`, building within such a
test requires installing the entire Rust toolchain and doing a clean build,
which is a waste of resources.
With this argument, it is possible to build the template before running the
tests and passing the file path into the script.
2025-06-15 23:43:31 +02:00
Daniel Rainer
1e571263a0 Ensure translation script is CWD-independent 2025-06-15 23:43:31 +02:00
Daniel Rainer
1a0a6f544d Do not export test strings
When including the tests in the build, string literals passed to `wgettext!`
would be included in the gettext template file, which we do not want here,
because the strings should not be localized for this test.
2025-06-15 23:43:31 +02:00
Daniel Rainer
413ce9fdb3 Call cursor_position() lazily
This function does not need to run when the pager is not focused. Calling it
lazily eliminates the overhead of calling it when it is not needed.
This code runs on each keypress when entering a command, so it makes sense to
keep it as lean as possible. (At the very least it avoids spam when trying to
debug/analyze gettext behavior.)
2025-06-15 23:16:22 +02:00
Daniel Rainer
03e3d0aa3f Split up sphinx HTML and MAN file generation
This test is the one with the longest runtime. Splitting the two targets into
separate tests allows them to run in parallel, which can speed up the tests.
2025-06-15 18:44:58 +02:00
Peter Ammon
00c528c13f Remove parser.assert_can_execute
We don't need this; Rust's Send safety means that a Parser never changes its
thread.
2025-06-14 16:05:54 -07:00
Peter Ammon
60dbb9c8ba Fix a misleading comment. 2025-06-14 15:18:18 -07:00
Peter Ammon
2104f8a18a Remove Rc from Parser's vars
This will help enable Parser to be Send, which will be important for
concurrent execution.
2025-06-14 13:59:17 -07:00
Peter Ammon
6f18a362e6 Remove the process argument to ProcPerformer
Processes can't cross threads, so this doesn't belong here.
Preparation for concurrent execution.
2025-06-14 13:34:04 -07:00
Peter Ammon
d67fdd1f02 Make Job store boxed process list instead of Vec 2025-06-14 12:04:52 -07:00
Creeperxie
d92bb57418 Add description for gzip -d completion 2025-06-14 10:59:44 -07:00
Peter Ammon
eb4cec1fe2 Clean up pgroup assignment and tighten up some post-fork code 2025-06-14 10:34:33 -07:00
Peter Ammon
ef2e30cdc1 Clean up pids
Use OnceLock more often in place of atomics. Tighten up async signal safety.
2025-06-14 10:34:27 -07:00
Peter Ammon
294d589d2f Clean up ProcStatus
Don't need all of these atomics.

In particular use OnceLock in InternalProc as this doesn't doesn't need
locking if there's only a single writer.
2025-06-14 10:34:20 -07:00
Peter Ammon
415232631a Continued refactoring of some exec functions 2025-06-14 10:34:15 -07:00
Peter Ammon
e10a12c0f2 Rationalize certain edge cases for function execution
This concerns edge cases when executing a function. Historically, when we parse
fish script, we identify early whether or not it's a function; but only record
the function's name and not its properties (i.e. not its source).

This means that the function can change between parsing and execution. Example:

    function foo; echo alpha; end
    foo (function foo; echo beta; end)

This has historically output "beta" because the function is replaced as part of
its own arguments.

Worse is if the function is deleted:

    function foo; echo alpha; end
    foo (functions --erase foo)

This outputs an error but in an awkward place; that's OK since it's very rare.

Let's codify this behavior since someone might be depending on it.
2025-06-14 10:34:10 -07:00
Peter Ammon
6fffb76937 Move Process's block node into its Type
Previously, for Processes which were BlockNodes, we stored the node separately
in the Process via an Option; just promote this to a real field of the
ProcessType::BlockNode.

No user visible changes expected.
2025-06-14 10:34:05 -07:00
Peter Ammon
36e385e1fb Make ProcessType not Eq or PartialEq
We are going to give it fields shortly.
2025-06-14 10:33:58 -07:00
Peter Ammon
e598010020 Clean up some Node representations
Use NodeRef more pervasively, leading to simplifications.
2025-06-14 10:33:53 -07:00
Peter Ammon
eba4c906ae Minor cleanup of process creation
Remove some useless types and unnecessary boxing.
2025-06-14 10:33:48 -07:00
Peter Ammon
fbb4a8d853 Adopt Rust naming conventions in JobControl and ProcessType 2025-06-14 10:33:46 -07:00
Peter Ammon
10e525c49c Fix rustdoc warnings on macOS 2025-06-14 10:32:41 -07:00
Johannes Altmanninger
ec27b418e4 test_driver: support Python 3.8 for now
Our docker tests are currently broken since we no longer seem to install
"build_root".  When I sidestep this issue for now and run

	sudo docker/docker_run_tests.sh --shell-before docker/focal.Dockerfile
	cd /fish-source
	CARGO_TARGET_DIR=$HOME/out
	tests/test_driver.py ~/out/debug

the test driver fails in various ways.
This is because Ubuntu Focal provides Python 3.8.

Fix some of the typing incompatibilities.  Fix a hang in tests like
"tests/checks/init-command.fish"; apparently fish believes it's interactive
because Python 3.8's create_subprocess_shell() makes the fish child believe
that stdin is a TTY, so it's implicitly interactive.
2025-06-13 15:04:31 +02:00
Johannes Altmanninger
535a09a5b3 Silence error in check-all-fish-files
Our docker/docker_run_tests.sh script runs tests in a container with the fish
source tree mounted as read-only.  We have a hack to speed up repeated runs
of the check-all-fish-files test that assumes the source tree is writable.
Paper over this by silencing the error for now.

  There were no remaining checks left to match stderr:1:
    touch: cannot touch '/fish-source/tests/.last-check-all-files': Read-only file system
2025-06-13 14:56:02 +02:00
Johannes Altmanninger
4be17bfefb fixup! Extract config path module. NFC
Fix cargo (non-cmake) build.
2025-06-13 12:17:10 +02:00
Johannes Altmanninger
6fd0025f38 Make LOCALEDIR relocatable as well
As explained in c3740b85be (config_paths: fix compiled-in locale dir,
2025-06-12), fish is "relocatable", i.e. "mv /usr/ /usr2/" will leave
"/usr2/bin/fish" fully functional.

There is one exception: for LOCALEDIR we always use the path determined at
compile time.
This seems wrong; let's use the same relocatable-logic as for other paths.

Inspired by bf65b9e3a7 (Change `gettext` paths to be relocatable (#11195),
2025-03-30).
2025-06-13 11:52:46 +02:00
Johannes Altmanninger
052fc18db9 Extract config path module. NFC
This is the "code movement" part of bf65b9e3 ("Change `gettext` paths to be
relocatable (#11195)").

While at it, fix some warnings.
2025-06-13 11:52:46 +02:00
Johannes Altmanninger
d584f36f5d Remove support for elf-patching LOCALEDIR
Commit bf65b9e3a7 (Change `gettext` paths to be relocatable (#11195),
2025-03-30) is difficult to follow because it combines code movement with
two behavior changes. Our parent commit fixed the first behavior change.

The second behavior change made us tolerate trailing NUL bytes in LOCALEDIR.
This was motivated because conda wants to use binary patching to change
the effective prefix at runtime, presumably so the user can move around the
"fish" executable program arbitraily.

This turned out to be unnecessary because fish is already "relocatable"
(see our parent commit).

Let's remove the special case for LOCALEDIR. Treat it like other paths.

Closes #11574
Closes #11474
2025-06-13 11:22:15 +02:00
Johannes Altmanninger
c3740b85be config_paths: fix compiled-in locale dir
Fish uses this logic to find paths to functions etc.:

1. if $(status fish-path) starts with $CARGO_MANIFEST_DIR,
   we use $CARGO_MANIFEST_DIR/share etc.

   Aside: this also has the unintended effect that "cmake
   -DCMAKE_INSTALL_PREFIX=$PWD/prefix" will not use "$PWD/prefix/share" but
   "$PWD/share", at least since eacbd6156d (Port and adopt main written in
   Rust, 2023-08-18).

2. Else if $(status fish-path) ends with "bin/fish",
   and $(status fish-path)/../share/fish exists, we use that, since 4912967eab
   (Large set of changes related to making fish relocatable, and improving
   the build and install story, 2012-07-08)

3. Else if $(status fish-path) ends in "fish" (which is very likely),
   and $(status fish-path)/share exists, we use that, since
   c2a8de4873 (Make fish find config directories in source tree, 2016-09-23).
   I think this is for running (without installing) in-tree builds ("cmake .");
   this is not recommended but it is used, see
   https://github.com/fish-shell/fish-shell/pull/10330

4. If none of the above worked, either because the fish binary has been
   moved into a weird directory, or if we fail to get $(status fish-path)
   (e.g. on OpenBSD, where "argv[0]" is not available),
   then we fall back to reasonable default paths determined at compiled
   time.

   These paths include data_dir=$PREFIX/share.
   We recently added locale_dir too in bf65b9e3a7 (Change `gettext` paths
   to be relocatable (#11195), 2025-03-30).

In case 1, we use               locale: manifest_dir.join("share/locale"),
In case 2 and 3, we use         locale: data_dir.join("locale"),
In case 4, we use               locale: data_dir.join("share"),

The last one seems wrong (there is not "/usr/share/share"). Fix that.

Alternatively, we could revert bf65b9e3a7 (and redo the parts we want to keep).
2025-06-13 11:22:15 +02:00
Johannes Altmanninger
d840fd9a7f config_paths: remove code clone
Another evident problem from bf65b9e3a7 (Change `gettext` paths to be
relocatable (#11195), 2025-03-30). How disrespectful.
2025-06-13 11:22:15 +02:00
Johannes Altmanninger
592b059c30 config_paths: inline function 2025-06-12 11:20:56 +02:00
Johannes Altmanninger
86b9a0b876 test_driver: use isinstance chain to replace Python 3.10's match statement
We still want to support Python 3.9 (debian-oldstable); it's still used by
our (outdated) FreeBSD CI, and, more importantly by (nightly) builders on OBS.

Ref: https://github.com/fish-shell/fish-shell/pull/11560#discussion_r2134556573
2025-06-12 11:20:55 +02:00
Johannes Altmanninger
6822a772fb Merge pull request #11573 2025-06-12 10:29:11 +02:00
Daniel Rainer
912d93c99d Remove tmpdirs at the end of tests 2025-06-11 22:33:32 +02:00
Johannes Altmanninger
74f4742565 Merge pull request #11567 2025-06-11 14:02:07 +02:00
Johannes Altmanninger
a47dcad1ea Clean up staticbuild CI action
- This action does not use CMake or CTest, so remove associated environment variables.
- Remove a seemingly unnecessary check

Tested with "gh --repo krobelus/fish-shell workflow run staticbuild.yml --ref=tmp", see
https://github.com/krobelus/fish-shell/actions/runs/15583255106/job/43883294589
2025-06-11 13:22:09 +02:00
Integral
63a08e53e5 Replace some PathBuf with Path avoid unnecessary heap allocation (#10929)
(cherry picked from commit b19a467ea6)
2025-06-11 11:38:53 +02:00
Erick Howard
62ac23453e Code cleanup in src/bin/fish.rs to make it more idiomatic (#10975)
Code cleanup in `src/bin/fish.rs` to make it more idiomatic

(cherry picked from commit 967c4b2272)
2025-06-11 11:31:05 +02:00
Johannes Altmanninger
69bd7cc9a5 Merge pull request #11561 2025-06-11 11:14:56 +02:00
Daniel Rainer
b56ee16aa9 Parallelize test_driver.py
This uses Python's `asyncio` to run tests in parallel, which speeds up test
execution significantly.

The timeout is removed. It would be possible to add a timeout to
`asyncio.as_completed()` if we want that.
2025-06-10 20:11:43 +02:00
Daniel Rainer
679cef9c0e Add async versions of littlecheck tests
These will be used by a parallelized version of `test_driver.py`.

The old, non-async versions are kept, but just a wrappers around the async
versions.
2025-06-10 20:11:43 +02:00
Daniel Rainer
01b623efce Do not modify env vars in test_driver.py
Such modifications would break tests when they run concurrently, as they will
when this script is parallelized using `asyncio`.
2025-06-10 20:11:36 +02:00
Daniel Rainer
aa627ea935 Allow specifying env for running test
This can be used instead of the default operating system variables.
Useful for running multiple tests which need different environments.
2025-06-10 19:37:47 +02:00
Daniel Rainer
c15a900f31 Fail on compilation failure 2025-06-10 19:37:47 +02:00
Daniel Rainer
1136e656e0 Remove --cachedir for test_driver.py
This was only used to cache `fish_test_driver`, which can be built in a few tens
of milliseconds on most systems.

This avoids using outdated binaries for testing and simplifies the code and its
usage.
2025-06-10 19:37:47 +02:00
Daniel Rainer
456c9254fa Annotate more run_test parameters
This helps with static analysis.

Rename the second argument to clarify what it refers to.
2025-06-10 19:37:47 +02:00
Daniel Rainer
ebc16e51d7 Build fish_test_helper at most once
If no `--cachedir` is specifed for `test_driver.py`, it would build
`fish_test_helper` once per test it runs. This is unnecessary. Instead, build it
once in the beginning before running any tests and then use the binary in all
tests.
2025-06-10 19:37:41 +02:00
Johannes Altmanninger
c052beb4dd Fix build on Rust 1.70 2025-06-10 17:56:21 +02:00
Daniel Rainer
2d7a6063b9 Remove unnecessary trailing space 2025-06-10 17:08:44 +02:00
Daniel Rainer
7c57b746d0 Use Path for some paths
The added type annotations help with static analysis and constructing paths gets
some syntactic sugar.
2025-06-10 17:07:19 +02:00
Johannes Altmanninger
e0cabacdaa kitty keyboard protocol: fall back to base layout key
On terminals that do not implement the kitty keyboard protocol "ctrl-ц" on
a Russian keyboard layout generally sends the same byte as "ctrl-w". This
is because historically there was no standard way to encode "ctrl-ц",
and the "ц" letter happens to be in the same position as "w" on the PC-101
keyboard layout.

Users have gotten used to this, probably because many of them are switching
between a Russian (or Greek etc.) and an English layout.

Vim/Emacs allow opting in to this behavior by setting the "input method"
(which probably means "keyboard layout").

Match key events that have the base layout key set against bindings for
that key.

Closes #11520

---

Alternatively, we could add the relevant preset bindings (for "ctrl-ц" etc.)
but
1. this will be wrong if there is a disagreement on the placement of "ц" between two layouts
2. there are a lot of them
3. it won't work for user bindings (for better or worse)

(cherry picked from commit 7a79728df3)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
59b9f57802 fish_key_reader: unopinionated description for bind notation variants
As explained in the parent commit, "alt-+" is usually preferred over
"alt-shift-=" but both have their moments. We communicate this via a comment
saying "# recommended notation". This is not always true and not super helpful,
especially as we add a third variant for #11520 (physical key), which is
the recommended one for users who switch between English and Cyrillic layouts.

Only explain what each variant does. Based on this the user may figure out
which one to use.

(cherry picked from commit 4cbd1b83f1)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
65fc2b539c Fix some invalid assertions parsing keys
For example the terminal sending « CSI 55296 ; 5 u » would crash fish.

(cherry picked from commit c7391d1026)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
3f1add9e21 Sanitize some inputs in CSI parser
This was copied from C++ code but we have overflow checks, which
forces us to actually handle errors.

While at it, add some basic error logging.

Fixes #11092

(cherry picked from commit 4c28a7771e)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
68d2cafa6e input: remove unnecessary check in bracketed paste code path
When "self.paste_is_buffering()" is true, "parse_escape_sequence()" explicitly
returns "None" instead of "Some(Escape)".  This is irrelevant because this
return value is never read, as long as "self.paste_is_buffering()" remains
true until "parse_escape_sequence()" returns, because the caller will return
early in that case. Paste buffering only ends if we actually read a complete
escape sequence (for ending bracketed paste).

Remove this extra branch.

(cherry picked from commit e5fdd77b09)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
b9d9e7edc6 Match bindings with explicit shift first
The new key notation canonicalizes aggressively, e.g.  these two bindings
clash:

	bind ctrl-shift-a something
	bind shift-ctrl-a something else

This means that key events generally match at most one active binding that
uses the new syntax.

The exception -- two coexisting new-syntax binds that match the same key
event -- was added by commit 50a6e486a5 (Allow explicit shift modifier for
non-ASCII letters, fix capslock behavior, 2025-03-30):

	bind ctrl-A 'echo A'
	bind ctrl-shift-a 'echo shift-a'

The precedence was determined by definition order.
This doesn't seem very useful.

A following patch wants to resolve #11520 by matching "ctrl-ц" events against
"ctrl-w" bindings. It would be surprising if a "ctrl-w" binding shadowed a
"ctrl-ц" one based on something as subtle as definition order.  Additionally,
definition order semantics (which is an unintended cause of the implementation)
is not really obvious.  Reverse definition order would make more sense.

Remove the ambiguity by always giving precedence to bindings that use
explicit shift.

Unrelated to this, as established in 50a6e486a5, explicit shift is still
recommended for bicameral letters but not typically for others -- e.g. alt-+
is typically preferred over alt-shift-= because the former also works on a
German keyboard.

See #11520

(cherry picked from commit 08c8afcb12)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
6b17ec7dae Allow explicit shift modifier for non-ASCII letters, fix capslock behavior
We canonicalize "ctrl-shift-i" to "ctrl-I".
Both when deciphering this notation (as given to builtin bind),
and when receiving it as a key event ("\e[105;73;6u")

This has problems:

A. Our bind notation canonicalization only works for 26 English letters.
   For example, "ctrl-shift-ä" is not supported -- only "ctrl-Ä" is.
   We could try to fix that but this depends on the keyboard layout.
   For example "bind alt-shift-=" and "bind alt-+" are equivalent on a "us"
   layout but not on a "de" layout.
B. While capslock is on, the key event won't include a shifted key ("73" here).
   This is due a quirk in the kitty keyboard protocol[^1].  This means that
   fish_key_reader's canonicalization doesn't work (unless we call toupper()
   ourselves).

I think we want to support both notations.

It's recommended to match all of these (in this order) when pressing
"ctrl-shift-i".

	1. bind ctrl-shift-i do-something
	2. bind ctrl-shift-I do-something
	3. bind ctrl-I do-something
	4. bind ctrl-i do-something

Support 1 and 3 for now, allowing both bindings to coexist. No priorities
for now. This solves problem A, and -- if we take care to use the explicit
shift notation -- problem B.

For keys that are not affected by capslock, problem B does not apply.  In this
case, recommend the shifted notation ("alt-+" instead of "alt-shift-=")
since that seems more intuitive.
Though if we prioritized "alt-shift-=" over "alt-+" as per the recommendation,
that's an argument against the shifted key.

Example output for some key events:

	$ fish_key_reader -cV
	# decoded from: \e\[61:43\;4u
	bind alt-+ 'do something' # recommended notation
	bind alt-shift-= 'do something'
	# decoded from: \e\[61:43\;68u
	bind alt-+ 'do something' # recommended notation
	bind alt-shift-= 'do something'

	# decoded from: \e\[105:73\;6u
	bind ctrl-I 'do something'
	bind ctrl-shift-i 'do something' # recommended notation
	# decoded from: \e\[105\;70u
	bind ctrl-shift-i 'do something'

Due to the capslock quirk, the last one has only one matching representation
since there is no shifted key.  We could decide to match ctrl-shift-i events
(that don't have a shifted key) to ctrl-I bindings (for ASCII letters), as
before this patch. But that case is very rare, it should only happen when
capslock is on, so it's probably not even a breaking change.

The other way round is supported -- we do match ctrl-I events (typically
with shifted key) to ctrl-shift-i bindings (but only for ASCII letters).
This is mainly for backwards compatibility.

Also note that, bindings without other modifiers currently need to use the
shifted key (like "Ä", not "shift-ä"), since we still get a legacy encoding,
until we request "Report all keys as escape codes".

[^1]: <https://github.com/kovidgoyal/kitty/issues/8493>

(cherry picked from commit 50a6e486a5)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
08d796890a Stop accepting "bind shift-A"
This notation doesn't make sense, use either A or shift-a.  We accept it
for ASCII letters only -- things like "bind shift-!" or "bind shift-Ä"
do not work as of today, we don't tolerate extra shift modifiers yet.
So let's remove it for consistency.

Note that the next commit will allow the shift-A notation again, but it will
not match shift-a events.

(cherry picked from commit 7f25d865a9)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
4f98ef36f6 Extract KeyEvent type
The be used in the grandchild commit.

(cherry picked from commit 855a1f702e)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
a09c78491f Extract function for creating key event with modifiers
(cherry picked from commit fabbbba037)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
02932d6b8c Extract constant for the number of function keys
Switch to fish_wcstoul because we want the constant to be unsigned.
It's u32 because most callers of function_key() want that.

(cherry picked from commit e9d1cdfe87)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
7cca98bda2 Fix regression decoding function keys
Commit 109ef88831 (Add menu and printscreen keys, 2025-01-01)
accidentally broke an assumption by inverting f1..f12.  Fix that.

Fixes #11098

(cherry picked from commit d2b2c5286a)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
b77fc28692 Add menu and printscreen keys
These aren't typically used in the terminal but they are present on
many keyboards.

Also reorganize the named key constants a bit.  Between F500 and
ENCODE_DIRECT_BASE (F600) we have space for 256 named keys.

(cherry picked from commit 109ef88831)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
3475531ef7 Also ignore invalid recursive escape sequences
We parse "\e\e[x" as alt-modified "Invalid" key.  Due to this extra
modifier, we accidentally add it to the input queue, instead of
dropping this invalid key.

We don't really want to try to extract some valid keys from this
invalid sequence, see also the parent commit.

This allows us to remove misplaced validation that was added by
e8e91c97a6 (fish_key_reader: ignore sentinel key, 2024-04-02) but
later obsoleted by 66c6e89f98 (Don't add collateral sentinel key to
input queue, 2024-04-03).

(cherry picked from commit 84f19a931d)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
8222ed891b Stop parsing invalid CSI/SS3 sequences as alt-[/alt-o
This situation can be triggered in practice inside a terminal like tmux
3.5 by running

	tmux new-session fish -C 'sleep 2' -d reader -o log-file

and typing "alt-escape x"

The log shows that we drop treat this as alt-[ and drop  the x on the floor.

	reader: Read char alt-\[ -- Key { modifiers: Modifiers { ctrl: false,
	alt: true, shift: false }, codepoint: '[' } -- [27, 91, 120]

This input ("\e[x") is ambiguous.

It looks like it could mean "alt-[,x".  However that conflicts with a
potential future CSI code, so it makes no sense to try to support this.

Returning "None" from parse_csi() causes this weird behavior of
returning "alt-[" and dropping the rest of the parsed sequence.
This is too easy; it has even crept into a bunch of places
where the input sequence is actually valid like "VT200 button released"
but where we definitely don't want to report any key.

Fix the default: report no key for all unknown sequences and
intentionally-suppressed sequences.  Treat it at "alt-[" only when
there is no input byte available, which is more or less unambiguous,
hence a strong enough signal that this is a actually "alt-[".

(cherry picked from commit 3201cb9f01)
2025-06-10 16:50:00 +02:00
Johannes Altmanninger
f787e6858c Fix tests/checks/autoload.fish
Apparently this test runs with "build/tests" as CWD when run with cmake.
2025-06-10 16:50:00 +02:00
Daniel Rainer
64442cb464 Use with syntax for tmpdir root 2025-06-10 16:20:56 +02:00
Lorenzo Albano
07ead04890 Improve fish_git_prompt stashes detection.
When the informative status is disabled, the stashstate variable was
set to 1 if the $git_dir/logs/refs/stash file existed and was readable,
even if the file itself was empty (i.e., no stashes). Now the stashstate
variable is set only if the file is NOT empty.
2025-06-09 13:16:24 +02:00
Johannes Altmanninger
5346d3d491 check-all-fish-files: don't glob the entire worktree
Commit 22c0054c1e (Add check to test all fish files with -n, 2020-02-17)
added a test that runs "fish --no-execute" on all fish files in share/**.fish

Commit 329cd7d429 (Make functions, completions and tests resilient to
running on an embed-data fish, 2025-03-25) change this to run it on **.fish.

Evidently "the tests are exempt because they contain syntax errors" is no
longer true - this is because we have since changed those files to recursively
run 'fish -c "syntax-error"', which makes it easier to test for multiple
syntax-errors in a single test file. Remove the comment.

Globbing everything seems a bit crass, and there's no explicit
motivation.

	$ time find -name '*.fish' >/dev/null
	Executed in  431.93 millis
	$ time find * -name '*.fish' >/dev/null
	Executed in   39.98 millis

Let's go back to testing only directories where we currently have Git-tracked
fish files.  This makes uncached "check-all-fish-files.fish" go from 26
seconds to 5 seconds.
2025-06-09 10:28:49 +02:00
Johannes Altmanninger
138c6c4c40 check-all-fish-files: remove unneeded fallback
According to commit 8a07db8e8f (Revert "Revert "Speed up check-all-fish-files
when executed locally"", 2021-03-06), we can assume "find -newer" is supported.
2025-06-09 10:28:49 +02:00
Johannes Altmanninger
f8751a4f97 check-all-fish-files: fix caching logic
check-all-fish-files takes a long time (>20 seconds here); which is why we
have a (hacky) optimization to avoid checking files we already checked.
This optimization hasn't worked since commit e96b6e157c (Remove TMPDIR
dependency from tests/, 2021-07-30) which started each test invocation in
a private tmpdir. Fix that.

The optimization is useful because this test is, by far, the bottleneck
for parallel test execution (#11561):

	$ cargo b && time tests/test_driver.py target/debug
	...
	checks/tmux-complete.fish                      PASSED    8465 ms
	checks/check-completions.fish                  PASSED   10948 ms
	checks/check-sphinx.fish                       PASSED   12949 ms
	checks/check-all-fish-files.fish               PASSED   29828 ms
	200 / 200 passed (0 skipped)
	________________________________________________________
	Executed in   31.00 secs    fish           external
	   usr time   81.02 secs  462.00 micros   81.02 secs
	   sys time   26.41 secs  272.00 micros   26.41 secs

A cache miss for check-all-fish-files.fish takes 24 seconds (though the
grandchild commit will speed this up), a cache hit 0.5 seconds.
2025-06-09 10:28:49 +02:00
Johannes Altmanninger
cdc2db5eae Update translations for git completions 2025-06-08 14:07:17 +02:00
Johannes Altmanninger
aea9cd6165 completions/git: sort stash completions after branches and others
Completions like "stash@{1}" don't give a lot of information, unlike local
branches which are sorted by recency so let's put those first.
2025-06-08 13:42:01 +02:00
Johannes Altmanninger
d0a490d76b completions/git: extract logic 2025-06-08 13:42:01 +02:00
Johannes Altmanninger
b4392f6f7d completions/git: extract function for adding arbitrary-revision-completion
Most Git commands take arbitrary revisions.  AFAICT, we usually want the same
order, e.g. list local branches before remote branches before commit IDs etc.
I think there is no particular reason why this order is inconsistent between
various subcommands.

Let's extract a function. This standardizes the order and adds various
revision-types that were missing for some subcommands.
2025-06-08 13:42:01 +02:00
Johannes Altmanninger
7f2f5bb2f4 completions/git: remove code clone 2025-06-08 13:26:12 +02:00
Johannes Altmanninger
c47ecf9677 completions/git: rebase --onto requires a revision argument 2025-06-08 13:21:55 +02:00
Johannes Altmanninger
cd45a8c5cc completions/git: add more special refs
These are things like .git/HEAD, i.e. the ones that are typically not
namespaced under .git/refs.  The list is taken from gitrevisions(7).
2025-06-08 13:21:55 +02:00
Johannes Altmanninger
99f78fb0b1 completions/git: fix copy-paste error
This variable is never defined. It was copied from Git's
contrib/completion/git-completion.bash where $match is probably equivalent
to $(commandline -t). I could not measure a significant speedup from passing
this filter to "git for-each-ref", so let's remove it for now.
2025-06-08 13:21:55 +02:00
Johannes Altmanninger
235108e2df CI rust_checks: cargo --workspace obsoletes --all
This flag exists since 1.39, see
https://doc.rust-lang.org/nightly/cargo/CHANGELOG.html#cargo-139-2019-11-07

While at it, remove the "--all" option from "cargo fmt",
since it's not needed for formatting the entire workspace,
and because it would also format path-dependencies, see
https://github.com/fish-shell/fish-shell/pull/11550#discussion_r2133674330
2025-06-08 13:21:12 +02:00
Johannes Altmanninger
e66b13ac3d Merge pull request #11560 2025-06-08 12:09:41 +02:00
Johannes Altmanninger
0c211cbffb Merge pull request #11564 2025-06-08 11:27:01 +02:00
Johannes Altmanninger
da5a394178 Merge pull request #11566 2025-06-08 11:25:41 +02:00
Johannes Altmanninger
59bfd3ba6c Merge pull request #11563 2025-06-08 11:25:32 +02:00
Daniel Rainer
631bde1081 Revert "Hide some calls to localize() via Deref/AsRef"
This reverts commit 894139933d.

Rationale in this comment thread:
https://github.com/fish-shell/fish-shell/pull/11547#discussion_r2133625349
2025-06-08 02:52:01 +02:00
cyclopentane
383d2aa3e9 Fix behaviour upon repeating a vi-mode t/T jump 2025-06-08 01:03:06 +02:00
Daniel Rainer
cac3d0ef16 Build before running style.fish
This makes the latest versions of fish_indent (and fish) available to
`style.fish`.
2025-06-07 20:21:29 +02:00
Daniel Rainer
4721ffe512 Remove unused variables 2025-06-07 19:31:06 +02:00
Daniel Rainer
df097b114c Put test tmpdirs under common root tmpdir
This is done to prepare for running the tests in parallel.
With this approach the root tmpdir can be created before any test starts, each
test can create its home dir under the root tmpdir,
and when all tests are done the root tmpdir can be deleted.
Deletion of per-test dirs is more difficult in an async context.
2025-06-07 19:30:44 +02:00
Daniel Rainer
2ebe3134cf Extract function for running tests
This is done to prepare for running tests concurrently.

Align output and prevent flushing stdout between test name and result.
2025-06-07 19:28:58 +02:00
David Adam
d663f553df document alt-s binding programs more clearly 2025-06-07 22:47:56 +08:00
Shayan
dcde198c94 completions/adb: add listing device files for exec-out subcommand 2025-06-07 22:44:57 +08:00
Daniel Rainer
b5c393dc39 Add simple script for running checks
This is intended as a way to run all available checks with a single command.

The script can be used locally and in CI. It is intended to replace
`cmake/Tests.cmake` (but this script also runs checks not present there).
At the moment, `ctest` is not used, which could be added to speed up tests.

Address and thread sanitizers are not run by this script.
2025-06-07 15:34:53 +02:00
Daniel Rainer
f0a54510c3 Format files using build_tools/style.fish 2025-06-07 15:34:53 +02:00
Daniel Rainer
d18d414745 Improve style.fish
Add flags to control behavior.
- `--check` to fail if changes would be made by formatters
- `--force` to skip the prompt about uncommitted changes

Fix behavior when `--all` is not specified. It used to operate on `$files`,
which did not get set in that case.

Not all fish files are considered, mainly because some tests might test how fish
behaves on weirdly formatted files.

For Rust files, `cargo fmt` is used when `--all` is specified.
The `--check` flag for `cargo fmt` is used when appropriate.

Do not try to build `fish_indent`. `make fish_indent` does not work anymore. Let
the user handle building and installing/setting `$PATH`.
2025-06-07 15:34:53 +02:00
Johannes Altmanninger
ac44b3da91 build_tools/fish_xgettext.fish: fix formatting 2025-06-07 11:15:44 +02:00
Johannes Altmanninger
0903e7a8f2 Merge pull request #11557 2025-06-07 10:20:30 +02:00
Johannes Altmanninger
894139933d Hide some calls to localize() via Deref/AsRef
As suggested in https://github.com/fish-shell/fish-shell/pull/11547#discussion_r2133625349
AsRef is needed for OutputStream::append which has this signature:

	pub fn append<Str: AsRef<wstr>>(&mut self, s: Str) -> bool
2025-06-07 10:20:30 +02:00
Johannes Altmanninger
1aec1d3955 Merge pull request #11547
Supersedes previous approaches:
Closes #11543
Closes #11536
2025-06-07 10:20:30 +02:00
Daniel Rainer
a138bc328b Fix eager cloning
https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
2025-06-07 00:22:52 +02:00
Daniel Rainer
b9583bb16a Document call sites of from_external_source
This is intended to provide information to programmers where localizations might
be coming from, and potentially help with analyzing issues with localizations.
2025-06-07 00:10:10 +02:00
Daniel Rainer
80033adcf5 Use LocalizableString for gettext
This new wrapper type can be constructed via macros which invoke the
`gettext_extract` proc macro to extract the string literals for PO file
generation.

The type checking enabled by this wrapper should prevent trying to obtain
translations for a string for which none exist.

Because some strings (e.g. for completions) are not defined in Rust, but rather
in fish scripts, the `LocalizableString` type can also be constructed from
non-literals, in which case no extraction happens.
In such cases, it is the programmer's responsibility to only construct the type
for strings which are available for localization.

This approach is a replacement for the `cargo-expand`-based extraction.

When building with the `FISH_GETTEXT_EXTRACTION_FILE` environment variable set,
the `gettext_extract` proc macro will write the messages marked for extraction
to a file in the directory specified by the variable.

Updates to the po files:
- This is the result of running the `update_translations.fish` script using the
  new proc_macro extraction. It finds additional messages compared to the
  `cargo-expand` based approach.
- Messages IDs corresponding to paths are removed. The do not have localizations
  in any language and localizing paths would not make sense. I have not
  investigated how they made it into the po files in the first place.
- Some messages are reordered due to `msguniq` sorting differing from `sort`.

Remove docs about installing `cargo-expand`
These are no longer needed due to the switch to our extraction macro.
2025-06-07 00:10:05 +02:00
Daniel Rainer
51a57870eb Make help error message localizable 2025-06-07 00:02:31 +02:00
Daniel Rainer
98b3ba5e8e Remove concat! macro from localized strings
This is done in preparation for a proc macro which extracts strings which are
passed to `gettext`. Because the `concat!` macro would get expanded after the
proc macro, the proc macro would still see the `concat!`, which it cannot
handle.
2025-06-07 00:02:14 +02:00
Johannes Altmanninger
08bf5c92a9 Merge pull request #11545 2025-06-06 12:54:55 +02:00
Johannes Altmanninger
a84048511e Merge pull request #11542 2025-06-06 11:54:45 +02:00
Fabian Boehm
a014166795 completions/nmcli: Complete at runtime
This used to get all the interfaces and ssids when the completions
were loaded. That's obviously wrong, given that ssids especially can, you know, change

(cherry picked from commit 9116c61736)

cherry-picking since this easy to trigger
(seen again in https://github.com/fish-shell/fish-shell/pull/11549)
2025-06-06 11:52:17 +02:00
Johannes Altmanninger
46e8f12dbf Merge pull request #11554 2025-06-05 14:28:36 +02:00
Dennis Huang
7fe92be405 Add --all option to path
- Add --all option to path
- Add tests
- Add doc
2025-06-05 14:10:47 +02:00
Chinmay Dalal
366034940f Add run0 to alt-s commands
https://www.freedesktop.org/software/systemd/man/devel/run0.html
Since everyone using a systemd distro will have this, it's added
at the end so that it's tried last
2025-06-04 20:00:52 +05:30
Daniel Rainer
6239cba1e4 Add dry-run mode to update_translations.fish
This mode is intended for testing if the PO files are up-to-date and
well-formed.

At the moment, we only check translations in CI, where this is not particularly
relevant. Once we no longer need `cargo-expand`
(e.g. via https://github.com/fish-shell/fish-shell/pull/11536)
we can extend the `check_translations.fish` test to run
`update_translations.fish --dry-run` and fail if the exit status is nonzero.
2025-06-02 03:18:25 +02:00
Daniel Rainer
8c5de9acfb Remove manual contains
See https://rust-lang.github.io/rust-clippy/master/index.html#manual_contains.

The old code results in a clippy warning on Rust 1.87.
2025-05-31 12:56:58 +02:00
Daniel Rainer
75d243faaa Check rustdocs in CI
Setting `RUSTDOCFLAGS='-D warnings'` is needed to fail on warnings.
For `cargo test --doc` no equivalent option seems to exist.
See https://github.com/rust-lang/cargo/issues/14802.
2025-05-30 21:32:40 +02:00
Daniel Rainer
ba86028aaa Fix rustdoc warning 2025-05-30 21:32:40 +02:00
Johannes Altmanninger
f7e639504a completions/git: improve idempotency in case of double load
As mentioned in the previous few commits and in #11535, running
"set fish_complete_path ..."  and "complete -C 'git ...'"  may result in
"share/completions/git.fish" being loaded multiple times.

This is usually fine because fish internally erases all cached completions
whenever fish_complete_path changes.

Unfortunately there is at least global variable that grows each time git.fish
is sourced. This doesn't make a functional difference but it does slow
down completions.  Fix that by resetting the variable at load time.

(cherry picked from commit 4b5650ee4f)
2025-05-29 18:01:22 +02:00
Johannes Altmanninger
028b60cad6 Fix "set fish_complete_path" accidentally disabling autoloading
Commit 5918bca1eb (Make "complete -e" prevent completion autoloading,
2024-08-24) makes "complete -e foo" add a tombstone for "foo", meaning we
will never again load completions for "foo".

Due to an oversight, the same tombstone is added when we clear cached
completions after changing "fish_complete_path", preventing completions from
being loaded in that case.  Fix this by restoring the old behavior unless
the user actually used "complete -e".

(cherry picked from commit a7c04890c9)
2025-05-29 18:01:04 +02:00
Johannes Altmanninger
7a79728df3 kitty keyboard protocol: fall back to base layout key
On terminals that do not implement the kitty keyboard protocol "ctrl-ц" on
a Russian keyboard layout generally sends the same byte as "ctrl-w". This
is because historically there was no standard way to encode "ctrl-ц",
and the "ц" letter happens to be in the same position as "w" on the PC-101
keyboard layout.

Users have gotten used to this, probably because many of them are switching
between a Russian (or Greek etc.) and an English layout.

Vim/Emacs allow opting in to this behavior by setting the "input method"
(which probably means "keyboard layout").

Match key events that have the base layout key set against bindings for
that key.

Closes #11520

---

Alternatively, we could add the relevant preset bindings (for "ctrl-ц" etc.)
but
1. this will be wrong if there is a disagreement on the placement of "ц" between two layouts
2. there are a lot of them
3. it won't work for user bindings (for better or worse)
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
4cbd1b83f1 fish_key_reader: unopinionated description for bind notation variants
As explained in the parent commit, "alt-+" is usually preferred over
"alt-shift-=" but both have their moments. We communicate this via a comment
saying "# recommended notation". This is not always true and not super helpful,
especially as we add a third variant for #11520 (physical key), which is
the recommended one for users who switch between English and Cyrillic layouts.

Only explain what each variant does. Based on this the user may figure out
which one to use.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
3ab6fcf21c fish_key_reader: show most specific key notation first
As of the parent commit, "ctrl-shift-x" bindings will take precedence over
"ctrl-X". Have fish_key_reader imply this via the ordering The next commit
will make this more explicit.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
08c8afcb12 Match bindings with explicit shift first
The new key notation canonicalizes aggressively, e.g.  these two bindings
clash:

	bind ctrl-shift-a something
	bind shift-ctrl-a something else

This means that key events generally match at most one active binding that
uses the new syntax.

The exception -- two coexisting new-syntax binds that match the same key
event -- was added by commit 50a6e486a5 (Allow explicit shift modifier for
non-ASCII letters, fix capslock behavior, 2025-03-30):

	bind ctrl-A 'echo A'
	bind ctrl-shift-a 'echo shift-a'

The precedence was determined by definition order.
This doesn't seem very useful.

A following patch wants to resolve #11520 by matching "ctrl-ц" events against
"ctrl-w" bindings. It would be surprising if a "ctrl-w" binding shadowed a
"ctrl-ц" one based on something as subtle as definition order.  Additionally,
definition order semantics (which is an unintended cause of the implementation)
is not really obvious.  Reverse definition order would make more sense.

Remove the ambiguity by always giving precedence to bindings that use
explicit shift.

Unrelated to this, as established in 50a6e486a5, explicit shift is still
recommended for bicameral letters but not typically for others -- e.g. alt-+
is typically preferred over alt-shift-= because the former also works on a
German keyboard.

See #11520
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
3951a858dd reader: do not send queries if stdout is not a terminal
Interactive fish with output redirected ("fish >/dev/null")
is not a common use case but it is valid.

Perhaps surprisingly, "fish >some-file" *does* print terminal escape codes
(colors, cursor movement etc.) even if terminal output is not a TTY.
This is typically harmless, and potentially useful for debugging.

We also send blocking terminal queries but those are not harmless in this case.
Since no terminal will receive the queries, we hang; indefinitely as of today,
but we should give up after a timeout and print an error.  Either way that
seems needlessly surprising. Suppress queries in this case.

In future, we should probably do something similar if stdin is not a terminal;
though in that case we're even less likely to be interactive (only "-i"
I think).
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
c7a19a00ab reader: minor simplification 2025-05-29 17:57:38 +02:00
Johannes Altmanninger
e5fdd77b09 input: remove unnecessary check in bracketed paste code path
When "self.paste_is_buffering()" is true, "parse_escape_sequence()" explicitly
returns "None" instead of "Some(Escape)".  This is irrelevant because this
return value is never read, as long as "self.paste_is_buffering()" remains
true until "parse_escape_sequence()" returns, because the caller will return
early in that case. Paste buffering only ends if we actually read a complete
escape sequence (for ending bracketed paste).

Remove this extra branch.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
3fcdbe1a19 Discard input queue when ctrl-c is pressed while waiting for query response
On startup, we block until the terminal responds to our primary device
attribute query.
As an escape hatch, ctrl-c makes us stop waiting.

No keys are discarded; even ctrl-c is still enqueued.  Usually this isn't
noticed because typing "echo<ctrl-c>" will insert a "echo" only to immediately
clear it.

The double interpretation of ctrl-c seems odd.
Additionally, the queuing seems unsafe considering that when typing something
like "echo hello<enter><ctrl-c>" the command will be executed.

Clear the queue instead, including ctrl-c.
This matches other programs like gdb, Kakoune and possibly others.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
2071df126c Idiomatic type for reader_readline nchars argument 2025-05-29 17:57:38 +02:00
Johannes Altmanninger
4b5650ee4f completions/git: improve idempotency in case of double load
As mentioned in the previous few commits and in #11535, running
"set fish_complete_path ..."  and "complete -C 'git ...'"  may result in
"share/completions/git.fish" being loaded multiple times.

This is usually fine because fish internally erases all cached completions
whenever fish_complete_path changes.

Unfortunately there is at least global variable that grows each time git.fish
is sourced. This doesn't make a functional difference but it does slow
down completions.  Fix that by resetting the variable at load time.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
5657f093e7 Test case for autoload + erase + autoload
Commit 5918bca1eb (Make "complete -e" prevent completion autoloading,
2024-08-24) has a weird "!removed" check; it was added because "complete
-e" only needs to create the tombstone if we removed nothing.  Otherwise the
autoloader will usually take care of not loading the removed completions again.
We should probably get rid of "!removed"..  for now add a test to demonstrate
this behavior.
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
a7c04890c9 Fix "set fish_complete_path" accidentally disabling autoloading
Commit 5918bca1eb (Make "complete -e" prevent completion autoloading,
2024-08-24) makes "complete -e foo" add a tombstone for "foo", meaning we
will never again load completions for "foo".

Due to an oversight, the same tombstone is added when we clear cached
completions after changing "fish_complete_path", preventing completions from
being loaded in that case.  Fix this by restoring the old behavior unless
the user actually used "complete -e".
2025-05-29 17:57:38 +02:00
Johannes Altmanninger
52f23b9752 autoload: add more details to autoload-result log 2025-05-29 17:50:48 +02:00
Johannes Altmanninger
6737872fb7 embed-data: naturalize generated_completions-hack to prevent repeated autoloading
As reported in https://github.com/fish-shell/fish-shell/issues/11535#issuecomment-2915440295,
a command like "complete -C'git '" gets progressively slower every time.

A diff of "fish_trace=1" output shows that each completion invocation added
more stuff to the global "__fish_git_aliases", resulting in output like:

	--> for s db
	...
	--> for s db s db
	...
	--> for s db s db s db

Reproducer:

	$ touch ~/.local/share/fish/generated_completions/foo.fish
	$ cargo install --path . --debug
	$ ~/.cargo/bin/fish -d autoload -c 'function foo; end; for i in 1 2; complete -C"foo "; end'

We redundantly autoload the embedded file, which, by definition doesn't change.
This happens when
1. the "embed-data" feature is enabled (default for "cargo install")
2. there is a completion file in generated_completions

which triggers a hack to give precedence to "embedded:completions/git.fish"
over "generated_completions/git.fish".

Since we always load all file-based files first, we clobber the autoload cache
("self.autoloaded_files") with the mtime of the generated completion file, even
if we're never gonna return it.  This makes the embed-data logic think that
the asset has changed (which is impossible! But of course it is possible that
"fish_complete_path" changes and causes a need to load "embedded:git.fish").

Fix that by treating embedded files more like normal files.  This is closer
to historical behavior where $__fish_data_dir/{functions,completions}
are normal directories. Seems like this should fix a false negative in
"has_attempted_autoload" which feels useful.

Add a dead test, I guess. It's not run with feature="embed-data" yet. In
future we should test this in CI.
2025-05-29 17:38:42 +02:00
Johannes Altmanninger
f88f7e8dd6 autoload: remove code clone 2025-05-29 16:39:52 +02:00
Johannes Altmanninger
b3dbdb90c2 On enter, insert any failed search into the command line
This might help with use cases such as https://github.com/fish-shell/fish-shell/pull/11450.
Not sure.
2025-05-29 16:39:52 +02:00
Johannes Altmanninger
dc129add9e Assert that autosuggestions are always valid
This documents an invariant established by 532abaddae (Invalidate stale
autosuggestions eagerly, 2024-12-25). It was initially broken but fixed in
ba4ead6ead (Stop saving autosuggestions that we can't restore, 2025-01-17).
2025-05-29 16:39:52 +02:00
Johannes Altmanninger
19c3bebdd9 Merge pull request #11506 2025-05-29 16:23:19 +02:00
Johannes Altmanninger
093b468ac1 Merge pull request #11502 2025-05-29 16:06:24 +02:00
Johannes Altmanninger
88bbf5f3ac Merge pull request #11497 2025-05-29 16:06:11 +02:00
Daniel Rainer
ec8fa7485c Improve docs for string join 2025-05-28 17:09:13 +02:00
Daniel Rainer
c2e2237e7c Add a test which fails on sphinx warning/failure 2025-05-28 15:32:13 +02:00
Daniel Rainer
98df97d317 Add CI check for outdated translations 2025-05-27 16:48:33 +02:00
Daniel Rainer
7ca57894cc Update translations via script
No actual translations are added.
2025-05-27 16:48:20 +02:00
Johannes Altmanninger
c7391d1026 Fix some invalid assertions parsing keys
For example the terminal sending « CSI 55296 ; 5 u » would crash fish.
2025-05-27 14:33:09 +02:00
Johannes Altmanninger
1963b0830d Merge pull request #11517 2025-05-27 13:15:34 +02:00
Johannes Altmanninger
74ce965f32 Merge pull request #11522 2025-05-27 13:15:34 +02:00
Johannes Altmanninger
27420aaf8b Merge pull request #11528 2025-05-27 13:15:34 +02:00
Johannes Altmanninger
52cdb7fd62 functions/history: error out immediately if "builtin read" failed
Didn't test all of them..

Closes #11532
2025-05-27 13:15:33 +02:00
exploide
18c4debbc0 __fish_complete_man: cope with gzipped man pages 2025-05-25 11:48:28 +02:00
Johannes Altmanninger
b11e22d905 Fix uvar file mtime force-update (Rust port regression)
When two fish processes rewrite the uvar file concurrent, they rely on the
uvar file's mtime (queried after taking a lock, if locking is supported) to
tell us whether their view of the uvar file is still up-to-date.  If it is,
they proceed to move it into place atomically via rename().

Since the observable mtime only updates on every OS clock tick, we call
futimens() manually to force-update that, to make sure that -- unless both
fish conincide on the same *nanosecond* -- other fish will notice that the
file changed.

Unfortunately, commit 77aeb6a2a8 (Port execution, 2023-10-08) accidentally
made us call futimens() only if clock_gettime() failed, instead of when
it succeeded. This means that we need to wait for the next clock tick to
observe a change in mtime.
Any resulting false negatives might have caused us to drop universal variable updates.

Reported in https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2098948362

See #10300

(cherry picked from commit 8617964d4d)
2025-05-23 08:50:17 +02:00
Johannes Altmanninger
8617964d4d Fix uvar file mtime force-update (Rust port regression)
When two fish processes rewrite the uvar file concurrent, they rely on the
uvar file's mtime (queried after taking a lock, if locking is supported) to
tell us whether their view of the uvar file is still up-to-date.  If it is,
they proceed to move it into place atomically via rename().

Since the observable mtime only updates on every OS clock tick, we call
futimens() manually to force-update that, to make sure that -- unless both
fish conincide on the same *nanosecond* -- other fish will notice that the
file changed.

Unfortunately, commit 77aeb6a2a8 (Port execution, 2023-10-08) accidentally
made us call futimens() only if clock_gettime() failed, instead of when
it succeeded. This means that we need to wait for the next clock tick to
observe a change in mtime.
Any resulting false negatives might have caused us to drop universal variable updates.

Reported in https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2098948362

See #10300
2025-05-23 08:49:41 +02:00
wcbing
0d99859add completions/apt & apt-get: Let autoremove and autopurge take packages
- add complete for apt-get's autopurge
- continue #7095, add complete for apt/apt-get's autoremove and autopurge
2025-05-21 12:11:24 +08:00
nicole
0b8e0b8835 Add more completions to aptitude 2025-05-20 16:39:38 -03:00
Johannes Altmanninger
33f8415785 Fixup history file EINTR loop to actually loop
Fixes d84e68dd4f (Retry history file flock() on EINTR, 2025-05-20).

(cherry picked from commit 3867163193)
2025-05-20 17:19:12 +02:00
Johannes Altmanninger
3867163193 Fixup history file EINTR loop to actually loop
Fixes d84e68dd4f (Retry history file flock() on EINTR, 2025-05-20).
2025-05-20 17:17:12 +02:00
Johannes Altmanninger
5ccd155177 Retry history file flock() on EINTR
When locking the uvar file, we retry whenever flock() fails with EINTR
(e.g. due to ctrl-c).

But not when locking the history file.  This seems wrong; all other libc
functions in the "history_file" code path do retry.

Fix that. In future we should extract a function.

Note that there are other inconsistencies; flock_uvar_file() does not
shy away from remote file systems and does not respect ABANDONED_LOCKING.
This means that empirically probably neither are necessary; let's make things
consistent in future.

See https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2095096200
Might help #10300

(cherry picked from commit 4d84e68dd4)
2025-05-20 15:32:56 +02:00
Johannes Altmanninger
0f8d3a5174 Revert "Temporarily enable history_file debug category by default"
Commit f906a949cf (Temporarily enable history_file debug category by default,
2024-10-09) enabled the "history_file" debug category by default to gather
more data.

Judging from
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2876718382
the logs didn't help, or were at least not visible when logging to stderr
(due to reboot).

Let's disable "history_file" logs again to remove potential
noise if the file system is read-only, disk is full etc., see
https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2094781120

See #10300

(cherry picked from commit 285a810814)
2025-05-20 15:31:57 +02:00
Johannes Altmanninger
4d84e68dd4 Retry history file flock() on EINTR
When locking the uvar file, we retry whenever flock() fails with EINTR
(e.g. due to ctrl-c).

But not when locking the history file.  This seems wrong; all other libc
functions in the "history_file" code path do retry.

Fix that. In future we should extract a function.

Note that there are other inconsistencies; flock_uvar_file() does not
shy away from remote file systems and does not respect ABANDONED_LOCKING.
This means that empirically probably neither are necessary; let's make things
consistent in future.

See https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2095096200
Might help #10300
2025-05-20 15:31:33 +02:00
Johannes Altmanninger
285a810814 Revert "Temporarily enable history_file debug category by default"
Commit f906a949cf (Temporarily enable history_file debug category by default,
2024-10-09) enabled the "history_file" debug category by default to gather
more data.

Judging from
https://github.com/fish-shell/fish-shell/issues/10300#issuecomment-2876718382
the logs didn't help, or were at least not visible when logging to stderr
(due to reboot).

Let's disable "history_file" logs again to remove potential
noise if the file system is read-only, disk is full etc., see
https://github.com/fish-shell/fish-shell/pull/11492#discussion_r2094781120

See #10300
2025-05-20 15:31:33 +02:00
Johannes Altmanninger
541a069a91 CI: fix detection of path to llvm-symbolizer
clang --version here outputs "clang version 19.1.7"
but it looks like that changed on GHA's Ubuntu runner:

	++ clang --version
	++ awk 'NR==1 { split($NF, version, "."); print version[1] }'
	+ llvm_version='(1ubuntu1)'

which leads to

	  The CHECK on line 7 wants:
	    abbr -a -- cuckoo somevalue # imported from a universal variable, see `help abbr`

	  but there was no remaining output to match.

	  additional output on stderr:1:111:
	    =================================================================
	    ==4680==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7bc287a5d402 at pc 0x55e597fa96b6 bp 0x7ffd2bc00700 sp 0x7ffd2bbffea8
	    READ of size 18 at 0x7bc287a5d402 thread T0
	    ==4680==WARNING: invalid path to external symbolizer!
	    ==4680==WARNING: Failed to use and restart external symbolizer!

Fix that, assuming that "clang --version" always matches the latest symbolizer
that is installed.  While at it, leave a "set -x" (which should be the
default for CI), and install llvm explicitly.
2025-05-20 14:28:38 +02:00
Johannes Altmanninger
e8864ef441 Fix stack-use-after-scope
I missed this in 7c2c7f5874 (Use uninit instead of zeroed, 2025-05-19).
See #11515
2025-05-20 14:18:04 +02:00
Johannes Altmanninger
2f708a7c0b Fix unused import 2025-05-20 12:49:25 +02:00
Johannes Altmanninger
b7a73710e2 Merge pull request #11515 2025-05-20 12:49:04 +02:00
Johannes Altmanninger
7a54ed66fb Merge pull request #11514 2025-05-20 12:39:04 +02:00
Johannes Altmanninger
99f4c09ed3 Merge pull request #11513 2025-05-20 12:39:04 +02:00
Johannes Altmanninger
c4a26cb2b1 builtin status: remove spurious newline from current-command (Rust port regression)
WHen "status current-command" is called outside a function it always returns
"fish". An extra newline crept in, fix that.

Fixes 77aeb6a2a8 (Port execution, 2023-10-08).
Fixes #11503

(cherry picked from commit e26b585ce5)
2025-05-20 12:33:01 +02:00
Johannes Altmanninger
e26b585ce5 builtin status: remove spurious newline from current-command (Rust port regression)
WHen "status current-command" is called outside a function it always returns
"fish". An extra newline crept in, fix that.

Fixes 77aeb6a2a8 (Port execution, 2023-10-08).
Fixes #11503
2025-05-20 12:32:22 +02:00
王宇逸
7c2c7f5874 Use uninit instead of zeroed 2025-05-19 20:54:12 +08:00
Yuyi Wang
7b3a2900e9 Refactor *NullTerminatedArray
* Remove `strlen_safe` & `null_terminated_array_length` and use the provided method of `OwningNullTerminatedArray`.
* Remove unneeded traits and make `NullTerminatedArray` private.
2025-05-19 17:24:24 +08:00
Yuyi Wang
7a79366f91 Use CStr instead of strlen to improve readability 2025-05-19 16:47:09 +08:00
Yuyi Wang
223b98f2ff Fix build.rs to support cross-compiling to cygwin (#11512)
2719ae4 adds a special cfg for cygwin to avoid annoying warnings. As cygwin target is usually cross-compiled, cfg! is not enough to detect the correct target. This PR uses CARGO_CFG_TARGET_OS env var instead.
2025-05-19 10:27:04 +02:00
Yuyi Wang
01560bf195 Remove libc sem completely on non-linux (#11511)
As it's only used on Linux, we can cfg it out completely on other platforms. It also enables test_topic_monitor_torture on NetBSD & Cygwin.
2025-05-19 10:26:47 +02:00
Daniel Rainer
7fe34ea401 Move and rename messages template file
There is no reason to have this file clutter the repo root.
Move it into the `po` directory, and give it a more descriptive name.

Inspired by this discussion:
https://github.com/fish-shell/fish-shell/pull/11463#discussion_r2083453275

I use `template.po` instead of `message.po-template` to be more compatible with
automatic filetype detection. (e.g. vim/nvim detect the former as a po file, but
the latter as a conf file)
2025-05-18 21:31:00 -07:00
Johannes Altmanninger
7228cb15bf Include sys/statvfs.h for the definition of ST_LOCAL (Rust port regression)
See https://man.netbsd.org/statvfs.5.
According to https://github.com/NetBSD/src/blob/trunk/sys/sys/statvfs.h#L135,
NetBSD has "#define ST_LOCAL MNT_LOCAL".  So this commit likely makes no
difference on existing systems.

While at it
- comment include statements
- remove a code clone

See #11486

(cherry picked from commit d68f8bdd3b)
2025-05-16 08:21:56 +02:00
Alan Somers
d5b46d6535 Fix remote filesystem detection on FreeBSD
Need an extra include to get the definition of MNT_LOCAL

Fixes #11483

(cherry picked from commit 7f4998ad9b)
2025-05-16 08:21:25 +02:00
Johannes Altmanninger
36f035b52c Merge pull request #11501 2025-05-16 07:36:03 +02:00
Johannes Altmanninger
0e8edab872 Fix typo 2025-05-16 07:35:43 +02:00
Johannes Altmanninger
448d630d0c Merge pull request #11500 2025-05-16 07:35:34 +02:00
Johannes Altmanninger
38fb2cfd6d Merge pull request #11499 2025-05-16 07:32:45 +02:00
Johannes Altmanninger
d68f8bdd3b Include sys/statvfs.h for the definition of ST_LOCAL (Rust port regression)
See https://man.netbsd.org/statvfs.5.
According to https://github.com/NetBSD/src/blob/trunk/sys/sys/statvfs.h#L135,
NetBSD has "#define ST_LOCAL MNT_LOCAL".  So this commit likely makes no
difference on existing systems.

While at it
- comment include statements
- remove a code clone

See #11486
2025-05-16 07:31:26 +02:00
Johannes Altmanninger
80bafd5a22 Merge pull request #11486 2025-05-16 07:12:47 +02:00
Daniel Rainer
ae8c5eaab7 Fix rst formatting issues 2025-05-16 00:30:34 +02:00
Daniel Rainer
329d190fbf Update translation docs
This is done in accordance with the recent changes to our translation pipeline.
2025-05-15 22:35:05 +02:00
Daniel Rainer
e5fa047412 Mark format strings in po files
This allows msgfmt to detect issues with translations of format strings.
The detection used here is very simple. It just checks if a string contains '%',
and if it does, the entry in the po file is preceded by '#, c-format'.
Any entries with this marker are checked by msgfmt in our tests, so if an issue
arises, we will notice before it is merged.
2025-05-15 22:09:57 +02:00
Daniel Rainer
cb31887941 Do not hardcode xgettext output path
Instead output on stdout, which lets the caller decide what to do with it.
2025-05-13 21:18:39 +02:00
Johannes Altmanninger
d4b4d44f14 Fix Vi mode glitch when replacing at last character
Another regression from d51f669647 (Vi mode: avoid placing cursor beyond last
character, 2024-02-14) "Unfortunately Vi mode sometimes needs to temporarily
select past end". So do the replace_one mode bindings which were forgotten.

Fix this.

This surfaces a tricky problem: when we use something like

	bind '' self-insert some-command

When key event "x" matches this generic binding, we insert both "self-insert"
and "some-command" at the front of the queue, and do *not* consume "x",
since the binding is empty.

Since there is a command (that might call "exit"), we insert a check-exit
event too, after "self-insert some-command" but _before_ "x".

The check-exit event makes "self-insert" do nothing. I don't think there's a
good reason for this; self-insert can only be triggered by a key event that
maps to self-insert; so there must always be a real key available for it to
consume. A "commandline -f self-insert" is a nop. Skip check-exit here.

Fixes #11484

(cherry picked from commit 107e4d11de)
2025-05-13 00:31:22 +02:00
Johannes Altmanninger
b8cfd6d12b Fix typo causing wrong cursor position after Vi mode paste
Regressed in d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

(cherry picked from commit 50500ec5b9)
2025-05-13 00:31:09 +02:00
Johannes Altmanninger
04fd697ac9 CONTRIBUTING: update docs on how to create a new translation 2025-05-13 00:29:05 +02:00
Johannes Altmanninger
2558d13361 Merge pull request #11488 2025-05-13 00:21:49 +02:00
Daniel Rainer
02ccf25443 Prettify profiling for multi-line commands
The old version just prints the entire command being profiled as-is.
If such a command consists of more than one line, these lines do not have any
padding, and thus visually interfere with the timings.

This commit adds padding, such that all lines but the first one have padding
prepended, such that the original line content starts at the column in which the
first line starts.

This does not work perfectly for subcommands (in the profiling sense,
where the command starts with (regex) '-+>' instead of just '>').
In such cases, even if the command string is indented in the source, the command
will not start with whitespace. However, subsequent lines are not trimmed, so
the might be indented farther than they should be relative to the first line of
the command.
2025-05-13 00:11:33 +02:00
Johannes Altmanninger
a88acb9715 Merge pull request #11487 2025-05-13 00:01:11 +02:00
Johannes Altmanninger
8d3ad0c3c3 Merge pull request #11485 2025-05-13 00:01:11 +02:00
Johannes Altmanninger
660f52ee4f Merge pull request #11463 2025-05-13 00:01:11 +02:00
Johannes Altmanninger
594b8730d8 completions/git: fix regression causing wrong remote-branch completions
Fixes 54971621de (completions/git: show url as description for remote
completion, 2025-04-13).
Fixes #11482
2025-05-13 00:01:11 +02:00
Johannes Altmanninger
107e4d11de Fix Vi mode glitch when replacing at last character
Another regression from d51f669647 (Vi mode: avoid placing cursor beyond last
character, 2024-02-14) "Unfortunately Vi mode sometimes needs to temporarily
select past end". So do the replace_one mode bindings which were forgotten.

Fix this.

This surfaces a tricky problem: when we use something like

	bind '' self-insert some-command

When key event "x" matches this generic binding, we insert both "self-insert"
and "some-command" at the front of the queue, and do *not* consume "x",
since the binding is empty.

Since there is a command (that might call "exit"), we insert a check-exit
event too, after "self-insert some-command" but _before_ "x".

The check-exit event makes "self-insert" do nothing. I don't think there's a
good reason for this; self-insert can only be triggered by a key event that
maps to self-insert; so there must always be a real key available for it to
consume. A "commandline -f self-insert" is a nop. Skip check-exit here.

Fixes #11484
2025-05-13 00:01:11 +02:00
Johannes Altmanninger
50500ec5b9 Fix typo causing wrong cursor position after Vi mode paste
Regressed in d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).
2025-05-12 22:57:20 +02:00
Daniel Rainer
3ccce609f0 Add script for updating translations
The purpose of this script is to simplify the translation-related workflow for
both developers and translators. It runs the xgettext, msgmerge, msgfmt pipeline
(or only parts of it, depending on the arguments), either for all languages, or
for one specific one.

Developers can use the script with the `--no-mo` flag to update the PO files for
all languages after changes to the Rust/fish sources, to keep the translations
up to date. Ideally, this would run automatically for all changes, such that
translations are always up to date, but for now, it would already be an
improvement to run this script before releasing a new version of fish.

Translators can use the script in the same way as developers, to get up to date
PO files. To see their translations in action, the script can be called with
`--only-mo`, which takes the current version of the PO files and generates MO
files from them, which get placed in a location which fish (built with `cargo
build`) can detect.
Translators might also find it useful to specify the language they want to work
on as a non-option argument. This argument should be the path to the po file
they want to work on. Specifying non-existing files to work on a new language is
allowed, but the files must be in the po directory and follow the naming
convention.
2025-05-12 22:49:30 +02:00
Johannes Altmanninger
6fb22a4fd1 Fix regression causing crash indenting commandline with "$()"
Commit b00899179f (Don't indent multi-line quoted strings; do indent inside
(), 2024-04-28) changed how we compute indents for string tokens with command
substitutions:

	echo "begin
	not indented
	end $(
	begin
	    indented
	end)"(
	begin
	    indented
	end
	)

For the leading quoted part of the string, we compute indentation only for
the first character (the opening quote), see 4c43819d32 (Fix crash indenting
quoted suffix after command substitution, 2024-09-28).

The command substitutions, we do indent as usual.

To implement the above, we need to separate quoted from non-quoted
parts. This logic crashes when indent_string_part() is wrongly passed
is_double_quoted=true.

This is because, given the string "$()"$(), parse_util_locate_cmdsub calls
quote_end() at index 4 (the second quote). This is wrong because that function
should only be called at opening quotes; this is a closing quote. The opening
quote is virtual here. Hack around this.

Fixes #11444

(cherry picked from commit 48704dc612)
2025-05-12 21:41:10 +02:00
Johannes Altmanninger
35849c57dc Explicit type for "$()" hack in parse_util_locate_cmdsub
(cherry picked from commit 8abab0e2cc)
2025-05-12 21:41:10 +02:00
Johannes Altmanninger
27504658ce Remove code clone in parse_util_locate_cmdsub
(cherry picked from commit bd178c8ba8)
2025-05-12 21:41:10 +02:00
Johannes Altmanninger
db323348c7 Set transient command line in custom completions (Rust port regression)
Commit df3b0bd89f (Fix commandline state for custom completions with variable
overrides, 2022-01-26) made us push a transient command line for custom
completions based on a tautological null-pointer check ("var_assignments").

Commit 77aeb6a2a8 (Port execution, 2023-10-08) turned the null pointer into
a reference and replaced the check with "!ad.var_assignments.is_empty()".
This broke scenarios that relied on the transient commandline.  In particular
the attached test cases rely on the transient commandline implicitly placing
the cursor at the end, irrespective of the cursor in the actual commandline.

I'm not sure if there is an easy way to identify these scenarios.

Let's restore historical behavior by always pushing the transient command line.

Fixes #11423

(cherry picked from commit 97641c7bf6)
2025-05-12 21:39:42 +02:00
Johannes Altmanninger
edb1b5f333 Share alt-{b,f} with Vi mode, to work around Terminal.app/Ghostty more
Commit f4503af037 (Make alt-{b,f} move in directory history if commandline is
empty, 2025-01-06) had the intentional side effect of making alt-{left,right}
(move in directory history) work in Terminal.app and Ghostty without other,
less reliable workarounds.
That commit says "that [workaround] alone should not be the reason for
this change."; maybe this was wrong.

Extend the workaround to Vi mode.  The intention here is to provide
alt-{left,right} in Vi mode.  This also adds alt-{b,f} which is odd but
mostly harmless (?) because those don't do anything else in Vi mode.
It might be confusing when studying "bind" output but that one already has
almost 400 lines for Vi mode.

Closes #11479

(cherry picked from commit 3081d0157b)
2025-05-12 21:35:47 +02:00
Daniel Rainer
2d8d377ddc Make printf unicode-aware
Specifically, the width and precision format specifiers are interpreted as
referring to the width of the grapheme clusters rather than the byte count of
the string. Note that grapheme clusters can differ in width.

If a precision is specified for a string, meaning its "maximum number of
characters", we consider this to limit the width displayed.
If there is a grapheme cluster whose width is greater than 1,
it might not be possible to get precisely the desired width.
In such cases, this last grapheme cluster is excluded from the output.

Note that the definitions used here are not consistent with the `string length`
builtin at the moment, but this has already been the case.

(cherry picked from commit 09eae92888)
2025-05-12 21:33:40 +02:00
Alan Somers
bd26d4b61b Fix use of deprecated symbols in Nix 2025-05-12 13:28:56 -06:00
Alan Somers
7f4998ad9b Fix remote filesystem detection on FreeBSD
Need an extra include to get the definition of MNT_LOCAL

Fixes #11483
2025-05-12 13:18:21 -06:00
Daniel Rainer
122f39de66 Replace loop by pipeline
This simplifies the logic a bit and performs a better.

Performance improvements for extract_fish_script_messages (time in
microseconds):
- explicit regex: from 128241 to 83471 (speedup 1.5)
- implicit regex: from 682203 to 463635 (speedup 1.5)
2025-05-12 20:54:32 +02:00
Daniel Rainer
1df8fbff67 Replace long list by file
The replaces the `strs` list by a corresponding file, which eliminates the need
for looping over the list.

Use sed to transform strings into gettext po format entries.

Format the file with fish_indent and use more expressive variable name for the
file cargo expand writes to.

Performance improvements (in microseconds):
- sort+format rust strings: from 21750 to 11096 (speedup 2.0)
2025-05-12 20:35:41 +02:00
Daniel Rainer
ff5ff50183 Speed up constant string extraction
The fish builtin string functions are significantly slower than grep + sed.
The final replacement of \' to ' also does not make any sense here, because
single quotes appear unescaped in Rust strings.

Performance improvement: from 404880 to 44843 (speedup 9.0)

Profiling details (from separate runs):
Time (μs)   Sum (μs)  Command
       174     404880 > set -a strs (string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile |
             string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'")
    404706     404706 -> string match -rv 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile |
             string match -rg 'const [A-Z_]*: &str = "(.*)"' | string replace -a "\'" "'"

       202      44843 > set -a strs (grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile |
             grep -E 'const [A-Z_]*: &str = "(.*)"' |
             sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g")
      4952      44641 -> grep -Ev 'BUILD_VERSION:|PACKAGE_NAME' <$tmpfile |
             grep -E 'const [A-Z_]*: &str = "(.*)"' |
             sed -E -e 's/^.*const [A-Z_]*: &str = "(.*)".*$/\1/' -e "s_\\\'_'_g"
     28716      28716 --> command grep --color=auto $argv
     10973      10973 --> command grep --color=auto $argv
2025-05-12 20:11:05 +02:00
Daniel Rainer
c0d93e4740 Do not use huge fish list
Using a file is significantly faster.

Profiling overview (times in microseconds):
- cargo expand: from 4959320 to 4503409 (speedup 1.1)
- gettext call pipeline: from 436996 to 13536 (speedup 32.3)
- static string pipeline: from 477429 to 404880 (speedup 1.18)
2025-05-12 18:12:37 +02:00
Lucas Melo
3cbb5e384b Shorten and format completions for protontricks, protontricks-launch 2025-05-12 08:36:07 -03:00
Lucas Melo
90b35335ee Add completions for protontricks 2025-05-12 08:24:26 -03:00
Daniel Rainer
55752729d6 Fix escaping in translation 2025-05-12 00:51:07 +02:00
Johannes Altmanninger
41dfb5147f Fix typo in set_color test 2025-05-11 22:55:48 +02:00
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
3081d0157b Share alt-{b,f} with Vi mode, to work around Terminal.app/Ghostty more
Commit f4503af037 (Make alt-{b,f} move in directory history if commandline is
empty, 2025-01-06) had the intentional side effect of making alt-{left,right}
(move in directory history) work in Terminal.app and Ghostty without other,
less reliable workarounds.
That commit says "that [workaround] alone should not be the reason for
this change."; maybe this was wrong.

Extend the workaround to Vi mode.  The intention here is to provide
alt-{left,right} in Vi mode.  This also adds alt-{b,f} which is odd but
mostly harmless (?) because those don't do anything else in Vi mode.
It might be confusing when studying "bind" output but that one already has
almost 400 lines for Vi mode.

Closes #11479
2025-05-11 22:05:00 +02:00
Johannes Altmanninger
13e4736113 completions/commandline: don't offer deprecated option 2025-05-11 22:00:43 +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
Daniel Rainer
a86a4dfabf Remove source locations from translations
Source locations (file name and line number) where a string originates is not
required by gettext tooling. It can help translators to identify context,
but the value of this is reduced by our lack of context support, meaning that
all occurrences of a string will receive the same translation.
Translators can use `rg` or similar tools to find the source locations.
For further details see this thread:
https://github.com/fish-shell/fish-shell/pull/11463#discussion_r2079378627

The main advantage is that updates to the PO files are now only necessary when
the source strings change, which greatly reduces the diff noise.

A secondary benefit is that the string extraction logic is simplified.
We can now directly extract the strings from fish scripts,
and several issues are fixed alongside, mostly related to quoting.
The regex for extracting implicit messages from fish scripts has been tweaked to
ignore commented-out lines, and properly support lines starting with `and`/`or`.
2025-05-11 21:10:03 +02:00
Daniel Rainer
22bc8e12c9 Fix xgettext implicit regex
The old regex has the problem that it does not handle lines containing any
non-space characters in front of ` complete` (or ` function`), which results in
`string replace` leaving this part in the resulting string.
For example,
`and complete -d "foo"`
would turn into
`andN_ foo`
if passed to
`string replace --regex $regex 'N_ $1'` (where `$regex` is the `$implicit_regex`) variable.
Another issue are commented-out lines.
2025-05-11 21:10:03 +02:00
Peter Ammon
6c23c6f29b Add myself as SECURITY contact and reformat 2025-05-11 11:48:03 -07:00
Josef Andersson
39fd959eea Add initial security policy
Signed-off-by: Josef Andersson <janderssonse@proton.me>
2025-05-11 11:45:15 -07: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
Johannes Altmanninger
83f74f9332 builtin commandline: fix "-x" spuriously including redirection targets
completions frequently use

	argparse ... -- (commandline -xpc)

The "commandline -xpc" output
contains only string tokens.

A syntactically-valid process ("-p") consistes of only string tokens
and redirection tokens.  We skip all non-string tokens, but we do include
redirection targets, which are always strings.  This is weird, and confuses
completion scripts such as the one above.  Leave out redirection targets too.

Part of #11084
2025-05-11 12:46:08 +02:00
Johannes Altmanninger
58af4fa34c builtin commandline: rename tokenization mode 2025-05-11 12:46:08 +02:00
Daniel Rainer
f23501dbdc Add locale directory to config log 2025-05-11 09:27:35 +02:00
DaiLu Cao
035cd369c2 Supplement Chinese translation
Squashed commit of the following:

commit 23163d40bed2d97c72050990cf15db3944ce2ff0
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Thu Apr 24 10:11:04 2025 +0800

    Manually review up to line 1055 and modify all Chinese colons ':' to English ':' to prevent potential unknown errors.

commit dca5fb8182b94bffab5034dc5626b2b98d026b6f
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Thu Apr 17 10:50:13 2025 +0800

    Manually proofread up to 340 lines

commit 4b2d91c1138f3c8dec15b68aeb0510f02e15a776
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Thu Apr 17 09:50:21 2025 +0800

    use msgfmt check and fix all error

commit e2470d81c01ab7bf46d3d6ffd0291a05d4b38e13
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Wed Apr 16 11:10:54 2025 +0800

    Fix translation error converting '\\n' to '\\ n' error

commit 7ff970d06ce950aee35e1fb0ec70338f7bd42c1d
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Wed Apr 16 10:53:38 2025 +0800

    Fix make error, local cargo test completed

commit 018dfa225530a85486903ef58d47f4c358956b0b
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Fri Apr 11 16:46:36 2025 +0800

    modification of make errors

commit cbebd506a500aecc0669dce7f08422fcfed5615f
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Fri Apr 11 15:45:01 2025 +0800

    The second modification of make errors are all symbol problems

commit f75c3f7a2a84ffaea4eb642532b5a24da1c9154f
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Fri Apr 11 15:27:01 2025 +0800

    Re-add Chinese translation, try to solve the problem of make failing

commit 58551be20d261e3466a9e4ede290675f633e94a3
Author: DaiLu Cao <caodailu@foxmail.com>
Date:   Fri Apr 11 15:06:01 2025 +0800

    Supplement Chinese translation
2025-05-08 19:17:46 -07:00
Peter Ammon
057dd930b4 Changelog fix for #11354 2025-05-08 18:42:57 -07:00
Cuichen Li
25b944e3e6 Revert "Work around $PATH issues under WSL (#10506)"
This reverts commit 3374692b91.
2025-05-08 18:41:02 -07:00
Cuichen Li
3bef4863cf Revert "Work around $PATH issues under WSL (#10506)"
This reverts commit 3374692b91.
2025-05-08 18:35:56 -07:00
Daniel Rainer
2d58cfe4cb Remove line numbers from translation strings
This greatly reduces the number of changes necessary to the PO files when the
Rust/fish source files are updated. (Changes to the line number can be applied
automatically, but this adds a lot of noise to the git history.)

Due to the way we have been extracting Rust strings, differentiation between
the same source string in different contexts has not been possible regardless
of the change.

It seems that duplicate msgid entries are not permitted in PO files, so since we
do not use context to distinguish the strings we extract, there is no way to
have context-/location-dependent translations, so we might as well reduce the
git noise by eliminating line numbers.

Including source locations helps translators with understanding context.
Because we do not distinguish between contexts for a given source string,
this is of limited utility, but keeping file names at least allows to open the
relevant files and search them for the string. This might also be helpful to
identify translations which do not make sense in all context in which they are
used. (Although without adding context support, the only remedy would be to
remove the translation altogether, as far as I can tell.)

For extraction from Rust, additional issues are fixed:
- File name extraction from the grep results now works properly. Previously,
  lines not starting with whitespace resulted in missing or corrupted matches.
  (missing if the source line contains no colon followed by a whitespace,
  corrupted if it does, then the match included the part of the line in front of
  the colon, instead of just the location)
- Only a single source location per string was supported (`head -n1`). The new
  approach using sed does not have this limitation.
2025-05-08 18:15:56 +02:00
David Adam
df591a2e0f fish.spec/Debian packaging: drop man dependency in favour of groff 2025-05-08 22:16:33 +08:00
Johannes Altmanninger
ecefce2ea8 Fix "help printf" on --features=embed-data builds 2025-05-08 11:11:15 +02:00
Peter Ammon
786239d280 Changelog fix for #11465 2025-05-07 18:28:25 -07:00
Carl Andersson
7a668fb17e Unset SYSTEMD_COLORS for systemd completion
Fixes an issue where systemctl and other systemd commands completions are prefixed by ANSI color escape codes
2025-05-07 18:23:51 -07:00
Johannes Altmanninger
bf2f7ee6c0 Respect feature flags in fish_key_reader, fix display of "?" key
Commit daa692a20b (Remove unnecessary escaping for # and ~ inside key name
tokens, 2025-04-01) stopped escaping ? in fish_key_reader output.  This is
generally correct but not if the "qmark-noglob" feature flag is turned off.
Add that back, to be safe.

While at it, pass an environment variable more explicitly in a test.
2025-05-07 17:19:51 +02:00
Johannes Altmanninger
2f762e2da1 completions/cargo: re-use __fish_cargo
Technically this is in the autogenerated part, but I'm not sure how I can
re-generate it with today's cargo.
2025-05-07 17:17:09 +02:00
Benjamin VERGNAUD
11d8b83838 completions/cargo: enforce color off
Signed-off-by: Benjamin VERGNAUD <ben@bvergnaud.fr>
2025-05-06 15:39:39 +02:00
Yuyi Wang
c2eaef7273 Update nix to 0.30.1 (#11458)
After nix updated to 0.30, all functions related to file descriptor accepts impl AsFd, e.g., BorrowedFd. This PR is a minimal update. It tries to use impl AsFd as long as possible, but uses BorrowedFd in some places. Yes it introduces unsafe, but doesn't introduce new unsafe code.
2025-05-06 10:52:54 +02:00
Yuyi Wang
2f278f4bfa Update errno to 0.3.11 2025-05-06 10:44:18 +08: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
Peter Ammon
c993fd022c Rework fish AST implementation
This merges a large set of changes to the fish AST, with the intention of
making the code simpler.

There's no expected user-visible changes here, except for some minor
changes in the output of `fish_indent --dump-parse-tree`.

Ast parsing is about 50% faster measured via
`cargo +nightly bench  --features=benchmark bench_ast_construction`
and also uses less memory due to some size optimization.

The biggest change is removing the `Type` notion from `Node`. Previously
each Node had an integer type identified with it, like Type::Argument. This
was a relic from C++: types were natural in C++ and we could use LLVM-style
RTTI to identify Nodes, leveraging the fact that C++ has inheritance and so
Type could be at the same location in each Node.

This proved quite awkward in Rust which does not have inheritance. So
instead we switch to a new notion, Kind:

    pub enum Kind<'a> {
        Redirection(&'a Redirection),
        Token(&'a dyn Token),
        Keyword(&'a dyn Keyword),
        VariableAssignment(&'a VariableAssignment),
                ...

and a `&dyn Node` can now return its Kind. Basically leveraging Rust's enum
types.

Interesting lesson about the optimal way to construct ASTs in both
languages.
2025-05-04 19:45:36 -07:00
Peter Ammon
fe10f65587 ast: Box redirections in ArgumentOrRedirection
Redirections are bigger and less common.

Reduces ast size of __fish_complete_gpg.fish by ~28 KB.
2025-05-04 19:38:08 -07:00
Peter Ammon
b98c5ee897 ast: remove NodeSubTraits
This can be implemented directly in Node.
2025-05-04 19:37:25 -07:00
Peter Ammon
9ccff5ad5d ast: Clean up implement_acceptor_for_branch macro
We no longer need the field types to be passed to the macro.
2025-05-04 18:59:13 -07:00
Peter Ammon
55f70cbb6d ast: Clean up more macros
Factor some logic out of macros into a trait, to reduce the macro
complexity.
2025-05-04 18:59:13 -07:00
Peter Ammon
b7005e8378 ast: clean up NodeVisitorMut
This eliminates a bunch of the different functions from NodeVisitorMut.

It also removes the runtime polymorphism - now it's a generic instead of
using &dyn. The reason is that there's only one implementation of
NodeVisitorMut so there's no size savings from polymorphism.
2025-05-04 18:59:13 -07:00
Peter Ammon
1f79d48a48 ast: further macro cleanup 2025-05-04 18:59:13 -07:00
Peter Ammon
e9036774cb ast: simplify visitor_accept_field macro
This is a relic from when we used to support visiting in reverse order; we can
simplify this.
2025-05-04 18:59:13 -07:00
Peter Ammon
2cd185a4f1 ast: Eliminate ConcreteNode trait
Fold this into Node
2025-05-04 18:59:13 -07:00
Peter Ammon
bb92d82c3b ast: remove types 2025-05-04 18:59:13 -07:00
Peter Ammon
f9ba834788 ast: further migration from type to kind 2025-05-04 18:59:13 -07:00
Peter Ammon
d23b8af60d ast: More migration from type to kind 2025-05-04 18:59:13 -07:00
Peter Ammon
82eacb6d50 ast: Switch from type to kind in is_same_node 2025-05-04 18:59:13 -07:00
Peter Ammon
c62b09d5d1 ast: Switch from some types to kinds
Preparing to remove types entirely
2025-05-04 18:59:13 -07:00
Peter Ammon
ccfe949514 ast: make Ast generic
We can parse two different things via Ast:

1. A regular job list
2. A freestanding argument list, as used in `complete --arguments ...`

This second case is specific to one use.

Prior to this commit, we parsed the Ast and then "forgot" what we parsed,
storing a &dyn Node. Then we had to cast it to the right type, and assert,
and etc.

Make Ast generic over the Node type it parsed, and default the Node type to
JobList. This simplifies call sites.
2025-05-04 18:59:13 -07:00
Peter Ammon
ccc75d08f3 ast: remove all of the as_foo functions from Node
Kind has subsumed these.
2025-05-04 18:59:05 -07:00
Peter Ammon
dfac66082a ast: adopt Kind in yet more places 2025-05-04 18:59:05 -07:00
Peter Ammon
9ae01ae00d ast: adopt Kind in more places 2025-05-04 18:59:05 -07:00
Peter Ammon
51784b090d ast: adopt Kind in parse_util_detect_errors_in_ast 2025-05-04 18:59:05 -07:00
Peter Ammon
8115982485 ast: adopt Kind in highlighting 2025-05-04 18:59:05 -07:00
Peter Ammon
d88a656e9e ast: further adoption of Kind 2025-05-04 18:59:05 -07:00
Peter Ammon
d6ee4ec698 ast: Clean up BlockStatementHeader
Make this a real Node.
2025-05-04 18:59:05 -07:00
Peter Ammon
dbae271fe7 ast: remove StatementVariant
Statement is the new StatementVariant.
2025-05-04 18:59:05 -07:00
Peter Ammon
a4ec30f298 ast: Remove StatementVariant::None
We can do without this.
2025-05-04 18:59:05 -07:00
Peter Ammon
ee9cf33689 ast: Remove Node::category
This is now unused.
2025-05-04 18:59:05 -07:00
Peter Ammon
11b6bf31c0 ast: Minor cleanup of source ranges 2025-05-04 18:59:05 -07:00
Peter Ammon
4f0e11383e ast: Remove as_mut_foo() functions
Kinds have replaced these.
2025-05-04 18:59:05 -07:00
Peter Ammon
bf78309f79 ast: adopt Kinds in more places 2025-05-04 18:59:05 -07:00
Peter Ammon
01bd854f25 ast: introduce Kind and cast
This begins the process of replacing the underlying Node "type" notion with
Kind. A Kind is an Enum of all of the possible node types, except with
Token and Keyword collapsed into one.

The idea is, rather than this:

    if node.type() == Type::Argument {
	    let arg = node.as_argument().unwrap();
		...
	}

we can instead do this:

    if let Kind::Argument(arg) = node.kind() {
	    // we already have arg
	}

There is also a cast() function:

    let arg: Option<Argument> = node.cast()

which may be convenient in some places.

The big thing we lose is the ability to talk about a Node's type without
actually having a Node. But this turns out to not be an issue in practice.

Future commits will begin adopting Kind.
2025-05-04 18:59:05 -07:00
Peter Ammon
0348389195 ast: Remove as_mut_leaf
This was unused.
2025-05-04 18:28:25 -07:00
Peter Ammon
e05ecd6c7d ast: clean up lists
Make working with lists more natural
2025-05-04 18:28:25 -07:00
Peter Ammon
325232bec1 ast: remove the ability to traverse in reverse
Prior to this commit, each Node in the ast could accept a visitor and visit
children either in order or in reverse order. This reverse feature added a lot
of complexity and the only client is Traversal.

Switch Traversal to reverse the nodes itself and remove the reverse bool
elsewhere, leading to some code simplifications.
2025-05-04 17:09:00 -07:00
Peter Ammon
b78d168050 ast: eliminate ArgumentOrRedirectionVariant
Just use ArgumentOrRedirection directly. Continued simplification.
2025-05-04 17:09:00 -07:00
Peter Ammon
31edcf029b ast: factor out as_node
Shrink another macro.
2025-05-04 17:09:00 -07:00
Peter Ammon
27dc4b3c8a ast: Blanket implementation of NodeMut
Continue to shrink the implement_node! macro.

No functional changes expected.
2025-05-04 17:09:00 -07:00
Peter Ammon
77a4f38a13 ast: derive Category from Type
In the fish AST, each node falls into one of three "categories":

    1. A branch: contains child nodes
    2. A leaf: no child nodes, contains a source range
    3. A list: a sequence of child nodes and nothing more

Prior to this commit the category was explicit in the code for each Node type;
make it instead derived from the node's type. This continues to shrink our
macros.

No functional change expected.
2025-05-04 17:09:00 -07:00
Peter Ammon
e9d396615b ast: push try_source_range into default Node implementation
Minor refactoring, reducing macro size.
2025-05-04 17:09:00 -07:00
Peter Ammon
79ec558d08 ast: remove Default implementation
This doesn't make much conceptual sense, and isn't required.

Do some other miscellaneous cleanup.
2025-05-04 17:09:00 -07:00
Peter Ammon
719a5d2909 ast: remove stale parent pointer comment
It no longer applies.
2025-05-04 17:08:59 -07:00
Peter Ammon
93962c82df ast: store &dyn Node and not &dyn NodeMut
Minor simplifications.
2025-05-04 17:08:59 -07:00
Johannes Altmanninger
111922b60f Fix export test on macOS GHA runner
This system sets something like
$MANPATH: originally inherited as |/Applications/Xcode_15.4.app/...|
2025-05-04 18:19:42 +02:00
Johannes Altmanninger
cb92a5530f functions/export: fix for path variables
Commit f38646593c (Allow `export` to set colon-separated `PATH`, `CDPATH`
and `MANPATH`., 2017-02-10)
did something very weird for «export PATH=foo».
It essentially does

	set -gx PATH (string replace -- "$PATH" (string join ":" -- $PATH) foo)

which makes no sense.  It should set PATH to "foo", no need to involve the
existing value of $PATH.

Additionally, the string split / string join dance is unnecessary.  Nowadays,
builtin set already handles path variables as is needed here, so get rid of
this special case.

Fixes #11434
2025-05-04 18:06:18 +02:00
Johannes Altmanninger
dd4c04e2ff Fix empty soft-wrapped line not being removed before execution
Commit 7acc2b7 added an empty line to our screen representation if we are
wrapped. This regressed the fix for #6826.  In the attached test case, there is
a spurious empty line after the first one.  Adjust the fix to remove it again.

Patch-by: kerty <g.kabakov@inbox.ru>
https://github.com/fish-shell/fish-shell/pull/11153#issuecomment-2800087389
2025-05-04 12:50:12 +02:00
Johannes Altmanninger
6fec5ab320 completions/wpctl: fix when "settings" subcommand is not available
The error is printed to stdout, see
https://github.com/fish-shell/fish-shell/pull/11438#discussion_r2072455009
2025-05-04 12:06:01 +02:00
Johannes Altmanninger
ada9aff63e Merge pull request #11453 2025-05-04 12:01:06 +02:00
Johannes Altmanninger
1d63c1f188 Merge pull request #11399 2025-05-04 11:58:05 +02:00
Johannes Altmanninger
a12298152f Merge pull request #11448 2025-05-04 11:57:18 +02: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
239
9f80e1f225 completions/keybase: update to 6.4.0
Closes #11428
2025-05-04 11:56:14 +02:00
fabiojb
9a8d578142 completion(winetricks): redirect winetricks list-all sderr to /dev/null 2025-05-03 18:25:17 -03:00
Daniel Rainer
09eae92888 Make printf unicode-aware
Specifically, the width and precision format specifiers are interpreted as
referring to the width of the grapheme clusters rather than the byte count of
the string. Note that grapheme clusters can differ in width.

If a precision is specified for a string, meaning its "maximum number of
characters", we consider this to limit the width displayed.
If there is a grapheme cluster whose width is greater than 1,
it might not be possible to get precisely the desired width.
In such cases, this last grapheme cluster is excluded from the output.

Note that the definitions used here are not consistent with the `string length`
builtin at the moment, but this has already been the case.
2025-05-03 22:53:27 +02:00
Daniel Rainer
af6c3eb69f Ensure that strings do not get wrapped in po files 2025-05-03 16:07:20 +02:00
Daniel Rainer
dd5864ce13 Add quotes around gettext string
This should prevent occurrences of the search string from being found in other
locations (e.g. in a comment).

The whole approach of string extraction from Rust sources is sketchy,
but this at least prevents producing garbage when the content of a string
appears somewhere else unquoted.
2025-05-03 16:07:20 +02:00
Daniel Rainer
d31dc9ffd8 Fix fish script translation file generation
The previous version generates files which do not preserve the line number from
the original fish script file, resulting in translation not working.

The new approach is quite ugly, and might have some issues,
but at least it seems to work in some cases.
2025-05-03 16:07:03 +02:00
Daniel Rainer
d5e80d43d9 Extract function for gettext extraction
Extracting explicit and implicit messages works essentially the same way, which
is also reflected in the code being identical, except for the regex.

Extract the duplicated code into a function.
2025-05-03 16:03:03 +02:00
Johannes Altmanninger
0d59e89374 completions/wpctl: silence stderr
In case the command is missing, I guess
See https://github.com/fish-shell/fish-shell/pull/11438
2025-05-03 14:15:33 +02:00
Johannes Altmanninger
8b1f72c54b completions/tmutil: namespace 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
54a5ade57d Merge pull request #11394 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
7c25d6a1ba Merge pull request #11443 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
a5a5dc46e4 Merge pull request #11438 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
1687b3fe7a Merge pull request #11377 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
f3ddf793a3 Merge pull request #11381 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
647ae7da8c Merge pull request #11411 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
0950cd1598 Merge pull request #11422 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
a1b1bff97b Merge pull request #11441 2025-05-03 14:15:33 +02:00
Johannes Altmanninger
a95be351fb Merge pull request #11447 2025-05-03 14:15:33 +02:00
Axlefublr
91b9bbf651 fix single backticks 2025-05-03 19:26:07 +08:00
Johannes Altmanninger
c14e8c1939 Fix assertion error in set_color
This doesn't hold for e.g. TERM=linux-m fish -c 'set_color red'
2025-05-03 12:56:45 +02:00
Daniel Rainer
7e4c3b9fa7 Use workspace config in packages
- Apply lint config to entire workspace

- Inherit workspace config for fish-printf

- Allow stdlib printing in fish-printf tests

The current problem which is addressed by this is that warnings about C-String
literals are generated by clippy for code in fish-printf. These literals are not
available with the current MSRV 1.70, but previously the MSRV setting was not
inherited by fish-printf, causing the warning to appear.
2025-05-02 22:31:39 +02: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
Fabian Boehm
8a5a547d88 builtins/commandline: Correct error message 2025-05-02 20:54:29 +02:00
Johannes Altmanninger
48704dc612 Fix regression causing crash indenting commandline with "$()"
Commit b00899179f (Don't indent multi-line quoted strings; do indent inside
(), 2024-04-28) changed how we compute indents for string tokens with command
substitutions:

	echo "begin
	not indented
	end $(
	begin
	    indented
	end)"(
	begin
	    indented
	end
	)

For the leading quoted part of the string, we compute indentation only for
the first character (the opening quote), see 4c43819d32 (Fix crash indenting
quoted suffix after command substitution, 2024-09-28).

The command substitutions, we do indent as usual.

To implement the above, we need to separate quoted from non-quoted
parts. This logic crashes when indent_string_part() is wrongly passed
is_double_quoted=true.

This is because, given the string "$()"$(), parse_util_locate_cmdsub calls
quote_end() at index 4 (the second quote). This is wrong because that function
should only be called at opening quotes; this is a closing quote. The opening
quote is virtual here. Hack around this.

Fixes #11444
2025-05-02 08:31:15 +02:00
Johannes Altmanninger
8abab0e2cc Explicit type for "$()" hack in parse_util_locate_cmdsub 2025-05-02 08:31:15 +02:00
Johannes Altmanninger
bd178c8ba8 Remove code clone in parse_util_locate_cmdsub 2025-05-02 08:31:15 +02:00
Johannes Altmanninger
cb719cd418 Remove dead code
Introduced in 149594f974 (Initial revision, 2005-09-20).
2025-05-02 08:31:15 +02:00
Johannes Altmanninger
1ff8f983c4 Remove obsolete Vi mode delete key workaround
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$n20_uqiMqatEQcPG79Ca0c2_YvHBHTr-yCVXTEuze_Y

commit f5fac096c0 (Don't move cursor in delete-char, 2017-04-19) fixed the
behavior of Vi mode keys "delete" and "x" when the cursor is at the end of
the buffer, and commit d51f669647 (Vi mode: avoid placing cursor beyond
last character, 2024-02-14) generalized this fix.

This means that the delete-specific fix is no longer necessary. Remove it.

Note that if the cursor is at end of a line but not the last line, the
behavior of "delete" in Vi mode is still wrong.  It should stay on the line.
2025-05-02 06:05:31 +02:00
Johannes Altmanninger
e3517f69b3 Simplify check for bare builtin invocation 2025-05-02 06:05:31 +02:00
Fabian Boehm
f7bde1354d Only count it as a naked invocation at the end of the "file"
This is a weird confusion between the "end" and "terminate" token
types.

"end" is the end of the "line" - a newline or ";".

"terminate" is the end of the "file" - like pressing newline
interactively or having the file end.

So this would count things like `if` and `switch` as a "help"
invocation even if followed by a newline, e.g.

```fish
if; echo foo
```

and

```fish
switch
case foo
```

The result of that was that a naked "if" in a script file isn't an
error, but doesn't start a block either, so if you complete the block
it would count the "end" as superfluous, which sends you on a bit of a
hunt to figure out where the block start is missing.
2025-05-01 14:57:30 +02:00
Axlefublr
1d69226c58 preciser wording for builtin crossmode alt+p binding 2025-05-01 13:58:18 +08:00
Daniel Rainer
d5e71bc46e Fix diff_profiles.fish
This script was broken by the changes to profiling output in
9d904e1113.

The new version works with both the old and new profiling output, even when
mixed. The script output has been adjusted to match the new profiling style
better.

This also adds basic error handling for situations where the script is invoked
incorrectly and makes the file executable.
2025-04-30 19:41:45 +02:00
fabiojb
0d5ab2514c wpctl: add description for settings command options 2025-04-30 11:18:12 -03:00
David Adam
bf0a30b9a8 CHANGELOG: work on 4.1 2025-04-30 14:15:58 +08:00
fabiojb
b54042e512 wpctl: add completion for settings option 2025-04-29 17:11:01 -03:00
Johannes Altmanninger
f79e5d5820 Remove a special case parsing the fish_color_normal fallback
The first two attempts skip over empty variables and the last one doesn't.
This is fine but since we need the default case anyway, might as well reuse
it here too.  (An empty color variable is treated the same way a missing
color variable is.)
2025-04-29 13:59:27 +02:00
Johannes Altmanninger
54e80e65a8 Be more careful to only pass actual keys to self-insert
I don't have a runnable test case but this does seem to have bitrotted.
Originally, we only cared about keys and the EOF and check-exit events.
Returning one of the other new events here seems totally wrong.

Try to fix this, and move the logic closer to where it's needed, so we no
longer need to update its name and we're less likely to forget to update it,
and it cannot.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
1122bba3c1 Fix typo in docs 2025-04-29 13:51:18 +02:00
Johannes Altmanninger
094e8b29c2 Cleanup some import statements 2025-04-29 13:51:18 +02:00
Johannes Altmanninger
decec955d2 Fix DCS parser spuriously stopping at escape byte
DCS commands stop at ST ("\e\\"). Make sure we don't stop at just "\e". I
don't know of any command that will actually include the escape byte in its
payload but better safe than sorry.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
4a5e8a8f48 Handle boolean capabilities in XTGETTCAP response parser 2025-04-29 13:51:18 +02:00
Johannes Altmanninger
f8699d2b7e Move mouse click handling from input decoding to the input queue consumer
The input queue doesn't want to be blocked, so let's decide later what to
do with a mouse click.  This fixes the potential problem where a mouse click
is ignored if it is received while we're waiting for the terminal to repond
to a query.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
168c1a50a4 Don't route query responses until we pop them from the input queue
This makes more sense, see also the next commit.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
7e393f47e4 Prevent code execution from focus events while blocked on query response
While we are waiting for a query response from the terminal, we defer any
input processing until we receive our query response
 Then that response is promoted to the front of the input queue, and
remaining inputs are processed in order.

We accidentally process focus events, which may run arbitrary code.  We can't
do this; it breaks a lot of invariants (for example the it can invalidate
the cursor positions for CursorPositionQuery, or it can cause fish to exit
before fully consumeing a query response).

Make sure we only process known-safe events.  We definitely need to process
CheckExit (in case we received SIGHUP). I guess we should also process Eof,
in case the terminal is buggy.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
5897d13333 Dedicated input event type for query responses
These code paths have a tiny bit of logic in common, share that.

Maybe this should be nested in ImplicitEvent, and maybe Eof and CheckExit
shouldn't be..
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
d18cb6ce27 Use OnceCell for terminal query state initialization
This object is initialized once just before we start reading from the terminal.
Once seems to be the appropriate type for this.  This gets rid of an awkward
enum variant.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
9b44a59b80 Rename terminal-query-state data structure
While at it, extract a function for initialization.  This looks pretty ugly
but it will get better with the next commit.
2025-04-29 13:51:18 +02:00
Johannes Altmanninger
788eddd0e8 Make terminal query data state a RefCell instead of mutex
We never need to access this from other threads, so a Mutex is overkill.
Leave behind stale variable names like "wait_guard" to be cleaned up by the
next commit.

Since TestInputEventQueuer is used concurrently in tests,
give it its own private object, to avoid borrowing conflicts.

Same for fish_key_reader; this fixes the issue that fish_key_reader potentially
reads keyboard input before a query is finished.
2025-04-29 13:50:15 +02:00
Johannes Altmanninger
e7c9f6d47e Move terminal query state data structure into the parser
Whenever config.fish runs (interactive) builtin read, we push and pop a
top-level, before the main shell's reader.

The terminal state outlives all readers, so its scope should reflect that
to avoid redundant initialization. Move it into the parser.

This is also used by a following commit that wants to access the query state
from a builtin. This should work even if no reader is active.

Note that Mutex doesn't really make sense here - the next commit will fix that.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
bb1e3f3aba Share InputEventQueuer::is_blocked implementation 2025-04-29 13:31:13 +02:00
Johannes Altmanninger
e490ba6fdf Remove stale lint suppression 2025-04-29 13:31:13 +02:00
Johannes Altmanninger
84c48c3f97 themes: sort
Keep fish_color_normal first since it seems to be the only one that's
special enough?
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
fd0f942fd0 builtin set_color: reuse outputter
The differences between color variables and set_color implementation have
gotten somewhat small so make them explicit by getting rid of this code clone.

Outputter::set_text_face() has clever caching logic that is not always needed
by builtin set_color -- in fact, it even needs to explicitly disable the
cache for foreground and background colros -- but this might still be worth it.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
c8f2471357 Stop --background=somecolor from implicitly setting the bold modifier
As reported in https://github.com/fish-shell/fish-shell/issues/11325, we have logic that
implicitly activates bold mode.

Even worse: the test case from https://github.com/fish-shell/fish-shell/issues/11426 shows that
we're not even consistent about that.

To reproduce, use

    set -g fish_pager_color_background --background=fff
    set -g fish_pager_color_prefix --underline --bold 000
    set -g fish_pager_color_completion
    set -g fish_pager_color_description
    complete : -s a -l all -d asdf

and type ": -" <TAB>

The second prefix is underlined but not bold,
because the implicit bold mode has a subtle bug.

Now if we were to fix this, using

    diff --git a/src/terminal.rs b/src/terminal.rs
    index b86a7d85fe..7791d34936 100644
    --- a/src/terminal.rs
    +++ b/src/terminal.rs
    @@ -589,7 +589,7 @@
             // Lastly, we set bold, underline, italics, dim, and reverse modes correctly.
             if style.is_bold()
                 && !self.last.style.is_bold()
    -            && !bg_set
    +            && !(bg_set && !last_bg_set)
                 && self.write_command(EnterBoldMode)
             {
                 self.last.style.bold = true;

that would make the description bold as well, which would probably cause chaos.
Either way, it seems wrong to expand this hack.

Let's remove it.

For better or worse, we can't safely update the default theme yet on
an existing user's machine, because we have set universal variables.
This means that fish_color_search_match and fish_pager_color_progress on
existing installations are no longer bold. That's probably acceptable.
The former was hard to read for the longest time, until 9af6a64fd2 (Fix
bad contrast in search match highlighting, 2024-04-15). The progress info
is probably not a big deal.

Attentive users may run "fish_config theme choose 'fish default'". Perhaps
we should tell them on upgrade?

Closes #11325
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
742016f455 __fish_config_interactive: reuse default theme
(As suggested in 84e7fbd466 (Make default .theme file consistent with uvars,
2022-02-03))

Historical behavior in default fish is that

1. fish_color_keyword and fish_color_option are unset, meaning they
   default to their fallbacks, fish_color_command and fish_color_param.
2. colors not mentioned in the default them, such as
   fish_pager_color_secondary_background, are unset

"fish_config theme save fish\ default"
- sets group 1 to a non-empty value (deactivating the fallbacks)
- sets group 2 to an empty value (which has no function change except it
  changes completions for builtin set)

Both are probably fine. I guess the historical behavior is a bit nicer.
But the new behavior is simpler. We can definitely optimize it later,
for example by never redundantly setting universal color variables to an
empty value.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
e71cace5f1 Remove unused fish_color_match
I'm not sure if keeping this helps anything? We can always add it back,
along with an announcement for third-party theme authors.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
50b93dd5c0 themes: update fish_color_search_match to be consistent with new default
The foreground component of fish_color_search_match was first used in commit
9af6a64fd2 (Fix bad contrast in search match highlighting, 2024-04-15)
which also changed it from bryellow to white.  Unfortunately it forgot to
update the themes. Probably all of them want to the default, so let's do that.
2025-04-29 13:31:13 +02:00
Johannes Altmanninger
364d84e620 Remove unused query for cursor position reporting
We only query for the cursor position if either
1. if the terminal sends an XTGETTCAP response indicating it supports scroll
   forward (terminfo code indn)
2. if the terminal sends a mouse click event

In practice, the terminals that do either are also capable of reporting the
cursor position, so let's require that for now.

We could definitely make this optional, and degrade gracefully -- that's
what I originally intended.

But maybe we don't need it? Keeps things simpler. In future, we can add a
timeout, and print an error, to help debugging terminals.
2025-04-29 13:31:13 +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
Daniel Rainer
e10573088a Clean up shell scripts
Some changes fix actual problems, e.g. missing spaces in square bracket tests,
and backticks unintentionally causing code execution when intended as formatting.

Others, such as conservative quoting probably work fine in the old version in
most situations, but it's nice to have some additional safety.

Using `{ ..; }` instead of `(..)` is just a small performance enhancement.

Many of these issues were identified by shellcheck, which might be useful in CI
as well.
2025-04-29 10:14:06 +02:00
Johannes Altmanninger
b431873ce5 Use fallback colors also for background/underline
Given

	set -g fish_color_error --background=red --background=blue
	set_color --background=red --background=blue

Historically, the former would use the first color (red) while the equivalent
set_color command uses the second one (blue).

This changed in 037c1896d4 (Reuse wgetopt parsing for set_color for internal
colors, 2025-04-13) which gave set_color semantics to the former.

This seems like the wrong choice set_color is less important.

For foreground colors we already pick the best color in a way that's consistent
across both.  Let's extend this approach to background and underline colors
(even though I'd not really recommend using this feature).

Fixes #11420
Closes #11421
2025-04-25 14:14:00 +02:00
Johannes Altmanninger
2c07dc3851 Reuse color parsing logic better
Consolidate best_color() calls because the following commit
wants to use this for background and underline colors too.
Switch to Result so we can use the "?" syntax.
2025-04-25 14:11:54 +02:00
Johannes Altmanninger
95ff22f644 Improve name for missing option argument error 2025-04-25 14:07:10 +02:00
Johannes Altmanninger
73a7d79023 Remove dead code in color parsing 2025-04-25 14:07:10 +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
Fabian Boehm
f222db609f Comment some possible changes if we increase MSRV 2025-04-24 19:54:39 +02:00
Johannes Altmanninger
97641c7bf6 Set transient command line in custom completions (Rust port regression)
Commit df3b0bd89f (Fix commandline state for custom completions with variable
overrides, 2022-01-26) made us push a transient command line for custom
completions based on a tautological null-pointer check ("var_assignments").

Commit 77aeb6a2a8 (Port execution, 2023-10-08) turned the null pointer into
a reference and replaced the check with "!ad.var_assignments.is_empty()".
This broke scenarios that relied on the transient commandline.  In particular
the attached test cases rely on the transient commandline implicitly placing
the cursor at the end, irrespective of the cursor in the actual commandline.

I'm not sure if there is an easy way to identify these scenarios.

Let's restore historical behavior by always pushing the transient command line.

Fixes #11423
2025-04-24 19:35:03 +02:00
Johannes Altmanninger
59d86e8e33 __fish_complete_suffix: don't write to global/universal variables 2025-04-24 19:35:03 +02:00
Anton Bilous
b7b1753716 Mention replace mode in fish_mode_prompt docs 2025-04-24 16:26:45 +03:00
Daniel Rainer
4555768d98 Add clippy lints about using stdlib print macros
Context why we do not want to use these macros:
https://github.com/fish-shell/fish-shell/pull/11397#discussion_r2050759690
https://github.com/fish-shell/fish-shell/pull/11397#discussion_r2050759693
https://github.com/fish-shell/fish-shell/pull/11397#discussion_r2050759696

These lints are not strictly about the macros, but at the moment they are
implemented to flag `print!`, `println!`, `eprint!`, and `eptintln!`.

https://rust-lang.github.io/rust-clippy/master/#print_stdout
https://rust-lang.github.io/rust-clippy/master/#print_stderr
https://doc.rust-lang.org/stable/clippy/lint_configuration.html#allow-print-in-tests
2025-04-23 20:24:12 +02:00
Johannes Altmanninger
07ed77e9a8 builtin set_color: do print other colors if one is reset-all
Commit cebc05f6c1 (Reset is not a color, 2025-04-15) tried to simpilfy
this behavior but forgot about cases like "set_color --background=normal
red --bold" where we do want to continue after resetting background.

Closes #11417
2025-04-23 20:11:24 +02:00
Johannes Altmanninger
709f193b50 builtin set_color: remove obsolete comment
"set_color normal --bold" does set the bold modifier since commit cebc05f6c1
(Reset is not a color, 2025-04-15), so this comment no longer applies.
2025-04-23 20:11:24 +02:00
Fabian Boehm
131f0f3916 CHANGELOG 2025-04-23 16:51:37 +02:00
Fabian Boehm
ae6eb121d9 Ignore some unused ControlFlow returns
Current rust nightly warns on these.
2025-04-23 16:36:16 +02:00
Daniel Rainer
51cf65d7c8 Remove e?println macros
These macros are problematic because:
- They panic when the output stream is closed.
- They are not aware of fish's encoding of arbitrary bytes into a section of a
  Unicode private use area. The custom printf macros handle this.

https://github.com/fish-shell/fish-shell/pull/11397
https://github.com/fish-shell/fish-shell/pull/11402
2025-04-23 15:24:35 +02:00
Anton Bilous
0349a70321 Fix typo in language docs 2025-04-23 21:07:31 +08:00
Ilia Gogotchuri
c0f5fcb089 Update tofu.fish 2025-04-22 14:17:52 +04: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
692599387b colors: test weird behavior of "--background=normal" 2025-04-21 18:11:44 +02:00
Johannes Altmanninger
c32b7d35ea Document differences between builtin set_color and fish_color_* handling 2025-04-21 18:11:44 +02:00
Johannes Altmanninger
939902eb29 Remove mysterious workaround for buggy sgr0 handling
This workaround was added in commit d66700a0e4 (Color work, 2012-02-11).
I don't understand why it would be necessary, it seems redundant.  Bravely
remove it. Would be interesting to know which terminal caused the motivating
problem.  Terminal.app and others seem to be unaffected by this change.
2025-04-21 18:11:44 +02:00
Johannes Altmanninger
cebc05f6c1 Reset is not a color
This command does not work

	set_color --background=reset

These seem to work

	set fish_color_normal reset
	set fish_color_normal --background=reset

but I don't understand why anyone would do that, since an empty color option
gives the same behavior.

Also "reset" is totally undocumented, since "normal" is our canonical spelling.

Let's simplify things by removing support for reset everywhere except if it's
a foreground color (since there are some uses of "set_color reset" out there).

Also, simplify the set_color logic accordingly.
2025-04-21 18:11:44 +02:00
Johannes Altmanninger
de830644fc webconfig: set_color -b=red is invalid
While at it, support parsing of "set_color -b red".
2025-04-21 18:11:43 +02:00
Johannes Altmanninger
1a63956860 Move separate bg/fg parsing up the call stack
Our highlighting module allows different highlight roles for foreground
and background.

Other users of our color-parsing logic have no need for this.

Historically we have passed an "is_background" bool and only parsed what we're
interested in.  This sort of makes sense because it's exactly what we need,
but it meant that the special behavior spread quite far.

There is no real need for spreading it; a function with the behavior "parse
a text face but honor is_background" is strictly more complex than "parse a
text face". Additionally, any performance optimization is only relevant if
the user specifies faces that won't be used, which is a very unusual case.

Let's isolate this logic in the highlighting module.
2025-04-21 18:11:43 +02:00
Johannes Altmanninger
6a8a02a549 Improve consistency of the CSI m writing logic 2025-04-21 18:11:43 +02:00
Johannes Altmanninger
d33cc5ea24 Replace tuple return value with struct
The parent commit got rid of the is_background parameter that determined
the meaning of the return value (fg/bg); since we always return both now,
give them names.
2025-04-21 18:11:43 +02:00
Johannes Altmanninger
9c39cab239 Make text style bitflags a plain struct
A following commit wants to add other underline styles.  At most one underline
style can be active at one time.  This can't be modelled well by a flat
bitset, so let's use a composable type here.
2025-04-21 18:11:43 +02:00
Johannes Altmanninger
426b242ce5 Outputter: use literals instead of variables 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
69aa492d40 Future-proof text style resetting logic
Some text styles don't have way of unsetting them specifically, so we use
CSI m. Let's make this the default action.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
45a13a0075 Outputter cache to use text face type
When the text face changes from bold to non-bold, we need to reset
all attributes since there is no exit_bold_mode.

The same holds for various dim and reverse mode, and future attributes.

A following commit wants to make this logic more robust to addition of future
attributes. Prepare for that by using the new type.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
fada8cfd6c Document weird "set_color normal --bold" behavior 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
a77da2366b builtin set_color: reuse outputter for resetting attributes 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
f36b704098 builtin set_color: remove redundant condition 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
234a9ef777 builtin set_color: remove weird use of lifetime extension
This is correct but seems odd. Converting this value to a reference
does not add convenience since we only use it as method receiver now.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
dd02a7e662 Remove hack for "set_color --print-colors --background normal"
This is no longer needed.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
037c1896d4 Reuse wgetopt parsing for set_color for internal colors
Not sure if this is 100% a good idea but it does remove some duplication.

While at it, change parse_color_maybe_none to actually return Option::None
and not Color::None which means something else (see a following commit).
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
b7c4ad455c builtin set_color: extract function 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
8586286837 Remove a needless use of Color::None 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
64c362bb73 Move text face/color parsing functions into new module
No other change.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
2ce3068465 New type for colors + text styling attributes
Our "Color" type also includes text styling (bold, italics, ...).  This doesn't
seem like the perfect way to model this, because the background text styles
are always unused (this is noticeable with some fish_color_* variables).

Introduce a type that represents attributes to apply to text, and nothing
else. Prefer to pass this instead of two Color values with redundant text
style is redundant.
2025-04-21 17:37:36 +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
Johannes Altmanninger
5067fa5f1d Harmonize fg/bg color output state transition
A "None" type color means "don't change it, use the last color.  So it makes
no sense to ever set "self.last_fg = NONE".  The background-color code path
only sets it in the other cases.  Let's copy that for the foreground one.

Also, extract this assignment to simplify both code paths.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
70c25096f2 Outputter: improve field name 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
007eda2f89 builtin set_color: fix inconsistent output in --print-colors
fish -c 'set_color --print-colors --background blue' |xxd

does not print color enabling sequences but does print *disabling* sequences.
There's no need for that.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
76dbd76c73 builtin set_color: remove dead code 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
82e7281675 Avoid intermediate WString when parsing colors
While at it, remove a check for "color_name.is_empty()" that is always true.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
1f0ce40408 Pass the RGB type instead of three bytes 2025-04-21 17:37:36 +02:00
Johannes Altmanninger
5b9ba559c7 Rename RgbColor to Color
RgbColor can also be a named color, so this name is surprising to readers
who don't have the implicit assumption that named colors are the default
and that RGB support is something novel.
2025-04-21 17:37:36 +02:00
Johannes Altmanninger
6f65661109 Replace redundant type name with Self 2025-04-21 17:37:36 +02:00
Peter Ammon
489d5d1733 ast: remove Node parent pointers
tl;dr reduce memory usage and ast complexity. No functional change expected.

This concerns how our ast is represented. Prior to this commit, and ever
since the new ast was introduced, each Node had a reference to its parent -
the so-called "parent pointer". This made it convenient to "walk around"
the AST - for example we could get a command and then walk up the AST to
determine if that command had a decoration (`time`, etc).

This parent pointer concept was natural in C++ for a few reasons:

1. Pointers are idiomatic in C++.
2. Parent pointers were "thin": just regular pointer-sized, e.g.
   8 bytes in x86-64.
3. C++'s inheritance means that the pointer can just be stored as a field
   in the base Node class. Super easy and efficient.

But these proved to have significant drawbacks when expressed in Rust:

1. Parent pointers form a cyclic data structure which is very awkward in
   Rust. We had to use raw pointers and unsafe code.
2. Parent pointers were a `&dyn Node` which is necessarily "fat" (base
   pointer + vtable pointer), taking up 16 bytes on a 64 bit machine. This
   greatly bloated the size of the AST because our AST is quite fine (many
   detailed node types).
3. The lack of inheritance means that parent pointers had to be repeated
   for every node and exposed through the Node trait, which was awkward and
   verbose.

In fact storing parent pointers is rather uncommon among AST
implementations. For example, LLVM does not do this; instead it dynamically
constructs a map of parent pointers on demand (see `ParentMapContext`).
fish could do this or something like it, but in fact we can do better: we
can tweak Traversal to provide parent pointers.

As a reminder, Traversal is a way of naturally iterating over all AST nodes
in a for loop:

    for node in ast.walk() {...}

This is in-order ("top-down"). A parent node is yielded before its children.

Prior to this commit, this worked as follows: the Traversal maintained a
stack of next-to-be-yielded nodes. The `next()` function would pop off the
next node, push all of its children onto the stack, and then yield that
popped node.

We can easily make Traversal remember the sequence of parents of a given
Node by tweaking the Traversal to remember each Node after popping it. That
is, mark each Node in the stack as "NeedsVisit" or "Visited". Within
`next()`, check the status of the top node:

  - NeedsVisit => mark it as Visited, push its children, and return that Node
  - Visited => pop it, discard it, and try again

This means that, for any Node returned by `next()`, we can get the sequence
of parents as those Nodes that are marked as Visited on the stack.

The net effect of all of this is a large decrease in ast complexity and
memory usage. For example, __fish_complete_gpg.fish goes from 508 KB to 198 KB,
as measured by `fish_indent --dump-parse-tree`.

There's somewhat higher memory usage for Traversal, but these are transient
allocations, not permanent.
2025-04-20 17:53:48 -07:00
Peter Ammon
e6bc8ffa13 ast: remove dead code
Having removed parent pointers, a bunch of existing ast "as_" functions have
become unused; remove them.
2025-04-20 17:53:43 -07:00
Peter Ammon
ff87e2cf0a ast: remove parent pointers
This removes parent back-pointers from ast nodes. Nodes no longer store
references to their parents, resulting in memory size reductions for the ast
(__fish_complete_gpg.fish goes from 508 KB to 198 KB in memory usage).
2025-04-20 17:53:43 -07:00
Peter Ammon
a528567d5c IndentVisitor to stop using parent pointers
We can just store these ourselves; don't have to be baked into the AST.
2025-04-20 17:53:43 -07:00
Peter Ammon
374b504eeb parse_util_detect_errors_in_ast to stop using ast parent pointers
Continue to move away from parent pointers.
2025-04-20 17:53:43 -07:00
Peter Ammon
119716fbf2 extract_tokens::is_command to stop using ast parent pointers
Simple change to remove a user of parent back-references.
2025-04-20 17:53:43 -07:00
Peter Ammon
68a357be3d fish_indent to stop using ast parent pointers
Reimplement fish_indent to discover parents through traversals, not ast
parent pointers.
2025-04-20 17:53:43 -07:00
Peter Ammon
996b34b5cb ast: pretty-print to stop using ast parent pointers
These depths are used in calculating indents for ast pretty-printing.

This moves away from parent back-pointers, so that we can ultimately remove
them.
2025-04-20 17:53:43 -07:00
Peter Ammon
8f46b617db ast: make Traversal more powerful
Prior to this commit, Traversal was a convenient way to walk the nodes of
an ast in pre-order. This worked simply: it kept a stack of Nodes, and then
when a Node was visited, it was popped off and its children added.

Enhance Traversal to track whether each node on the Stack is `NeedsVisit`
or `Visited`. The idea is that, when a Node is yielded from next(), we can
reconstruct its parents as those Visited nodes on the Traversal stack.

This will allow clients to get the parents of Nodes as they are traversed
without each Node needing to explicitly save its parent.
2025-04-20 17:53:43 -07:00
Peter Ammon
f7543dd447 ast: remove certain as_node() function calls
We can remove all of them once MSRV becomes 1.86, which adds support for trait
upcasting coercion; we can remove a few today.
2025-04-20 17:53:43 -07:00
Peter Ammon
7d98cc8850 ast: stop using Node::ptr_eq
This function hid a bug! It converted two Nodes to `*const ()` which discards
the vtable pointer, using only the data pointer; but two nodes can and do have
the same data pointer (e.g. if one node is the first item in another).

Add the (statically dispatched) is_same_node function with a warning comment,
and adopt that instead.
2025-04-20 17:53:43 -07:00
Peter Ammon
b33795533c ast: remove leaf_as_node()
Plain old as_node() is fine.
2025-04-20 17:53:42 -07:00
Peter Ammon
3f4839e5f2 Optimize ParseKeyword::from(&wstr)
This is a hot function and is easy to optimize.
2025-04-20 17:53:42 -07:00
Peter Ammon
cef7c3c5c4 Switch ParseKeyword to Rust naming conventions 2025-04-20 17:53:42 -07:00
Peter Ammon
a874237bff ast: Bravely stop allocating so much in Boxes
Now that we have more confidence in our pointers, we can allocate directly
more often, instead of always through Box. This recovers the performance
lost from the previous commit.
2025-04-20 17:53:42 -07:00
Peter Ammon
0b4883d07f ast: Bravely stop boxing items in lists
Prior to this commit, lists of items (e.g. an argument list to a command) would
each be Boxed, i.e. we had effectively Vec<Box<Item>>. The rationale here is
that we had raw pointers and pointer stability was important to enforce.

But we have fewer raw pointers now - only the parent pointers - and we can be
confident that the Ast will not change or move after construction. So remove
this intermediate Box, simplifying some logic and reducing ast size by ~5%.

This slows down Ast construction because we're still constructing
the Box and moving things in and out of it - that will be addressed in
subsequent commits.
2025-04-20 17:53:42 -07:00
Peter Ammon
3b3063287b ast: Add some comments about raw pointers and stability 2025-04-20 17:53:42 -07:00
Peter Ammon
be88d103ba ast: Use boxed slice instead of vec for list nodes
This saves a decent amount of memory, both because we no longer have excess
capacity sitting around that we'll never use, but also because we no longer need
to store the "capacity" value.
2025-04-20 17:53:42 -07:00
Peter Ammon
271a85571d Add a benchmark for AST construction
Run with `cargo +nightly bench --features=benchmark`
2025-04-20 17:53:42 -07:00
Peter Ammon
5f0584a6e6 Teach fish_indent to emit basic parse tree size metrics
A good basis to begin optimization.
2025-04-20 17:53:42 -07:00
David Adam
22d2dd6c90 Merge branch 'Integration_4.0.2' 2025-04-21 07:55:38 +08:00
Peter Ammon
485a6fa859 Fix a redundant import 2025-04-20 16:34:10 -07:00
Fabian Boehm
ca8416f18d docs/bind: Fix typo
Fixes #11408
2025-04-20 21:54:57 +02:00
David Adam
f1456f9707 Release 4.0.2 2025-04-20 21:11:52 +08:00
Sam Doran
b9f2275349 Refine when file completions are offered and add a missing short arg 2025-04-19 01:59:47 -04:00
Sam Doran
0b97fa7114 Evaluate completion arguments when called
This makes the destinations update dynamically when they are added/removed.
Unquote the echo statement so that it is correctly paresd by the -a options.
2025-04-19 01:17:58 -04:00
Sam Doran
1a2958d42b No need to reset ID
The values are only echoed if ID matches, so it will always be correct.
2025-04-19 00:59:30 -04:00
Sam Doran
3e8308f6eb Argument not description 2025-04-19 00:54:18 -04:00
Sam Doran
ff987f5f76 Do not use test for evaluating string match
Also add `--` to ensure parameters don't get mixed up with the line itself.
2025-04-19 00:52:31 -04:00
Daniel Rainer
9d904e1113 Improve profiling output
Indicate the units of the durations (microseconds).

Right-align the durations for better readability.

Use `format!` instead of `fprintf` for more flexible formatting.

Write to `File` instead of raw fd.

Closes #11396
2025-04-18 20:22:30 +02:00
David Adam
c88e6827b7 CHANGELOG: work on 4.0.2 2025-04-19 00:06:31 +08:00
Lucas Garron
3d7d57d612 Add completions for iconutil (macOS).
Closes #11392
2025-04-18 18:05:49 +02:00
exploide
fb314b28ff completions(tcpdump): suppress stderr + updates 2025-04-18 17:17:39 +02:00
Daniel Rainer
aa01f984b7 Use File as arg to print_profile 2025-04-17 11:46:35 +02:00
Daniel Rainer
b8bd3a25d7 Improve error handling 2025-04-17 11:46:35 +02:00
Daniel Rainer
01e7ba4b3a Reduce scope of raw_fd 2025-04-17 11:46:35 +02:00
Daniel Rainer
e5c953ea92 Replace read_loop with more idiomatic code 2025-04-17 11:46:35 +02:00
Daniel Rainer
70d682a110 Set file permissions via stdlib method 2025-04-17 11:46:35 +02:00
Daniel Rainer
21e284e548 Rename last_read_file to last_read_file_id
This is done to match the field's type.
2025-04-17 11:46:35 +02:00
Daniel Rainer
c2b8ee5554 Replace fstat with File::metadata() where possible 2025-04-17 11:46:35 +02:00
Daniel Rainer
5e8276ed15 Change file_id_for_fd to file_id_for_file 2025-04-17 11:46:35 +02:00
Sam Doran
a6fdb41940 Update completion for tmutil
- Reorganize completions and options so they are easier to read.
- Add destination UUIDs to completetions as well as descriptions
- Add a few missing sub commands
2025-04-16 11:59:24 -04:00
Johannes Altmanninger
bc3e3ae029 builtin read: always handle out-of-range codepoints (Rust port regression)
As mentioned in
https://github.com/fish-shell/fish-shell/pull/9688#discussion_r1155089596,
commit b77d1d0e2b (Stop crashing on invalid Unicode input, 2024-02-27), Rust's
char type doesn't support arbitrary 32-bit values.  Out-of-range Unicode
codepoints would cause crashes.  That commit addressed this by converting
the encoded bytes (e.g. UTF-8) to special private-use-area characters that
fish knows about.  It didn't bother to update the code path in builtin read
that relies on mbrtowc as well.

Fix that. Move and rename parse_codepoint() and rename/reorder its input/output
parameters.

Fixes #11383

(cherry picked from commit d9ba27f58f)
2025-04-16 11:33:15 +02:00
Johannes Altmanninger
3191ac13e5 Reduce parse_codepoint responsibilities, fixing alt in single-byte locale?
This also changes the single-byte locale code path to treat keyboard input
like "\x1ba" as alt-a instead of "escape,a".  I can't off-hand reproduce
a problem with "LC_ALL=C fish_key_reader", I guess we always use a UTF-8
locale if available?

(cherry picked from commit b061178606)
2025-04-16 11:28:28 +02:00
Johannes Altmanninger
4f810809c8 Fix builtin test assigning wrong range to "! -d /" (Rust port regression)
Fixes #11387

(cherry picked from commit c740c656a8)
2025-04-16 11:25:35 +02:00
Johannes Altmanninger
4e85366416 builtin commandline: minor cleanup 2025-04-16 11:24:33 +02:00
Johannes Altmanninger
0284292392 builtin read to pass through invalid UTF-8; reader to ignore invalid codepoints
Two issues:

1. typing the codepoint 0x123456 into fish_key_reader:

	$ fish_key_reader -cV
	# decoded from: \xf4\xa3\x91
	bind \xf4 'do something'
	# decoded from: 
	bind \xa3 'do something'
	# decoded from: 
	bind \x91 'do something'

The invalid codepoint is represented in its original encoding, which leaks
to the UI. This was more or less intentionally added by b77d1d0e2b (Stop
crashing on invalid Unicode input, 2024-02-27).  That commit rendered it
as replacement byte, but that was removed for other reasons in e25a1358e6
(Work around broken rendering of pasted multibyte chars in non-UTF-8-ish
locale, 2024-08-03).

We no longer insert such (PUA) codepoints into the commandline.  The "bind"
comes above would work however.  I don't think this is something we want
to support.  Discard invalid codepoints in the reader, so they can't be
bound and fish_key_reader shows nothing.

2. builtin read silently drops invalid encodings This builtin is not really
suited to read binary data (#11383 is an error scenario), but I guess it can
be bent to do that.  Some of its code paths use str2wcstring which passes
through e.g. invalid UTF-8.  The read-one-char-at-a-time code path doesn't.
Fix this.
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
d9ba27f58f builtin read: always handle out-of-range codepoints (Rust port regression)
As mentioned in
https://github.com/fish-shell/fish-shell/pull/9688#discussion_r1155089596,
commit b77d1d0e2b (Stop crashing on invalid Unicode input, 2024-02-27), Rust's
char type doesn't support arbitrary 32-bit values.  Out-of-range Unicode
codepoints would cause crashes.  That commit addressed this by converting
the encoded bytes (e.g. UTF-8) to special private-use-area characters that
fish knows about.  It didn't bother to update the code path in builtin read
that relies on mbrtowc as well.

Fix that. Move and rename parse_codepoint() and rename/reorder its input/output
parameters.

Note that the behavior is still wrong if builtin read can't decode the
input; see the next commit.

Fixes #11383
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
b061178606 Reduce parse_codepoint responsibilities, fixing alt in single-byte locale?
This also changes the single-byte locale code path to treat keyboard input
like "\x1ba" as alt-a instead of "escape,a".  I can't off-hand reproduce
a problem with "LC_ALL=C fish_key_reader", I guess we always use a UTF-8
locale if available?
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
a63633edea Remove redundant code in parse_codepoint 2025-04-16 11:24:33 +02:00
Johannes Altmanninger
c740c656a8 Fix builtin test assigning wrong range to "! -d /" (Rust port regression)
Fixes #11387
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
721c9a2c14 completions/set: add some special variables 2025-04-16 11:24:33 +02:00
Johannes Altmanninger
7337bfee47 completions/set: sort 2025-04-16 11:24:33 +02:00
Johannes Altmanninger
5076cfbd71 Fix a case where path canonicalization leaks trailing slash
As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$BDVmBtBgtKCj45dVfS36rP7Y6Fo7E4uBg1vcH9IIIQg

	tmux new-session -c "" fish -C 'echo $PWD'

prints

	/home/fishuser/

This is because our path canonicalization function only
removes trailing slashes if there were duplicate slashes in the string.
Else (for the case above), we end up with "trailing == len"
which means we ignore trailing slashes.

I don't think this was intended by 24f1da7f30 (Add a fancy new
paths_are_equivalent function to test for equivalent paths instead of merely
equal ones, 2013-08-27). Fix it.
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
2d506245be Rename confusing variables in path_make_canonical
The terms leading/trailing for the read-head and write-head are reasonable
but confusing in this context where trailing (slash) has another meaning.
2025-04-16 11:24:33 +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
123b262e97 fish_jj_prompt: remove not-so-useful bits
Things like branch and tag name can take up a lot of space on the screen. The
empty status may be useful but we're still looking for evidence.  For now let's
keep only the conflict status, which is fairly familiar from the Git prompt.

See also #11183
2025-04-16 11:24:33 +02:00
Johannes Altmanninger
267b16235d Fix transient prompt mode for single-line prompts
Extend a hack multi-line prompts to the new transient prompt code path.
This fixes transient prompt with single-line prompts; added a test case.

While at it, add a test that covers the need for this hack.

Patch-by: kerty <g.kabakov@inbox.ru>

See https://github.com/fish-shell/fish-shell/pull/11153#issuecomment-2801014723
2025-04-16 11:22:14 +02:00
kpbaks
54971621de completions/git: show url as description for remote completion 2025-04-16 09:56:45 +02:00
Ilya Grigoriev
76a6ffe59e status get/list-files: fix minor bugs when compiled without embedded files (#11390)
* man: redirect stderr to /dev/null when checking for embedded files

This fixes a bug where `man status` results in "status: fish was not
built with embedded files⏎" printed.

* fish_config and status completions: redirect stderr to /dev/null when checking for embedded files

I am less sure about this commit, can get rid of it.

* status get-file/list-files: add \n to error message when not compiled with embedded files
2025-04-16 08:46:22 +02:00
Fabian Boehm
6ede047680 completions/cargo: Fix package completion
The original only worked in the manifest directory *and* didn't even
list the right packages.

E.g. for fish it listed "printf", when the package is called
"fish-printf". So we're not keeping it because it's wrong.

Instead let's parse the actual json. It's a shame there is no
simple command to just get it line-delimited, of course.

Fixes #11384
2025-04-15 20:23:03 +02:00
Fabian Boehm
ab7d52d727 completions/rustup: Simplify listing installable targets 2025-04-15 20:21:10 +02:00
Fabian Boehm
6c75cf75fe Update widestring 2025-04-15 20:13:22 +02:00
ndrew222
827bc32561 added completion for uv and uvx 2025-04-16 00:36:42 +08:00
Peter Ammon
85ea9eefc6 Fight off some clipplies 2025-04-14 21:08:26 -07:00
David Adam
692b53ab85 remove stray file 2025-04-13 09:14:46 +08:00
Johannes Altmanninger
92510c0488 man.fish: fix spurious error on embed-data builds
Commands like "man grep" print an error because __fish_data_dir[1] is no
longer defined. Fix that.
2025-04-12 20:25:08 +02:00
exploide
b6c5f3dc38 completions: improved ip completions
added completions for ip tuntap
standardize help completion
2025-04-12 16:26:15 +02:00
Fabian Boehm
765b700a04 cmake: Warn on unknown build type
CMake has this entire zoo of weird build types including "MinSizeRel".
I've also seen it set to empty, in distro packages no less.

Since we can't really make them all known to cargo, let's warn.

We could also error, but I'm not convinced there isn't some distro
packager out there setting it to "StrawberriesAndKittens" for some
reason,
and they'd be very cross with us if that stopped working.

See #11376
2025-04-12 14:21:56 +02:00
Johannes Altmanninger
b569f0d62f Update docs for transient prompt
Closes #11153
2025-04-12 12:09:08 +02:00
Johannes Altmanninger
6e85e5f6a0 Fix sphinx warning in changelog 2025-04-12 12:07:54 +02:00
Johannes Altmanninger
4b2c707721 Simplify exec_prompt_cmd 2025-04-12 12:07:54 +02:00
kerty
b3e417fd05 Add documentation for transient prompt 2025-04-12 12:07:26 +02:00
kerty
231ab22ce4 Update docs for transient prompt
See #11153
2025-04-12 12:07:26 +02:00
kerty
ca1d7ef863 Fix residual lines after repaint with shrinking prompt
If you use `set t 10; function fish_prompt; seq $t; set t $(math $t - 1); end` and trigger a repaint, you will see 9 residual lines from the previous prompt.
2025-04-12 10:51:35 +02:00
kerty
7ed4dfbd2d Ease condition for the execution of the right prompt
Now, the right prompt will not be executed only if it is undefined `fish_right_prompt`.
This allows the use of `read -p 'echo left' -R 'echo right'`.

Also changes condition for use of `DEFAULT_PROMPT` for consistency.
2025-04-12 10:46:33 +02:00
kerty
cb31f3e092 Refactor Reader::exec_prompt
Also fixes repaint-mode being run interactively
2025-04-12 10:46:33 +02:00
Johannes Altmanninger
b81a55e5f0 Fix bad conflict resolution 2025-04-12 10:34:38 +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
Johannes Altmanninger
e7270915ac Update color support on COLORTERM change 2025-04-11 22:20:45 +02:00
Johannes Altmanninger
e45401e403 Fix copy paste error for smso/ritm/rmul sequences
We have basically zero system tests for text coloring/formatting.  I have
something in the works that will enable this without forcing tests to parse
the output of "tmux capture-pane -pe".

Fixes #11373
Fixes 17b4b39c8b (Stop reading terminfo database, 2025-03-20).
2025-04-11 22:20:45 +02:00
Johannes Altmanninger
fee48f8508 Remove stale output buffering code
This is handled above.
2025-04-11 22:20:45 +02:00
Johannes Altmanninger
d622949d26 Fix kill-selection crash when selection start is out-of-bounds
This part of the code could use some love; when we happen to clear the
selected text, we should end the selection.

But that's not how it works today. This is fine for Vi mode, because Vi
mode never deletes in visual mode.

Let's fix the crash for now.

Fixes #11367

(cherry picked from commit af3b49bf9c)
2025-04-11 19:31:09 +02:00
Daniel Rainer
9618a38215 Make control flow more explicit, log errors 2025-04-11 17:52:27 +02:00
Daniel Rainer
5c0fddae70 Refactor history flushing
Use function names which explicitly state their flushing behavior.
When writing history items to a new file, flushing is only done at the end.
When appending items to an existing file, flushing is done for each item, in
order to keep the `first_unwritten_new_item_index` counter consistent with the
file system.
2025-04-11 17:52:27 +02:00
Daniel Rainer
5c8d822ee1 Flush history with sync
- Replace the write_loop call with Writer::write_all.
- Call sync_all on the file to ensure it gets written to storage.
2025-04-11 17:52:27 +02:00
Fabian Boehm
170b3593a0 CHANGELOG 2025-04-11 17:39:56 +02:00
Fabian Boehm
b815fff292 Set $__fish_data_dir to empty for embed-data builds
These builds do not use it, and setting it makes it possible to use
stale files.

So instead, we set it to empty. All uses I could find are either fine
with that (`set fish_function_path $__fish_data_dir/functions` - which
would also just be empty, which means it reads the embedded
functions),

or would break even if the variable was set but the directory was
empty (`source $__fish_data_dir/completions/git.fish`).
2025-04-11 17:29:22 +02:00
Fabian Boehm
329cd7d429 Make functions, completions and tests resilient to running on an embed-data fish
In case a completion needs a function from another script, run
`complete -C"foo "` to load it, so the full autoloading logic is used.

Otherwise these things break if the path is off. E.g. cargo's version
will fail if you override the cargo completion in
~/.config/fish/completions without also overriding the rustup
completions.

In other cases, fix for empty $__fish_data_dir, which will be coming in the next commit
2025-04-11 17:29:22 +02:00
Fabian Boehm
53b2f5511b Rename the "installable" feature to "embed-data"
This reflects better what it is - fish doesn't need to "install"
itself anymore, it just includes the data in the binary.

This also means we could include a separate "embed-man" feature that
can be turned off if you want the man pages to be shipped separately.

Also explain that in the README.
2025-04-11 17:29:22 +02:00
Fabian Boehm
1a96db1708 functions/*: Extract data when needed
Technically the fish_update_completions files could also be piped to
python, but they'd have to be one file.

So for now, if you start a single-file fish, you'll have to run
fish_update_completions manually.

That fits the idea of having a single file that you move somewhere
better, given that it otherwise would run a script in the background
that creates a bunch of files
2025-04-11 17:29:22 +02:00
Fabian Boehm
ee2a6a851d Document and complete status get-file/list-files 2025-04-11 17:29:22 +02:00
Fabian Boehm
b56b876a98 Add status list-files
This allows us to implement fish_config using embedded files
2025-04-11 17:29:22 +02:00
Fabian Boehm
ca3a7f8356 Add status get-file
This allows getting embedded files, so we can use them in functions
2025-04-11 17:29:22 +02:00
Fabian Boehm
c8719fbff5 Rebuild if share/ or doc_src/ changed
Because these are embedded in the fish binary,
we need to rebuild fish once they're changed.

This is only for release builds,
because rust-embed only really embeds in those
(debug builds read from the filesystem).
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
Fabian Boehm
2a3a23f53d Teach autoloader to read embedded files
This will load the functions and completions from inside of the fish
binary.

That means its no longer necessary to *install* a self-installable
build for basic functionality.

The functions/completions will be loaded *last*, so they are still
overridable via a file on disk (with the exception of
generated_completions, which we only use as a fallback if no
completions exist).

It still needs to extract files that are to be used by other tools,
including the man pages, fish_config.py, the man page completion
generator.

The remaining issues:

- It no longer prompts to install, but if you tried `fish_config`
  after this it would fail to open the tool,
  and it would be easy to forget to update those files
  So: When and how should this remind you that these files need to be extracted?
  Do we want e.g. a builtin that checks the version file (`status installed`)?
  This could then be run by `fish_config` and `help` and tell you to run `fish --install`.
- `builtin --help` will fail - we could read these things from inside,
  but we'd need groff for that.
  Do we want to pre-process these and put them in the builtins themselves?
  Do we want to print these on demand in `__fish_print_help` to groff?
- What directories need to still be defined? Does $__fish_data_dir need to keep existing?

Technically this *could* be the main distribution method. Maybe we
could let distro packages skip the embedded documentation and external
files,
but keep the functions/completions in the binary.
2025-04-11 17:29:22 +02:00
Fabian Boehm
66d7c00ba3 Let parser eval string directly
This gets the reader out of asting the source and is needed for
autoloader to get it to read a source string directly

Also add an "eval_file_wstr" method as a convenience to run a wstr as if it is a *file*, with a block and stuff
2025-04-11 17:29:22 +02:00
Fabian Boehm
64659e48f8 HACK: Create man1 dir even if not installable 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
Johannes Altmanninger
ad6d7137b8 Simplify selection between "CSI A" and "CSI Ps A"
I think multi is always shorter unless we're only moving by one cell.

Also, we want to simplify this for a following commit where we no longer
check if it's supported.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
f2e28fa6c4 Drop unnecessary use of is_dumb()
"infocmp dumb" shows that this is redundant.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
ef7bd4f13a Filter all control sequences but colors and cursor movement in tests
There are more escape sequences that can affect terminal state; let's allow
only the ones that are known-safe.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
f1aba8e3cd Remove unused terminfo capabilities 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
854e13048b Stop supporting terminals without eat_newline_glitch
This reverts commit 58347d494a (update PROMPT_SP heuristic, 2016-12-23)

If we write the last column of a line:

	printf %0"$COLUMNS"d 0; sleep 3

most terminals will *not* move the cursor to the next line.

This behavior is indicated by the terminfo's xenl (AKA xen or
eat_newline_glitch) boolean capability.

We originally added checks for this capability because ConEmu and Windows
ConHost did not implement it, but they do now.

Also, as mentioned in
https://github.com/fish-shell/fish-shell/pull/11342#issuecomment-2769979520,
we're not aware of any present-day terminal that does not have this behavior,
but the value advertised by terminfo is sometimes wrong.

Let's get rid of this for now. A following commit will document that we
require this behavior.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
0ca08ce81d Buffer OSC 0 terminal title writing 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
15379ae409 Ignore values XTGETTCAP values for indn/cuu
I don't think we want to support terminals that implement XTGETTCAP but for
some reason don't use CSI Ps S for scroll forward; that would be a needless
complication. 
Let's make ctrl-l / scrollback-push fail hard if a terminal does this.
Confusingly kitty and foot use different response formats, but happily we
no longer care.

An upcoming commit will document that we require the CSI Ps S style.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
7d5fb623c6 Remove unused variable 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
c0ad15fbc5 Fix missing repaint when TERM changes
E.g.

	set TERM xterm-16color
	set TERM xterm-mono
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
926566bad5 Remove unused parameter 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
aa825c40da Fix RST syntax 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
423a5a20ba Remove dead code checking for uninitialized terminal
See 75f7cda6ab (Add xterm-256color fallback, 2024-01-28).
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
594daf8f64 Use internal RST link for linking to #building 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
d3b4a33ba4 Remove intrusive Screen::scoped_buffer
scoped_buffer borrows the screen to be able to flush buffers on drop.  This is
a bit intrusive (see also 29ae571afa (Make scoped_push nicer, 2024-12-28)).

Not sure what's the best solution -- probably we should always pass the
outputter as parameter, removing the field.

For now let's at least contain the effects of this.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
ce01b16402 Fix typo 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
39aa478108 Extract unwrapping for buffer-writes that are assumed to not fail 2025-04-11 15:11:22 +02:00
Johannes Altmanninger
9206a91701 Improve BufferedOuputter ergonomics
Factor some redundant logic from call sites into the constructor, even if
it's exactly what the constructor actually needs.
2025-04-11 15:11:22 +02:00
Johannes Altmanninger
af3b49bf9c Fix kill-selection crash when selection start is out-of-bounds
This part of the code could use some love; when we happen to clear the
selected text, we should end the selection.

But that's not how it works today. This is fine for Vi mode, because Vi
mode never deletes in visual mode.

Let's fix the crash for now.

Fixes #11367
2025-04-11 15:11:22 +02:00
Daniel Rainer
ad0e2c17ac Fix profiling time log
`Duration::as_nanos()`
"Returns the total number of nanoseconds contained by this Duration."
https://doc.rust-lang.org/core/time/struct.Duration.html#method.as_nanos

Because we are indicating the time in milliseconds, we cannot use
`Duration::subsec_nanos()` but we need to manually get the whole duration in
nanoseconds and subtract the duration in milliseconds to get the fractional
part.
2025-04-10 19:43:19 +02:00
exploide
83963287d6 completions(resolvectl): updated to newer version 2025-04-09 19:11:59 +08:00
Fabian Boehm
d95b662542 docs: Fix string-match glob examples
`?` no longer is a wildcard.

See #11361

(cherry picked from commit eb4a0b2560)
2025-04-08 17:14:12 +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
d88d3122c8 Fix crash when history pager is closed before search
With

	bind ctrl-r 'sleep 1' history-pager

typing ctrl-r,escape crashes fish in the history pager completion callback,
because the history pager has already been closed.

Prior to 55fd43d86c (Port reader, 2023-12-22), the completion callback
would not crash open a pager -- which causes weird races with the
user input.

Apparently this crash as been triggered by running "playwright",
and -- while that's running typing ctrl-r ligh escape.
Those key strokes were received while the kitty keyboard protocol
was active, possibly a race.

Fixes #11355

(cherry picked from commit c94e30293a)
2025-04-04 14:37:03 +02:00
Johannes Altmanninger
c94e30293a Fix crash when history pager is closed before search
With

	bind ctrl-r 'sleep 1' history-pager

typing ctrl-r,escape crashes fish in the history pager completion callback,
because the history pager has already been closed.

Prior to 55fd43d86c (Port reader, 2023-12-22), the completion callback
would not crash open a pager -- which causes weird races with the
user input.

Apparently this crash as been triggered by running "playwright",
and -- while that's running typing ctrl-r ligh escape.
Those key strokes were received while the kitty keyboard protocol
was active, possibly a race.

Fixes #11355
2025-04-04 14:34:11 +02:00
Bec Donald-Wilson
68a8ab9667 Fix alt-right binding 2025-04-03 02:01:49 +02:00
Johannes Altmanninger
88e724384c pexpects/history.py: reduce surprise in env setup
This "SpawnedProc(env=os.environ.copy())" seems redundant but it's not, since
the default argument is initialized (with a copy of env) at module-load time.
Reshuffle the code to make it look less odd.

While at it, fix some invalid escape sequence warnings.
2025-04-03 00:51:35 +02:00
Johannes Altmanninger
50a6e486a5 Allow explicit shift modifier for non-ASCII letters, fix capslock behavior
We canonicalize "ctrl-shift-i" to "ctrl-I".
Both when deciphering this notation (as given to builtin bind),
and when receiving it as a key event ("\e[105;73;6u")

This has problems:

A. Our bind notation canonicalization only works for 26 English letters.
   For example, "ctrl-shift-ä" is not supported -- only "ctrl-Ä" is.
   We could try to fix that but this depends on the keyboard layout.
   For example "bind alt-shift-=" and "bind alt-+" are equivalent on a "us"
   layout but not on a "de" layout.
B. While capslock is on, the key event won't include a shifted key ("73" here).
   This is due a quirk in the kitty keyboard protocol[^1].  This means that
   fish_key_reader's canonicalization doesn't work (unless we call toupper()
   ourselves).

I think we want to support both notations.

It's recommended to match all of these (in this order) when pressing
"ctrl-shift-i".

	1. bind ctrl-shift-i do-something
	2. bind ctrl-shift-I do-something
	3. bind ctrl-I do-something
	4. bind ctrl-i do-something

Support 1 and 3 for now, allowing both bindings to coexist. No priorities
for now. This solves problem A, and -- if we take care to use the explicit
shift notation -- problem B.

For keys that are not affected by capslock, problem B does not apply.  In this
case, recommend the shifted notation ("alt-+" instead of "alt-shift-=")
since that seems more intuitive.
Though if we prioritized "alt-shift-=" over "alt-+" as per the recommendation,
that's an argument against the shifted key.

Example output for some key events:

	$ fish_key_reader -cV
	# decoded from: \e\[61:43\;4u
	bind alt-+ 'do something' # recommended notation
	bind alt-shift-= 'do something'
	# decoded from: \e\[61:43\;68u
	bind alt-+ 'do something' # recommended notation
	bind alt-shift-= 'do something'

	# decoded from: \e\[105:73\;6u
	bind ctrl-I 'do something'
	bind ctrl-shift-i 'do something' # recommended notation
	# decoded from: \e\[105\;70u
	bind ctrl-shift-i 'do something'

Due to the capslock quirk, the last one has only one matching representation
since there is no shifted key.  We could decide to match ctrl-shift-i events
(that don't have a shifted key) to ctrl-I bindings (for ASCII letters), as
before this patch. But that case is very rare, it should only happen when
capslock is on, so it's probably not even a breaking change.

The other way round is supported -- we do match ctrl-I events (typically
with shifted key) to ctrl-shift-i bindings (but only for ASCII letters).
This is mainly for backwards compatibility.

Also note that, bindings without other modifiers currently need to use the
shifted key (like "Ä", not "shift-ä"), since we still get a legacy encoding,
until we request "Report all keys as escape codes".

[^1]: <https://github.com/kovidgoyal/kitty/issues/8493>
2025-04-03 00:51:35 +02:00
Johannes Altmanninger
7f25d865a9 Stop accepting "bind shift-A"
This notation doesn't make sense, use either A or shift-a.  We accept it
for ASCII letters only -- things like "bind shift-!" or "bind shift-Ä"
do not work as of today, we don't tolerate extra shift modifiers yet.
So let's remove it for consistency.

Note that the next commit will allow the shift-A notation again, but it will
not match shift-a events.
2025-04-03 00:51:35 +02:00
Johannes Altmanninger
855a1f702e Extract KeyEvent type
The be used in the grandchild commit.
2025-04-03 00:51:35 +02:00
Johannes Altmanninger
fabbbba037 Extract function for creating key event with modifiers 2025-04-03 00:51:35 +02:00
Johannes Altmanninger
2731c4f8c8 Fix compiler warning when building with installable support 2025-04-03 00:51:35 +02:00
Fabian Boehm
a7f717c59c CHANGELOG for 4.0.2 2025-04-02 17:06:55 +02:00
Fabian Boehm
ba49981f17 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

(cherry picked from commit 411a396fa9)
2025-04-02 17:03:57 +02:00
Farhood Etaati
05ae55b172 Adds git subtree completion
Closes #11063

(cherry picked from commit 48306409ef)
2025-04-02 17:03:57 +02:00
Ilya Grigoriev
b5877ebe44 jj completions: use dynamic completions by default, also fix
This uses jj's dynamic completions when possible.

This avoids an annoying problem. After 04a4e5c4, jj's dynamic
completions (see the second paragraph of
<https://jj-vcs.github.io/jj/latest/install-and-setup/#command-line-completion>)
do not work very well in fish if the user puts `COMPLETE=fish jj |
source` in their `~/.config/fish/config.fish`. When the user types `jj
<TAB>`, they are instead overridden by fish's built-in non-dynamic
completions.

The difference is subtle. One problem I saw is that `jj new <TAB>` works
as expected (and shows revisions) while `jj new -A <TAB>` becomes broken
(and shows files).

If the user puts `COMPLETE=fish jj | source` in
`~/.config/fish/completions/jj.fish` there is no problem. However, users
might be confused if they run `COMPLETE=fish jj | source` or put it in
their config and it works in a broken fashion. I certainly was.

Meanwhile, I checked that if the user has `jj completion fish | source`
in their `config.fish`, executing `COMPLETE=fish jj
__this_command_does_not_exist | source` afterwards still works
correctly.

Let me know if there's a better approach to this problem.

(cherry picked from commit 932010cd04)
2025-04-02 17:03:57 +02:00
Clément Martinez
f9a03215b8 Add wlr-randr completions
(cherry picked from commit ea8e122fad)
2025-04-02 17:03:57 +02:00
memchr
ff0980c4c1 completions/systemd-analyze: add new options and subcommands
options:
- instance
- image
- image-policy
- tldr
- unit
- table
- no-legend
- detailed
- scale-svg
- malloc

subcommands:
- filesystems
- compare-versions
- inspect-elf
- fdstore
- has-tpm2
- pcrs
- srk
- architectures
- smbios11

fix a typo in timespan completion

Signed-off-by: memchr <memchr@proton.me>
(cherry picked from commit 3744c02a01)
2025-04-02 17:03:57 +02:00
memchr
1a58d3f08b completions/cryptsetup: complete device mapping names
The commands 'close', 'resize', and 'status' each take 'name' as their solo argument.

Signed-off-by: memchr <memchr@proton.me>
(cherry picked from commit 5012bcb976)
2025-04-02 17:03:57 +02:00
memchr
b71027f622 completions/git: add --filter option
supported subcommands:
- clone
- fetch
- submodule update
- rev-list

(cherry picked from commit 795d6b6c40)
2025-04-02 17:03:57 +02:00
Jonathan Palardy
84c03c6f26 completions/git: Added autostash option to git merge
(cherry picked from commit 269ed5ddf4)
2025-04-02 17:03:57 +02:00
memchr
bf455bc316 completions/btrfs: add new options and commands
Also add completion for balance filters

(cherry picked from commit 95b93c6bff)
2025-04-02 17:03:57 +02:00
Johannes Altmanninger
6af0378916 Don't insert text from keys like super-i
While at it, use declaration order for modifiers.

(cherry picked from commit 35ae0bf1f2)
2025-04-02 17:03:57 +02:00
Fabian Boehm
de154065fe fish_print_hg_root: Don't break if $PWD includes newlines
Fixes #11348

(cherry picked from commit 5e25cdaa6f)
2025-04-02 17:01:25 +02:00
Fabian Boehm
459e9b7847 completions/cargo: Speed up
This does two things:

- it stops completing cargo- tools because `cargo --list` already
includes them. This speeds up loading especially with a long $PATH
- it stops using `cargo search` for `cargo add` and install.
  this removes a network call, which may be unexpected and can take a
  long time

Fixes #11347

(cherry picked from commit 18371fbd4e)
2025-04-02 17:00:30 +02:00
Fabian Boehm
5e25cdaa6f fish_print_hg_root: Don't break if $PWD includes newlines
Fixes #11348
2025-04-02 16:59:21 +02:00
Fabian Boehm
9c5be2a2d8 completions/cargo: Complete -Z options 2025-04-02 16:58:47 +02:00
Fabian Boehm
18371fbd4e completions/cargo: Speed up
This does two things:

- it stops completing cargo- tools because `cargo --list` already
includes them. This speeds up loading especially with a long $PATH
- it stops using `cargo search` for `cargo add` and install.
  this removes a network call, which may be unexpected and can take a
  long time

Fixes #11347
2025-04-02 16:57:32 +02:00
Johannes Altmanninger
d234ebf484 Fix fuzzy matching for multi-character lowercase sequences
Same as 8668ce336c (Fix common::wcscasecmp() for multi-byte lowercase strings,
2023-05-02).
2025-04-02 02:02:12 +02:00
Johannes Altmanninger
81f1ab75d0 Fix clippy warning about needlessly narrow parameter type 2025-04-02 01:19:13 +02:00
Johannes Altmanninger
daa692a20b Remove unnecessary escaping for # and ~ inside key name tokens
While at it, don't escape "?", I don't know why 68e167d576 (f-k-r should
use the user's locale, 2016-06-29) did that. Question mark is only special
in combination with redirections.
2025-04-02 01:05:51 +02:00
Johannes Altmanninger
892c970bfa webconfig: remove legacy and raw key name parser for now
This parser was pretty nice but it has some issues with the new syntax.
It's not really needed when most bindings use the new syntax.

Let's remove it altogether.
2025-04-02 01:05:51 +02:00
Johannes Altmanninger
defd041863 webconfig: clarify invariant
We're splitting at most twice, so there can only be three or fewer parts.
2025-04-02 01:05:51 +02:00
Johannes Altmanninger
d4082893ae completions/bind: complete super modifier 2025-04-02 01:05:51 +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
e9d1cdfe87 Extract constant for the number of function keys
Switch to fish_wcstoul because we want the constant to be unsigned.
It's u32 because most callers of function_key() want that.
2025-04-02 01:01:59 +02:00
Johannes Altmanninger
26ca12d5af docs/bind.rst: add missing named keys 2025-04-02 00:53:48 +02:00
Johannes Altmanninger
3fe6d49224 Silence unused-imports warning when not installable 2025-04-01 17:35:58 +02:00
Johannes Altmanninger
2719ae443b Silence unexpected_cfgs error about unknown cygwin target
Extract our own cfg value, to avoid noisy warnings like:

	warning: unexpected `cfg` condition value: `cygwin`
	  --> src/fallback.rs:78:23
	   |
	78 |             #[cfg(not(target_os = "cygwin"))]
	   |                       ^^^^^^^^^^^^^^^^^^^^
	   |

The cygwin target will be added to Rust 1.86, so we can get rid of this
after some time.
2025-04-01 17:30:15 +02:00
王宇逸
ec1c2473c2 Fix tty timestamps handling
Closes #11238
2025-04-01 17:15:48 +02:00
王宇逸
bbf678e718 Reduce warnings when posix_spawn disabled. 2025-04-01 17:15:48 +02:00
王宇逸
e21eea6ac6 Reduce warnings on is_console_session 2025-04-01 17:15:48 +02:00
王宇逸
99fdcd725b Disable test_topic_monitor_torture on cygwin 2025-04-01 17:15:48 +02:00
王宇逸
b35825e618 Fix wc <-> mb conversion 2025-04-01 17:15:48 +02:00
王宇逸
4eceabeaad Fix path env on cygwin when cross compiling from Windows 2025-04-01 17:15:48 +02:00
王宇逸
2e89f37446 Fix wcwidth on cygwin 2025-04-01 17:15:48 +02:00
Johannes Altmanninger
f88470aa3c Address some unused_must_use warnings for ControlFlow
As seen on nightly Rust.
2025-04-01 17:15:48 +02:00
Johannes Altmanninger
415da8fc3b Remove obsolete st \e[P binding for delete
Since we request application keypad mode, st sends \e[3~ instead which we
already decode.
2025-04-01 17:00:48 +02:00
Johannes Altmanninger
18e6074aa7 Fix regression causing fish_key_reader to not request modifyOtherKeys
If the kitty protcol is not supported, we still want to request modifyOtherKeys
and application keypad mode. Since 2d234bb676 (Only request keyboard protocols
once we know if kitty kbd is supported, 2025-01-26), fish_key_reader fails
to turn on those modes if the kitty keyboard protocol is not supported.
2025-04-01 17:00:48 +02:00
Johannes Altmanninger
4c212776bf Remove obsolete st \e[Z binding for shift-tab
We already decode this to shift-tab (not to mention that up-line was the
wrong action, no?).
2025-04-01 17:00:48 +02:00
Hameer Abbasi
bf65b9e3a7 Change gettext paths to be relocatable (#11195)
Move config path logic into its own module and use it for locale as well.
2025-03-30 19:48:47 +02:00
Fabian Boehm
205d80c75a findrust: Simplify (#11328)
FindRust is too clever by half. It tries to do rustup's job for it.

See b38551dde9 for how that can break.

So we simplify it, and only let it check three things:

- Where's rustc? Look in $PATH and ~/.cargo/bin
- Where's cargo? Look in $PATH and ~/.cargo/bin
- What is the rust target (because we pass it explicitly)?

If any of these aren't that simple, we'll ask the user to tell us,
by setting Rust_COMPILER, Rust_CARGO or Rust_CARGO_TARGET.

None of the other things are helpful to us - we do not support windows
or whatever a "unikraft" is, and if the rust version doesn't work
it'll print its own error.

We could add a rustc version check, but that will become less and less
useful because rustc versions since 1.56 (released October 2021) will check rust-version in
Cargo.toml. So even at this point it's only pretty old rust versions already.
2025-03-30 19:47:09 +02:00
Fabian Boehm
446f1344fc completions/patch: Put CYGWIN code first
Just so we don't error with non-0
2025-03-30 19:46:01 +02:00
Daniel Rainer
460b93a5bc Rebuild on changes relevant to build artifacts
If anything changes in one of the listed directories or files, trigger a
rebuild.

Rebuilds are needed to update the version info built into the binaries.
The version info includes an abbreviated git commit hash, as well as information
about whether the repo was in a dirty state (uncommitted changes) when building.
Changes to files not explicitly listed will not trigger a rebuild, so to get
accurate version info upon such changes (also when checking out a different
commit which does not differ in any of the listed files), a rebuild needs to be
triggered manually (e.g. via `cargo clean` or `touch build.rs`).
2025-03-30 19:43:04 +02:00
Fabian Boehm
6dcead7be5 docs: Make --wraps clearer
Fixes #11317
2025-03-30 19:42:00 +02:00
Johannes Altmanninger
35ae0bf1f2 Don't insert text from keys like super-i
While at it, use declaration order for modifiers.
2025-03-30 16:00:38 +02:00
memchr
95b93c6bff completions/btrfs: add new options and commands
Also add completion for balance filters
2025-03-29 13:47:38 +01:00
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
Jonathan Palardy
269ed5ddf4 completions/git: Added autostash option to git merge 2025-03-29 13:11:35 +01:00
memchr
795d6b6c40 completions/git: add --filter option
supported subcommands:
- clone
- fetch
- submodule update
- rev-list
2025-03-29 13:10:59 +01: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
b2aaf1db52 Rebuild if src changed
From the cargo docs (https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection):

> By default, it takes a conservative approach of always re-running the build script if any file within the package is changed (or the list of files controlled by the exclude and include fields). For most cases, this is not a good choice, so it is recommended that every build script emit at least one of the rerun-if instructions (described below). If these are emitted, then Cargo will only re-run the script if the given value has changed

So, since we emit rerun-if-path-changed, we need to emit *all* the paths.
Failing to do this shows up most visibly as an outdated git version.

Fixes #11332
2025-03-28 18:29:23 +01:00
Johannes Altmanninger
f127323c33 Prevent commandline modification inside abbreviation callbacks
Consider command line modifications triggered from fish script via abbreviation
expansion:

	function my-abbr-func
	    commandline -r ""
	    echo expanded
	end
	abbr -a foo --function my-abbr-func

Prior to commit 8386088b3d (Update commandline state changes eagerly as well,
2024-04-11), we'd silently ignore the command line modification.
This is because the abbreviation machinery runs something similar to

	if my-abbr-func
	    commandline -rt expanded
	end

except without running "apply_commandline_state_changes()" after
"my-abbr-func", so the «commandline -r ""» update is lost.

Commit 8386088b3d applies the commandline change immediately in the abbrevation
function callback, invalidating abbrevation-expansion state.

The abbreviation design does not tell us what should happen here.  Let's ignore
commandline modifications for now. This mostly matches historical behavior.

Unlike historical behavior we also ignore modifications if the callback fails:

	function my-abbr-func
	    commandline -r ""
	    false
	end

Remove the resulting dead code in editable_line.

See #11324

(cherry picked from commit 11c7310f17)
2025-03-28 13:05:22 +01:00
Fabian Boehm
3fc245d829 docs: Readd bind -k to the docs
Fixes #11329

(cherry picked from commit d88f5ddbaf)
2025-03-28 12:59:44 +01:00
Johannes Altmanninger
11c7310f17 Prevent commandline modification inside abbreviation callbacks
Consider command line modifications triggered from fish script via abbreviation
expansion:

	function my-abbr-func
	    commandline -r ""
	    echo expanded
	end
	abbr -a foo --function my-abbr-func

Prior to commit 8386088b3d (Update commandline state changes eagerly as well,
2024-04-11), we'd silently ignore the command line modification.
This is because the abbreviation machinery runs something similar to

	if my-abbr-func
	    commandline -rt expanded
	end

except without running "apply_commandline_state_changes()" after
"my-abbr-func", so the «commandline -r ""» update is lost.

Commit 8386088b3d applies the commandline change immediately in the abbrevation
function callback, invalidating abbrevation-expansion state.

The abbreviation design does not tell us what should happen here.  Let's ignore
commandline modifications for now. This mostly matches historical behavior.

Unlike historical behavior we also ignore modifications if the callback fails:

	function my-abbr-func
	    commandline -r ""
	    false
	end

Remove the resulting dead code in editable_line.

See #11324
2025-03-28 12:58:15 +01:00
Fabian Boehm
d88f5ddbaf docs: Readd bind -k to the docs
Fixes #11329
2025-03-27 15:56:09 +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
542793a534 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

(cherry picked from commit 360cfdb7ae)
2025-03-25 11:16:38 +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
memchr
5012bcb976 completions/cryptsetup: complete device mapping names
The commands 'close', 'resize', and 'status' each take 'name' as their solo argument.

Signed-off-by: memchr <memchr@proton.me>
2025-03-24 18:43:38 +01:00
memchr
3744c02a01 completions/systemd-analyze: add new options and subcommands
options:
- instance
- image
- image-policy
- tldr
- unit
- table
- no-legend
- detailed
- scale-svg
- malloc

subcommands:
- filesystems
- compare-versions
- inspect-elf
- fdstore
- has-tpm2
- pcrs
- srk
- architectures
- smbios11

fix a typo in timespan completion

Signed-off-by: memchr <memchr@proton.me>
2025-03-24 18:43:30 +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
Johannes Altmanninger
c2121b5a8d Move issue template following GitHub breaking change
We can no longer have a single template that is always inserted. Instead
the web UI shows a menu allowing to select between one of our templates and
a blank one.
2025-03-22 14:09:39 +01:00
Benjamin A. Beasley
a5adb362b0 Update lru to 0.13.0 2025-03-22 13:33:18 +01:00
Clément Martinez
ea8e122fad Add wlr-randr completions 2025-03-22 13:06:01 +01:00
Johannes Altmanninger
66115490d8 Use the cache directory owner for cache entries
Commit f086bc9564 (Maintain ownership when rewriting universal variables
file, 2015-09-26) fixed an issue where "sudo -E fish" would create root-owned
~/.config/fish/fish_variables that break the users's shell.

A simlar issue exists for files in ~/.cache/fish; fix that.

Note that ~/.cache/fish is currently created on first run when we generate
completions from manpages.

See the issue described in #11292
2025-03-21 10:41:39 +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
Johannes Altmanninger
17c072b4bf Fix command highlighting applying underline to trailing spaces
We incorrectly apply highlighting to trailing spaces that follow a command
or argument. This surfaces when the highlighting includes underline, which
is visible even on space characters.

Fix this by and have Claude add a unit test.

Co-Authored-By: Claude <noreply@anthropic.com>

Fixes #11265
2025-03-21 00:40:33 +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
Johannes Altmanninger
18c231de29 Fix concurrent setlocale() in string escape tests
In our C++ implementation, these tests were run serially.  As pointed out in
https://github.com/fish-shell/fish-shell/issues/11254#issuecomment-2735623229
we run them in parallel now, which means that one test could be changing
the global locale used by another.

In theory this could be fine because all tests are setting setting the
global locale to the same thing but the existence of a lock suggests that
setlocale() is not guaranteed to be atomic, so it's possible that another
thread uses a temporarily-invalid locale.

Fixes #11254

(cherry picked from commit 1d78c8bd42)
2025-03-19 09:46:12 +01:00
Johannes Altmanninger
1d78c8bd42 Fix concurrent setlocale() in string escape tests
In our C++ implementation, these tests were run serially.  As pointed out in
https://github.com/fish-shell/fish-shell/issues/11254#issuecomment-2735623229
we run them in parallel now, which means that one test could be changing
the global locale used by another.

In theory this could be fine because all tests are setting setting the
global locale to the same thing but the existence of a lock suggests that
setlocale() is not guaranteed to be atomic, so it's possible that another
thread uses a temporarily-invalid locale.

Fixes #11254
2025-03-19 09:45:51 +01:00
Johannes Altmanninger
8e78857836 Fix Vi mode delete key bindings while numlock is active
Commit 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30)
add bindings that obsolete the  terminfo-based `bind -k` invocations.

The `bind -k` variants were still left around[^*]. Unfortunately it forgot to
add the new syntax for some special keys in Vi mode.  This leads to issues if
a terminal that supports the kitty keyboard protocol sends an encoding that
differs from the traditional one.  As far as I can tell, this happens when
capslock or numlock is active.  Let's add the new key names and consistently
mark `bind -k` invocations as deprecated.

Fixes #11303

[^*]: Support for `bind -k` will probably be removed in a future release -
it leads to issues like https://github.com/fish-shell/fish-shell/issues/11278
where it's better to fail early.

(cherry picked from commit 733f704267)
2025-03-19 09:27:29 +01:00
Johannes Altmanninger
733f704267 Fix Vi mode delete key bindings while numlock is active
Commit 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30)
add bindings that obsolete the  terminfo-based `bind -k` invocations.

The `bind -k` variants were still left around[^*]. Unfortunately it forgot to
add the new syntax for some special keys in Vi mode.  This leads to issues if
a terminal that supports the kitty keyboard protocol sends an encoding that
differs from the traditional one.  As far as I can tell, this happens when
capslock or numlock is active.  Let's add the new key names and consistently
mark `bind -k` invocations as deprecated.

Fixes #11303

[^*]: Support for `bind -k` will probably be removed in a future release -
it leads to issues like https://github.com/fish-shell/fish-shell/issues/11278
where it's better to fail early.
2025-03-19 09:23:07 +01:00
kekeimiku
841687a1af iOS initial support
Usage:

	IPHONEOS_DEPLOYMENT_TARGET="13.1 cargo build --target aarch64-apple-ios --release
	codesign -d -s - --entitlements build_tools/ios_entitlements.xml target/aarch64-apple-ios/release/fish

Closes #10993
2025-03-18 22:25:55 +01:00
5225225
039df1c7c7 Fix all current rustdoc warnings (apart from mentioning private items) 2025-03-18 22:25:24 +01:00
Fabian Boehm
c7efbf590e 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

(cherry picked from commit d203ee4d53)
2025-03-17 19:55:25 +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
Ilya Grigoriev
932010cd04 jj completions: use dynamic completions by default, also fix
This uses jj's dynamic completions when possible.

This avoids an annoying problem. After 04a4e5c4, jj's dynamic
completions (see the second paragraph of
<https://jj-vcs.github.io/jj/latest/install-and-setup/#command-line-completion>)
do not work very well in fish if the user puts `COMPLETE=fish jj |
source` in their `~/.config/fish/config.fish`. When the user types `jj
<TAB>`, they are instead overridden by fish's built-in non-dynamic
completions.

The difference is subtle. One problem I saw is that `jj new <TAB>` works
as expected (and shows revisions) while `jj new -A <TAB>` becomes broken
(and shows files).

If the user puts `COMPLETE=fish jj | source` in
`~/.config/fish/completions/jj.fish` there is no problem. However, users
might be confused if they run `COMPLETE=fish jj | source` or put it in
their config and it works in a broken fashion. I certainly was.

Meanwhile, I checked that if the user has `jj completion fish | source`
in their `config.fish`, executing `COMPLETE=fish jj
__this_command_does_not_exist | source` afterwards still works
correctly.

Let me know if there's a better approach to this problem.
2025-03-17 19:06:48 +01:00
Fabian Boehm
5771085280 CHANGELOG 2025-03-16 19:15:28 +01:00
Fabian Boehm
76d2419228 Downgrade $TERM warnings to a term-support flog
The chances that xterm-256color breaks anything are miniscule.

In the features we use, there are basically no differences,
especially when you consider that we decode keys independently.

E.g. tmux-256color has differences, but they are either just taste
questions (xterm's clear_screen will also clear scrollback),
or they're just... not actually different?

Terminfo will claim that it uses a different cursor_up and
exit_attribute_mode, but it also understands the xterm ones,
and it sends a different key_home,
but we decode that even with TERM=xterm-256color.

In some cases, terminfo is also just outright *wrong* and will claim
something does not support italics when it does.

So, since the differences are very likely to simply not matter,
throwing a warning is more confusing than it is helpful.

(cherry picked from commit 642ec399ca)
2025-03-16 18:50:46 +01:00
Fabian Boehm
642ec399ca Downgrade $TERM warnings to a term-support flog
The chances that xterm-256color breaks anything are miniscule.

In the features we use, there are basically no differences,
especially when you consider that we decode keys independently.

E.g. tmux-256color has differences, but they are either just taste
questions (xterm's clear_screen will also clear scrollback),
or they're just... not actually different?

Terminfo will claim that it uses a different cursor_up and
exit_attribute_mode, but it also understands the xterm ones,
and it sends a different key_home,
but we decode that even with TERM=xterm-256color.

In some cases, terminfo is also just outright *wrong* and will claim
something does not support italics when it does.

So, since the differences are very likely to simply not matter,
throwing a warning is more confusing than it is helpful.
2025-03-16 18:50:36 +01:00
Johannes Altmanninger
ffbf957fa3 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

(cherry picked from commit 9f79fe17fc)
2025-03-16 12:12:03 +01:00
Peter Ammon
a0a6edd303 Remove Rc from line_counter
We no longer need this.
2025-03-15 16:43:17 -07:00
Peter Ammon
d1c7e8d96f Make ScopeGuard invoke its function by value
No need for &mut here.
2025-03-15 16:43:17 -07:00
Peter Ammon
a9837a3cbf Remove scoped_push and friends
These are now unused because of the recent migration to scoped cell types.
2025-03-15 16:43:17 -07:00
Peter Ammon
7f8e773b4d Use the new scoped machinery for the current filename 2025-03-15 16:43:17 -07:00
Peter Ammon
6eb9b60250 Refactor wildcard expansion state
Prior to this commit, the WildCardExpander had one scoped variable, leading to
the annoying "zelf" pattern. Factor this into its own object and pass it around
explicitly, to clean this up.
2025-03-15 16:43:17 -07:00
Peter Ammon
e0953cac41 Use new scoped types for line_counter and caller_id 2025-03-15 16:43:17 -07:00
Peter Ammon
adde79259b Move the eval_level into the Parser scoped data
Clean up some ugly atomic stuff.
2025-03-15 16:43:17 -07:00
Peter Ammon
29ae571afa Make scoped_push nicer
In C++ it's easy to make an RAII-type object like "increment a counter for
the duration of this function." Such an object might accept a pointer or
reference, increment the value, and then restore it in its destructor. We
do this all the time - for example to mark a region of code as
non-interactive, etc.

Rust makes this more awkward, because now the reference is tracked by the
borrow checker: it "owns" the object for the duration of the function. This
leads to approaches like "zelf" where the object that marks the parser as
non-interactive itself becomes the new parser, but we can't call it "self"
and it's just yucky.

In this commit we introduce a notion of the "scoped data" of the Parser,
factored out of the library data. This is data which is typically set in a
scoped fashion: whether we are a subshell, are interactive, emit fish_trace
debugging info, etc. Crucially we set this as Rc: this allow the scope
itself to share data with the Parser and we can get rid of lots of "zelf"s.

Introduce a new function `Parser::push_scope` which creates a new scope and
allows modifying these variables associated with the scope. This ends up as
a nice simplification.
2025-03-15 16:43:16 -07:00
Peter Ammon
2930466d53 Introduce ScopedCell and ScopedRefCell
As part of a plan to overhaul the "scoped_set" pattern, introduce two new
"scoped" types:

ScopedCell is a trivial wrapper around Cell which exposes a function
`scoped_mod`. This allows you to modify the contents of the Cell; the
original contents are restored when the guard is dropped.

ScopedRefCell is similar, except it requires the caller to supply an
accessor which returns a &mut field, and also the new value.

These will be used to replace the rather unsightly scoped_push calls
around the fish codebase.
2025-03-15 16:40:31 -07:00
Peter Ammon
a296ee085c Stop returning a value from ScopeGuarding::commit
This was unused outside of the tests.
2025-03-15 16:40:31 -07:00
Peter Ammon
0113db3ff7 Make parser.libdata.is_event a bool instead of an int
Contrary to the comment, this can and should be a bool.
2025-03-15 16:40:31 -07:00
Peter Ammon
7cc72f1306 Make the transient command line a single value, not a stack
This concerns completions which wrap other completions. For example, if 'tig'
wraps 'git' then for the duration of the git completions, we need to make a fake
("transient") command line which contains "git" and not "tig".

Previously we had a stack of such command lines, but we never inspected anything
except the last element. Make this a single value.
2025-03-15 16:40:31 -07: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
Farhood Etaati
48306409ef Adds git subtree completion
Closes #11063
2025-03-15 21:54:25 +01:00
Johannes Altmanninger
a18680cb53 timer: use write! instead of intermediate format!
See #10937
2025-03-15 21:54:25 +01:00
Sander Machado
f4a8368c9e builtins: idiomatic error code passing
Remaining code smells:
- exec_subshell_internal needs to convert a number to a result

Closes #10948
2025-03-15 21:30:49 +01:00
Ilya Grigoriev
bdb8f7da3a completion/tmux: quick fixup to conflict resolution in b85e405
Delete a line that should have been replaced with the following line (with --keep-order)

Closes #11288
2025-03-15 21:24:17 +01:00
Johannes Altmanninger
f43b16b1cb completions/pulumi: disable update check
As seen in GitHub Actions:

	132/193 Test  #17: check-completions.fish ...................***Failed   16.28 sec
	checks/check-completions.fish..Failure:

	  There were no remaining checks left to match stdout:1:
	    OUTPUT from /home/runner/work/fish-shell/fish-shell/share/completions/pulumi.fish: warning: A new version of Pulumi is available. To upgrade from version '3.154.0' to '3.156.0', visit https://pulumi.com/docs/install/ for manual instructions and release notes.
2025-03-15 21:24:17 +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
Fabian Boehm
19267ce3fc completions/pulumi: Silence stderr
This apparently checks for updates and warns if one is available on
start.

I don't love it.
2025-03-15 12:59:27 +01:00
Ilya Grigoriev
b85e4057bc completions/tmux: show all session panes in pane completions
This makes several changes:

- All panes in the current session are now show, instead of just the
  current window.

- Instead of using window names when referring to panes (e.g.
  "fish-dev.1"), we now use either window indicies ("3.1") or absolute
pane ids (%12). This is mainly because several windows often share the
same window name, e.g. many of my panes are automatically named "fish"
if they are currently running the shell and nothing else.

  I put the window names in the descriptions. Because fish uses the
descriptions for completions, completing `fish-dev` is still helpful.

- I include the pane name into the description for a similar reason,
  truncated to 15 chars.

- The panes are now ordered carefully, with panes in this window listed
  first, then panes are ordered by window, and finally panes are listed
by their id (which does not change when panes are moved between windows)

Example output after `tmux selectp -t <TAB>` for a session with a few
windows. Note that windows 0, 1, and 4 are all named
`fish`. A pane in the current window can be accessed in 3 ways: `3`,
`2.3`, or `%57`.


```
0         (%4 [fish-dev] ~/d/fish-shell <active pane>)  3.1                    (%58 [fish] man tmux ~/.c/f...)
1     (%8 [fish-dev] hwatch "jj.logs... <active win.>)  4.0                     (%1 [sshd] tmux rename-win...)
2    (%15 [fish-dev] /U/i/d/fish-she... <active win.>)  %1                     (4.0 [sshd] tmux rename-win...)
3        (%57 [fish-dev] ~/d/fish-shell <active win.>)  %4       (2.0 [fish-dev] ~/d/fish-shell <active pane>)
0.0                                    (%100 [fish] ~)  %8   (2.1 [fish-dev] hwatch "jj.logs... <active win.>)
1.0                         (%11 [fish] ~/d/_/nixpkgs)  %11                         (1.0 [fish] ~/d/_/nixpkgs)
1.1                    (%38 [fish] ~/.c/f/completi...)  %15  (2.2 [fish-dev] /U/i/d/fish-she... <active win.>)
2.0       (%4 [fish-dev] ~/d/fish-shell <active pane>)  %38                    (1.1 [fish] ~/.c/f/completi...)
2.1   (%8 [fish-dev] hwatch "jj.logs... <active win.>)  %41                         (3.0 [fish] ~/.c/f/conf.d)
2.2  (%15 [fish-dev] /U/i/d/fish-she... <active win.>)  %57      (2.3 [fish-dev] ~/d/fish-shell <active win.>)
2.3      (%57 [fish-dev] ~/d/fish-shell <active win.>)  %58                    (3.1 [fish] man tmux ~/.c/f...)
3.0                         (%41 [fish] ~/.c/f/conf.d)  %100                                    (0.0 [fish] ~)
```

Compared to before:

```
0  (pane)  2  (pane)  0:fish-dev.0  (session:window.pane)  0:fish-dev.2  (session:window.pane)  fish-dev  (window)
1  (pane)  3  (pane)  0:fish-dev.1  (session:window.pane)  0:fish-dev.3  (session:window.pane)
```

Note that the "before" version describes the same 3 panes several times
in a row, and all the entries involving "fish-dev" are suspect since
there could be another "fish-dev" window (or, more likely, this window
and others could all be named "fish").

Closes #11115
2025-03-15 12:30:00 +01:00
Ilya Grigoriev
f30a85f538 completions/tmux: more send-keys completions, add switch-client key table argument
The switch client option is a bit weird (why does this command have a
key table-related function?), but seems helpful to add.
2025-03-15 12:27:20 +01:00
Ilya Grigoriev
5fecc2e355 completions/tmux: fixups to key table commands, update to post-2017 tmux
There are some minor updates.

Also, the syntax seems to have changed in tmux 2.4 in 2017,
ef68debc8d/CHANGES (L1484)

Notably, many of the key table commands now use `-T` in place of
the correct `-t`, and the list of key binding tables has changed.
2025-03-15 12:27:20 +01:00
Yann Soubeyrand
052a010b57 feat(completions): add argocd, cue, dagger, kubebuilder and pulumi
These tools use the Cobra framework for argument parsing, which can
generate completions ready to be sourced.
2025-03-15 12:27:14 +01:00
lengyijun
517b02899a doc: bind ctrl-c clear-commandline 2025-03-15 10:58:34 +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
ae3532e9ec screen: Fix crash if prompt contains backspace
fish_wcwidth_visible can return -1, so usize::try_from fails.

Fixes #11280

(cherry picked from commit c03de2086a)
2025-03-14 20:19:49 +01:00
Fabian Boehm
5cd2ef903a key: Add super modifier
Fixes #11217

(cherry picked from commit 9f5e1736a8)
2025-03-14 20:19:49 +01:00
Fabian Boehm
c03de2086a screen: Fix crash if prompt contains backspace
fish_wcwidth_visible can return -1, so usize::try_from fails.

Fixes #11280
2025-03-14 16:23:33 +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
Fabian Boehm
7224776f80 staticbuilds: Build fish_indent/key_reader binaries to test 2025-03-13 16:38:21 +01:00
Fabian Boehm
6d93e6324a staticbuilds: Rename files
Use x86_64 instead of amd64 because that's what uname calls it,
and try to get the version in there.
2025-03-13 16:32:41 +01:00
David Adam
1477bf7a54 CHANGELOG: fix formatting 2025-03-13 15:48:52 +08:00
David Adam
298d79ef58 CHANGELOG: actually #10838 is out entirely 2025-03-13 12:04:15 +08:00
David Adam
3a86f8e6c7 CHANGELOG: correct version that #10838 is in 2025-03-13 12:01:14 +08:00
David Adam
a1b50b1a0e Merge branch 'Integration_4.0.1' 2025-03-13 12:00:31 +08:00
David Adam
67b6afffd4 Release 4.0.1 2025-03-13 11:16:55 +08:00
David Adam
6df88e1a9f CHANGELOG: work on 4.0.1 2025-03-13 10:59:58 +08:00
David Adam
f8202408f9 cmake: specify MSRV 2025-03-13 10:47:47 +08:00
Johannes Altmanninger
61884bda36 Fix GitHub Actions build now that images come with ninja
Looks like the github actions image now has ninja installed.
This causes a failure; we effectively do

	$ (
		mkdir build && cd build
		cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
	  )
	$ make VERBOSE=1
	[...]
	cd build; cmake .. -G "Ninja" \
		-DCMAKE_INSTALL_PREFIX="/usr/local" -DCMAKE_EXPORT_COMPILE_COMMANDS=1
	Re-run cmake no build system arguments
	CMake Error: Error: generator : Ninja
	Does not match the generator used previously: Unix Makefiles
	Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

"make" fails because it runs from top-level, with GNUMakefile's logic to
use -GNinja if available.  This is at odds with the direct cmake invocation,
which defaults to -G'Unix Makefiles'.

We shouldn't mix direct cmake invocation and the top-level Makefiles, so
run make from the build directory instead.

While at it, update some test invocations missed in 8d6fdfd9de
(Remove cmake "test" target, 2025-02-02).  This should
help avoid missing test failure output in CI, see
https://github.com/fish-shell/fish-shell/issues/11116#issuecomment-2629406479

(cherry picked from commit b0be53ed6a)
2025-03-13 10:36:28 +08:00
David Adam
66584dadcc CHANGELOG: work on 4.0.1 2025-03-12 23:28:29 +08:00
Johannes Altmanninger
d2cf002e64 Note that only rustup<=1.27 works OOTB for bisecting
See b38551dde9 (Drag FindRust.cmake back into the land of the living,
2025-03-05).
2025-03-12 08:40:44 +01:00
David Adam
5944518e6e docs/fish_title: add example on disabling title changing
Work on #11241.

(cherry picked from commit 3c8e058b75)
2025-03-12 14:39:33 +08:00
David Adam
3c8e058b75 docs/fish_title: add example on disabling title changing
Work on #11241.
2025-03-12 14:36:40 +08:00
Johannes Altmanninger
19502ff9e7 Add hack to fix off-by-one error in Vi-mode cancel-commandline
The new cursor-end-mode "inclusive" (which is active in Vi mode) is causing
many issues.

One of them is because cancel-commandline wants to move to the end of the
command line before printing "^C".  Since "inclusive" cursor mode prevents
the cursor from moving past the last character, that one will be overwritten
with a "^".  Hack around this.

Closes #11261

(cherry picked from commit b08ff33291)
2025-03-11 20:24:04 +01:00
Johannes Altmanninger
b08ff33291 Add hack to fix off-by-one error in Vi-mode cancel-commandline
The new cursor-end-mode "inclusive" (which is active in Vi mode) is causing
many issues.

One of them is because cancel-commandline wants to move to the end of the
command line before printing "^C".  Since "inclusive" cursor mode prevents
the cursor from moving past the last character, that one will be overwritten
with a "^".  Hack around this.

Closes #11261
2025-03-11 20:23:30 +01:00
Johannes Altmanninger
5b94af6367 Restore cursor shape when deactivating Vi mode
Running

	fish_vi_key_bindings
	fish_default_key_bindings

ought to maintain cursor shape, at least in the default configuration,
so let's do that.

Fixes 9ef76860e6 (Default Vi cursor shapes for insert/replace mode, 2024-10-26).
2025-03-11 20:22:27 +01:00
lengyijun
18c4ee4b41 cleanup: rm strange code block 2025-03-11 20:01:49 +01:00
Johannes Altmanninger
b0be53ed6a Fix GitHub Actions build now that images come with ninja
Looks like the github actions image now has ninja installed.
This causes a failure; we effectively do

	$ (
		mkdir build && cd build
		cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
	  )
	$ make VERBOSE=1
	[...]
	cd build; cmake .. -G "Ninja" \
		-DCMAKE_INSTALL_PREFIX="/usr/local" -DCMAKE_EXPORT_COMPILE_COMMANDS=1
	Re-run cmake no build system arguments
	CMake Error: Error: generator : Ninja
	Does not match the generator used previously: Unix Makefiles
	Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

"make" fails because it runs from top-level, with GNUMakefile's logic to
use -GNinja if available.  This is at odds with the direct cmake invocation,
which defaults to -G'Unix Makefiles'.

We shouldn't mix direct cmake invocation and the top-level Makefiles, so
run make from the build directory instead.

While at it, update some test invocations missed in 8d6fdfd9de
(Remove cmake "test" target, 2025-02-02).  This should
help avoid missing test failure output in CI, see
https://github.com/fish-shell/fish-shell/issues/11116#issuecomment-2629406479
2025-03-11 00:46:41 +01:00
Johannes Altmanninger
e37e1b8f78 Fix regression causing glitches when prompt has control character
Since commit 0627c9d9af (Render control characters as Unicode Control Pictures,
2020-08-29), we render control character in the commandline as "␇" etc.
They can be inserted via either history search, or bindings such as

	bind ctrl-g "commandline -i \a"

That commit incorrectly assumes that the prompt is rendered the same way as
the command line (which goes through "ScreenData" etc).
This is wrong -- prompt text is written to stdout as-is, and a prompt that
outputs \t (tab) or \a (BEL) is valid.  The wrong assumption means that we
overestimate the width of prompts containing control characters.

(For some reason, after switching from Vi insert to Vi normal mode, we seem
to get the width right which means the command line jumps around)

Let's revert to the old width computation for any prompt text.

Closes #11252

(cherry picked from commit 4d81cf8af4)
2025-03-11 00:03:34 +01:00
Johannes Altmanninger
4d81cf8af4 Fix regression causing glitches when prompt has control character
Since commit 0627c9d9af (Render control characters as Unicode Control Pictures,
2020-08-29), we render control character in the commandline as "␇" etc.
They can be inserted via either history search, or bindings such as

	bind ctrl-g "commandline -i \a"

That commit incorrectly assumes that the prompt is rendered the same way as
the command line (which goes through "ScreenData" etc).
This is wrong -- prompt text is written to stdout as-is, and a prompt that
outputs \t (tab) or \a (BEL) is valid.  The wrong assumption means that we
overestimate the width of prompts containing control characters.

(For some reason, after switching from Vi insert to Vi normal mode, we seem
to get the width right which means the command line jumps around)

Let's revert to the old width computation for any prompt text.

Closes #11252
2025-03-11 00:03:12 +01:00
Johannes Altmanninger
5d31be1c3e Fix regression causing crash on empty paste in Vi-mode
Fixes d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

Closes #11256

(cherry picked from commit 2b4f150883)
2025-03-10 22:38:38 +01:00
Johannes Altmanninger
2b4f150883 Fix regression causing crash on empty paste in Vi-mode
Fixes d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

Closes #11256
2025-03-10 22:28:40 +01:00
Johannes Altmanninger
ea6e819a33 completions/set: add fish_cursor_* variables 2025-03-10 22:28:40 +01:00
metamuffin
7a959723ef Print newline on path warnings to stderr instead of stdout (Rust port regression)
(cherry picked from commit 4227f534b4)
2025-03-09 14:13:44 +01:00
metamuffin
4227f534b4 Print newline on path warnings to stderr instead of stdout 2025-03-09 14:12:32 +01:00
Peter Ammon
7d3b157f13 Allow sprintf! macros to accept format string only
This allows something like `sprintf!("foo")`. Previously this was a compile time
error.

Fixes #11243
2025-03-08 20:26:03 -08:00
Peter Ammon
ad0feab86c Fix a Sphinx warning 2025-03-08 10:53:06 -08:00
Peter Ammon
2ecd0d011b Fix some clipplies 2025-03-08 10:52:27 -08:00
Johannes Altmanninger
ad7631093d Remove assertion about history items
For unknown reasons this assertion fails.  This means that 1b9b893169 (After
reading corrupted history entry, keep reading older entries, 2024-10-06)
is not fully working.  Go back to historical behavior for now.

Closes #11236

(cherry picked from commit 4f80e5cb54)
2025-03-08 13:14:44 +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
Johannes Altmanninger
4f80e5cb54 Remove assertion about history items
For unknown reasons this assertion fails.  This means that 1b9b893169 (After
reading corrupted history entry, keep reading older entries, 2024-10-06)
is not fully working.  Go back to historical behavior for now.

Closes #11236
2025-03-08 13:12:23 +01:00
Johannes Altmanninger
bd8d268255 Extend midnight commander workaround for when numlock/capslock is active
Midnight Commander 4.8.33 knows how to read the CSI u encoding of ctrl-o
(which is the only key it reads while the shell is in control).  But it fails
to when numlock or capslock is active.  Let's disable the kitty keyboard
protocol again until mc indicates that this is fixed.

Closes #10640

The other issue talked about in that issue is an unrelated mc issue, see
https://github.com/MidnightCommander/mc/issues/4597#issuecomment-2705900024
2025-03-07 12:14:56 +01:00
Niklas Liechti
90218821f9 Split content of *KnownHostsFile as this is a supported config option by ssh. 2025-03-06 21:53:30 -08:00
phanium
6e8d6328ee completions/flatpak: don't ignore packages with uppercase in name (#11230)
* completions/flatpak: don't ignore packages with uppercase in name

`[^A-Z]+` here seems to trim header section in old version flatpak (avoid one
more `tail -n -2`?) but this can ignore packages have uppercase name like
`org.gtk.Gtk3theme.Adwaita-dark`.

* completions/flatpak: use cached `__fish_print_flatpak_packages` for `flatpak install`
2025-03-06 21:39:10 -08:00
Peter Ammon
83f29ed09c Drag FindRust.cmake back into the land of the living
rustup has changed its output for 'rustup toolchain list --verbose`.
Teach FindRust.cmake about it, so that it may shamble on.

Cherry-picked from b38551dde9
2025-03-06 10:05:54 -08:00
Fabian Boehm
aca6836103 CHANGELOG add links 2025-03-06 11:37:19 +01:00
Peter Ammon
cc455ff976 Revert "CI: Disable FreeBSD"
With the prior commit, CMake and rustup can continue to talk to each other, for
now.

This reverts commit b69a1b2ffe.
2025-03-05 22:05:00 -08:00
Peter Ammon
b38551dde9 Drag FindRust.cmake back into the land of the living
rustup has changed its output for 'rustup toolchain list --verbose`.
Teach FindRust.cmake about it, so that it may shamble on.

This was reported against BSD and also affects macOS and ALSO affects Linux; our
CI just doesn't have a new enough rustup. Anyways we can't have nice things.
2025-03-05 21:53:54 -08: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
Peter Ammon
c9f1979b05 Revert "On undo after execute, restore the cursor position"
This reverts commit 815bc054e7.

This is too ambitious for a patch release, given that it affects how every
typed-in command runs.
2025-03-05 15:54:20 -08:00
Peter Ammon
4a35c48ce5 Changelog fix for 11221 2025-03-05 14:11:17 -08:00
Gabriel de Perthuis
f336cf5624 Fix dirent->d_name usage
Closes https://github.com/fish-shell/fish-shell/issues/11221

(cherry picked from commit a0dada5618)
2025-03-05 22:35:01 +01: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
Gabriel de Perthuis
a0dada5618 Fix dirent->d_name usage
Closes https://github.com/fish-shell/fish-shell/issues/11221
2025-03-05 13:29:46 -08:00
Johannes Altmanninger
4ff94b657f __fish_apropos: fixup broken macOS version check
Due to the parens, this prints the version twice.  Fixes 49023adec7
(Consolidate some calls to uname(1) around shell startup, 2025-03-05).
2025-03-05 14:30:06 +01:00
Johannes Altmanninger
1504731d53 Backout new assertion to support old Rust
error[E0015]: cannot call non-const fn `zeroed::<libc::statfs>` in constants
	   --> src/path.rs:712:35
	    |
	712 |             let f_type = unsafe { mem::zeroed::<libc::statfs>() }.f_type;
	    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	    |
	    = note: calls in constants are limited to constant functions, tuple structs and tuple variants

	error: `std::mem::size_of_val` is not yet stable as a const fn
	   --> src/path.rs:713:13
	    |
	713 |             mem::size_of_val(&f_type) <= mem::size_of::<usize>()
	    |             ^^^^^^^^^^^^^^^^^^^^^^^^^

(cherry picked from commit 54f9778003)
2025-03-05 13:02:53 +01:00
Johannes Altmanninger
54f9778003 Backout new assertion to support old Rust
error[E0015]: cannot call non-const fn `zeroed::<libc::statfs>` in constants
	   --> src/path.rs:712:35
	    |
	712 |             let f_type = unsafe { mem::zeroed::<libc::statfs>() }.f_type;
	    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	    |
	    = note: calls in constants are limited to constant functions, tuple structs and tuple variants

	error: `std::mem::size_of_val` is not yet stable as a const fn
	   --> src/path.rs:713:13
	    |
	713 |             mem::size_of_val(&f_type) <= mem::size_of::<usize>()
	    |             ^^^^^^^^^^^^^^^^^^^^^^^^^
2025-03-05 13:02:31 +01:00
Johannes Altmanninger
9dce68fab4 Fix crash on negative stat f_type (Rust-port regression)
Fixes #11219

(cherry picked from commit e5852a6100)
2025-03-05 12:34:59 +01:00
Johannes Altmanninger
49023adec7 Consolidate some calls to uname(1) around shell startup
Most versions of fish don't run any external processes at startup, except
maybe fish_vcs_prompt.  This changed recently with a couple additions of uname.
This is probably fine but I guess we can reduce it down to one.

This change feels somewhat wrong. Not sure.  I guess we can remove it once
we provide $OSTYPE.

Note that this is also the reason why bindings don't use

	bind alt-backspace 'if test "$(uname)" = Darwin ...'

We don't want to expose a private interface in "bind" output.
2025-03-05 12:34:17 +01:00
Johannes Altmanninger
ce40229da6 Fix broken macOS major version detection regex
Not that it matters in practice but this is broken for version 100.
Reduce the surprise.
2025-03-05 12:28:48 +01:00
Johannes Altmanninger
8d8d25ff45 completions/bind: add super modifier 2025-03-05 12:28:48 +01:00
Johannes Altmanninger
e5852a6100 Fix crash on negative stat f_type (Rust-port regression)
Fixes #11219
2025-03-05 12:28:48 +01:00
m1kc (Max Musatov)
db4c999272 De-duplicate install code in fish.rs 2025-03-04 21:44:44 -08:00
Fabian Boehm
b69a1b2ffe CI: Disable FreeBSD
This fails with:

```
CMake Warning (dev) at cmake/FindRust.cmake:349 (message):
  Unexpected output from `rustc --version` for Toolchain
  `stable-x86_64-unknown-freebsd`: ``.

  Ignoring this toolchain.
Call Stack (most recent call first):
  cmake/Rust.cmake:5 (include)
  CMakeLists.txt:24 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Rust Toolchain:
CMake Warning at cmake/FindRust.cmake:31 (message):
  The rustc executable was not found.  Rust not installed or ~/.cargo/bin not
  added to path?

  Hint: Consider setting `Rust_COMPILER` to the absolute path of `rustc`.
```

For some reason? Disable it for now until someone figures out what's
going on
2025-03-04 17:01:27 +01:00
Fabian Boehm
9f5e1736a8 key: Add super modifier
Fixes #11217
2025-03-04 17:00:26 +01:00
nicole
b3ff27b089 completions/emacs: add completion for argumnet: "--init-directory" (#11165) 2025-03-04 11:56:09 +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
lengyijun
67e95a1ce7 clippy: remove redundant .collect::<Vec<_>>()
Closes #11214
2025-03-04 10:31:14 +01:00
Johannes Altmanninger
815bc054e7 On undo after execute, restore the cursor position
Ever since 149594f974 (Initial revision, 2005-09-20), we move the
cursor to the end of the commandline just before executing it.

This is so we can move the cursor to the line below the command line,
so moving the cursor is relevant if one presses enter on say, the
first line of a multi-line commandline.

As mentioned in #10838 and others, it can be useful to restore the
cursor position when recalling commandline from history. Make undo
restore the position where enter was pressed, instead of implicitly
moving the cursor to the end. This allows to quickly correct small
mistakes in large commandlines that failed recently.

This requires a new way of moving the cursor below the command line.
Test changes include unrelated cleanup of history.py.

(cherry picked from commit 610338cc70)
(cherry picked from commit 0e512f8033)
2025-03-04 10:00:33 +01:00
Johannes Altmanninger
b8af4b20c2 Work around torn byte sequences in qemu kbd input with 1ms timeout
As reported on gitter, fish running inside a qemu console randomly fails to
recognize multi-byte sequences like "\e[D" (right); it sometimes recognizes
the first two bytes as "alt-[" and the last byte as the "D" key.

This because 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30) changed
our approach to reading multi-byte key sequences.  Previously, we'd wait
forever (or rather fish_sequence_key_delay_ms) for the "D" byte.

As of  8bf8b10f68, we assume the entire sequence is already present in the
input buffer; and stop parsing the sequence if stdin is not readable.

It would be more technically correct to implement the VT state machine but
then we'd probably want to to figure out a timeout or a reset key, in case
of transport or terminal issues.

Returning early is also what we have historically done for multi-byte code
points.  Also, other terminal programs have been using it for many years
without problems.

I don't know why this happens in qemu but it seems we can work around by
setting a 1ms timeout.  This timeout should be small enough two keys "escape"
and "[" typed by a human will still be seen separate.

Refs:
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$Cfi9wL8FGLAI6_VAQWG2mG_VxsADUPvdPB46P41Jdbs
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$O_-LZ1W7Dk6L_4Rj0MyCry6GtO2JQlEas8fH9PrSYT8

(cherry picked from commit e1be842167)
2025-03-04 10:00:33 +01:00
Johannes Altmanninger
e1be842167 Work around torn byte sequences in qemu kbd input with 1ms timeout
As reported on gitter, fish running inside a qemu console randomly fails to
recognize multi-byte sequences like "\e[D" (right); it sometimes recognizes
the first two bytes as "alt-[" and the last byte as the "D" key.

This because 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30) changed
our approach to reading multi-byte key sequences.  Previously, we'd wait
forever (or rather fish_sequence_key_delay_ms) for the "D" byte.

As of  8bf8b10f68, we assume the entire sequence is already present in the
input buffer; and stop parsing the sequence if stdin is not readable.

It would be more technically correct to implement the VT state machine but
then we'd probably want to to figure out a timeout or a reset key, in case
of transport or terminal issues.

Returning early is also what we have historically done for multi-byte code
points.  Also, other terminal programs have been using it for many years
without problems.

I don't know why this happens in qemu but it seems we can work around by
setting a 1ms timeout.  This timeout should be small enough two keys "escape"
and "[" typed by a human will still be seen separate.

Refs:
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$Cfi9wL8FGLAI6_VAQWG2mG_VxsADUPvdPB46P41Jdbs
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$O_-LZ1W7Dk6L_4Rj0MyCry6GtO2JQlEas8fH9PrSYT8
2025-03-04 09:45:15 +01: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
c06830ccf2 Orphan background tasks to work around terminals being sensitive to unreaped processes
When a command like "long-running-command &" exits, the resulting SIGCHLD
is queued in the topic monitor. We do not process this signal immediately
but only after e.g. the next command has finished. Only then do we reap the
child process.

Some terminals, such as Terminal.app, refuse to close when there are unreaped
processes associated with the terminal -- as in, having the same session ID,
see setsid(3).

In future, we might want to reap proactively.

For now, apply an isolated workaround: instead of taking care of a child
process, double-fork to create an orphaned process. Since the orphan will
be reaped by PID 1, we can eventually close Terminal.app without it asking
for confirmation.

	/bin/sh -c '( "$@" ) >/dev/null 2>&1 &' -- cmd arg1 arg2

This fix confines the problem to the period during which a background process
is running. To complete the fix, we would need to call setsid to detach the
background process from a controlling terminal. That seems to be desirable
however macOS does provide a setsid utility.

	setsid cmd arg1 arg2 >/dev/null 2>&1

Fixes #11181

(cherry picked from commit e015956de7)
2025-03-04 09:18:18 +01:00
Johannes Altmanninger
e015956de7 Orphan background tasks to work around terminals being sensitive to unreaped processes
When a command like "long-running-command &" exits, the resulting SIGCHLD
is queued in the topic monitor. We do not process this signal immediately
but only after e.g. the next command has finished. Only then do we reap the
child process.

Some terminals, such as Terminal.app, refuse to close when there are unreaped
processes associated with the terminal -- as in, having the same session ID,
see setsid(3).

In future, we might want to reap proactively.

For now, apply an isolated workaround: instead of taking care of a child
process, double-fork to create an orphaned process. Since the orphan will
be reaped by PID 1, we can eventually close Terminal.app without it asking
for confirmation.

	/bin/sh -c '( "$@" ) >/dev/null 2>&1 &' -- cmd arg1 arg2

This fix confines the problem to the period during which a background process
is running. To complete the fix, we would need to call setsid to detach the
background process from a controlling terminal. That seems to be desirable
however macOS does provide a setsid utility.

	setsid cmd arg1 arg2 >/dev/null 2>&1

Fixes #11181
2025-03-04 09:16:40 +01:00
Fabian Boehm
f96b9c53ce CHANGELOG for 4.0.1 2025-03-03 21:27:38 +01:00
Johannes Altmanninger
12527d1522 Add back legacy bindings to address modifyOtherKeys regressions in iTerm2<3.5.12
As of 303af07, iTerm2 3.5.11 on two different machines has two different
behaviors. For unknown reasons, when pressing alt-right fish_key_reader
shows "\e\[1\;9C" on one machine and "\e\[1\;3C" on another.

Feels like iTerm2 interprets modifyOtherKeys differently, depending on
configuration.

We don't want to risk asking for the kitty
keyboard protocol until iTerm2 3.5.12 (see
https://github.com/fish-shell/fish-shell/issues/11004#issuecomment-2571494782).

So let's work around around this weirdness by adding back the legacy
bindings removed in c0bcd817ba (Remove obsolete bindings, 2024-04-28) and
plan to remove them in a few years.

Note that fish_key_reader still reports this as "left", which already has
a different binding, but it looks like literal matches of legacy sequences
have precedence.

Fixes the problem described in
https://github.com/fish-shell/fish-shell/issues/11192#issuecomment-2692247060

Closes #11192

(cherry picked from commit 44d5abdc05)
2025-03-03 14:44:49 +01:00
Johannes Altmanninger
46422b6a16 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

(cherry picked from commit 50e595503e)
2025-03-03 14:44:49 +01:00
Johannes Altmanninger
44d5abdc05 Add back legacy bindings to address modifyOtherKeys regressions in iTerm2<3.5.12
As of 303af07, iTerm2 3.5.11 on two different machines has two different
behaviors. For unknown reasons, when pressing alt-right fish_key_reader
shows "\e\[1\;9C" on one machine and "\e\[1\;3C" on another.

Feels like iTerm2 interprets modifyOtherKeys differently, depending on
configuration.

We don't want to risk asking for the kitty
keyboard protocol until iTerm2 3.5.12 (see
https://github.com/fish-shell/fish-shell/issues/11004#issuecomment-2571494782).

So let's work around around this weirdness by adding back the legacy
bindings removed in c0bcd817ba (Remove obsolete bindings, 2024-04-28) and
plan to remove them in a few years.

Note that fish_key_reader still reports this as "left", which already has
a different binding, but it looks like literal matches of legacy sequences
have precedence.

Fixes the problem described in
https://github.com/fish-shell/fish-shell/issues/11192#issuecomment-2692247060

Closes #11192
2025-03-03 14:44:00 +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
97f0809b62 Add the commandline to the OSC 133 command start
Given

	$ cat ~/.config/kitty/kitty.conf
	notify_on_cmd_finish unfocused 0.1 command notify-send "job finished with status: %s" %c

kitty will send a notification whenever a long-running (>.1s) foreground
command finishes while kitty is not focused.

The %c placeholder will be replaced by the commandline.

This is passed via the OSC 133 command start marker, kitty's fish shell
integration.

That integration has been disabled for fish 4.0.0 because it's no longer
necessary since fish already prints OSC 133. But we missed the parameter for
the command string. Fix it.  (It's debatable whether the shell or the terminal
should provide this feature but I think we should fix this regression?)

Closes #11203

See https://github.com/kovidgoyal/kitty/issues/8385#issuecomment-2692659161

(cherry picked from commit 4378e73fc7)
2025-03-03 11:49:43 +01:00
Johannes Altmanninger
d30a2c5240 Try to reduce write(3) calls for OSC 133 prompt markers
Something like

	write!(f, "foo{}bar", ...)

seems to call f.write_str() thrice.

Splitting a single OSC 133 command into three calls to write(3) might result in
odd situations if one of them fails. Let's try to do it in one in most cases.

Add a new buffered output type that can be used with write!(). This is
somewhat redundant given that we have scoped_buffer().  While at it, remove
the confused error handling.  This doesn't fail unless we are OOM (and this
new type makes that more obvious).

(cherry picked from commit e5e932e970)
2025-03-03 11:48:48 +01:00
Johannes Altmanninger
4378e73fc7 Add the commandline to the OSC 133 command start
Given 

	$ cat ~/.config/kitty/kitty.conf
	notify_on_cmd_finish unfocused 0.1 command notify-send "job finished with status: %s" %c

kitty will send a notification whenever a long-running (>.1s) foreground
command finishes while kitty is not focused.

The %c placeholder will be replaced by the commandline.

This is passed via the OSC 133 command start marker, kitty's fish shell
integration.

That integration has been disabled for fish 4.0.0 because it's no longer
necessary since fish already prints OSC 133. But we missed the parameter for
the command string. Fix it.  (It's debatable whether the shell or the terminal
should provide this feature but I think we should fix this regression?)

Closes #11203

See https://github.com/kovidgoyal/kitty/issues/8385#issuecomment-2692659161
2025-03-03 11:47:50 +01:00
Johannes Altmanninger
e5e932e970 Try to reduce write(3) calls for OSC 133 prompt markers
Something like

	write!(f, "foo{}bar", ...)

seems to call f.write_str() thrice.

Splitting a single OSC 133 command into three calls to write(3) might result in
odd situations if one of them fails. Let's try to do it in one in most cases.

Add a new buffered output type that can be used with write!(). This is
somewhat redundant given that we have scoped_buffer().  While at it, remove
the confused error handling.  This doesn't fail unless we are OOM (and this
new type makes that more obvious).
2025-03-03 11:47:50 +01:00
Johannes Altmanninger
335462697e Remove obsolete clippy suppression
Missed this in b6269438e9.
2025-03-03 11:46:39 +01:00
Johannes Altmanninger
7ee6d91ba0 Work around keyboard-layout related bugs in WezTerm's modifyOtherKeys
modifyOtherKeys with non-English or other non-default keyboard layouts will
cause wrong keys to be sent by WezTerm. Let's try to disable it for now.

Proposed upstream fix: https://github.com/wezterm/wezterm/pull/6748

Closes #11204
2025-03-03 10:13:37 +01:00
Johannes Altmanninger
a94c4e96ab Split /etc/{,man}path by colons too
I don't know how /etc/manpath ends up containing lines like
"path1:path2".  But path_helper splits them so we should do too.

4ea11424b8/path_helper/path_helper.c (L149)

Fixes #10684

(cherry picked from commit 95d61ea0fb)
2025-03-02 22:21:03 +01:00
Peter Ammon
76923de6cf Suppress a dumb clipply 2025-03-02 12:14:14 -08:00
Fabian Boehm
e767bb623f completions/wine: Complete files
wine can be used, and is usually used for things like `wine
setup.exe`,
so it should allow for regular file completion.

Fixes #11202

(cherry picked from commit 86e531b848)
2025-03-02 13:09:57 +01:00
Fabian Boehm
86e531b848 completions/wine: Complete files
wine can be used, and is usually used for things like `wine
setup.exe`,
so it should allow for regular file completion.

Fixes #11202
2025-03-02 13:07:57 +01:00
Fabian Boehm
e0dd983c49 sample_prompts/acidhub: Use the same branch logic as fish_git_prompt
This was broken for 4.0 because it used `{}` command grouping.

Instead just do one of the things the fish_git_prompt does.

(the default isn't usable here because it gets the sha from elsewhere)

(cherry picked from commit e925eccad2)
2025-03-02 12:32:34 +01:00
Fabian Boehm
9dd1f6b634 Release 4.1.0-alpha0 2025-03-02 12:32:29 +01:00
Fabian Boehm
e925eccad2 sample_prompts/acidhub: Use the same branch logic as fish_git_prompt
This was broken for 4.0 because it used `{}` command grouping.

Instead just do one of the things the fish_git_prompt does.

(the default isn't usable here because it gets the sha from elsewhere)
2025-03-02 12:30:29 +01:00
Johannes Altmanninger
200eeffeee sample_prompts/acidhub: fix regression showing all branches
Fix the accidental "git branch" output leaking while making sure we support:
1. unborn branch, where HEAD does not exist (`git init`)
2. detached head (`git checkout --detach`)

Notably computing the branch name should be independent of computing
a diff against HEAD.
In scenario 1 there is a branch but no HEAD,
while in scenario 2 it's the other way round.

Hence we need a separate check to see if we're in a git repo.
"git rev-parse" seems to work. Not sure what's best pracitce.

Also remove the ahead/behind logic, it was broken because it misspelled
@{upstream}.

Fixes #11179

(cherry picked from commit 7b7e744353)
2025-03-02 11:48:17 +01:00
Johannes Altmanninger
7b7e744353 sample_prompts/acidhub: fix regression showing all branches
Fix the accidental "git branch" output leaking while making sure we support:
1. unborn branch, where HEAD does not exist (`git init`)
2. detached head (`git checkout --detach`)

Notably computing the branch name should be independent of computing
a diff against HEAD.
In scenario 1 there is a branch but no HEAD,
while in scenario 2 it's the other way round.

Hence we need a separate check to see if we're in a git repo.
"git rev-parse" seems to work. Not sure what's best pracitce.

Also remove the ahead/behind logic, it was broken because it misspelled
@{upstream}.

Fixes #11179
2025-03-02 11:46:58 +01:00
Jay
0d453039ac fix unknown command __fish_diskutil_volumes
Signed-off-by: Jay <BusyJay@users.noreply.github.com>
(cherry picked from commit c790b1051d)
2025-03-02 11:04:16 +01:00
Jay
c790b1051d fix unknown command __fish_diskutil_volumes
Signed-off-by: Jay <BusyJay@users.noreply.github.com>
2025-03-02 11:03:43 +01:00
Johannes Altmanninger
044afefc5c 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.

(cherry picked from commit 495083249b)
2025-03-02 09:34:51 +01:00
Johannes Altmanninger
5cce0918a9 completions/status: break up long line, add buildinfo
(cherry picked from commit 5278686f55)
2025-03-02 09:34:51 +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
5278686f55 completions/status: break up long line, add buildinfo 2025-03-02 09:34:06 +01:00
Peter Rice
d1bb4503d6 edit_command_buffer: pass cursor position to helix 2025-03-02 07:27:06 +01:00
Johannes Altmanninger
3a673aff63 Apply fish_color_search_match foreground only if explicit
Historically, up-arrow search matches have been highlighted by

1. using the usual foreground (from syntax highlighting)
2. using the background from $fish_color_search_match

Commit 9af6a64fd2 (Fix bad contrast in search match highlighting, 2024-04-15)
broke this by also applying the foreground from $fish_color_search_match.

As reported on gitter, there is a meaningful scenario where the foreground
from syntax highlighting should not be overwritten:

	set fish_color_search_match --reverse

this copies the foreground from syntax highlighting to the background.

Since commit 9af6a64fd2 overwrites the foreground highlight, the resulting
background will be monocolored (black in my case) instead of whatever is
the syntax-colored foreground.

FWIW the reversed foreground will always be monocolored, because we have
always done 2.

Let's unbreak this scenario by using the foreground from
fish_color_search_match only if it's explicitly set (like we do since
9af6a64fd2).

This is hacky because an empty color is normally the same as "normal", but
it gets us closer to historical behavior. In future we should try to come
up with a better approach to color blending/transparency.

(cherry picked from commit b6269438e9)
2025-03-02 07:09:44 +01:00
Johannes Altmanninger
b6269438e9 Apply fish_color_search_match foreground only if explicit
Historically, up-arrow search matches have been highlighted by

1. using the usual foreground (from syntax highlighting) 
2. using the background from $fish_color_search_match

Commit 9af6a64fd2 (Fix bad contrast in search match highlighting, 2024-04-15)
broke this by also applying the foreground from $fish_color_search_match.

As reported on gitter, there is a meaningful scenario where the foreground
from syntax highlighting should not be overwritten:

	set fish_color_search_match --reverse

this copies the foreground from syntax highlighting to the background.

Since commit 9af6a64fd2 overwrites the foreground highlight, the resulting
background will be monocolored (black in my case) instead of whatever is
the syntax-colored foreground.

FWIW the reversed foreground will always be monocolored, because we have
always done 2.

Let's unbreak this scenario by using the foreground from
fish_color_search_match only if it's explicitly set (like we do since
9af6a64fd2).

This is hacky because an empty color is normally the same as "normal", but
it gets us closer to historical behavior. In future we should try to come
up with a better approach to color blending/transparency.
2025-03-02 07:08:30 +01:00
Johannes Altmanninger
880aa479bf Work around Konsole not recognizing file:://$hostname/path as local
(This regressed in version 4 which sends OSC 7 to all terminals)

Konsole has a bug: it does not recognize file:://$hostname/path as directory.
When we send that via OSC 7, that breaks Konsole's "Open Folder With"
context menu entry.

OSC 7 producers are strongly encouraged to set a non-empty hostname, but
it's not clear if consumers are supposed to accept an empty hostname (see
https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20).
I think it should be fine; implementations should treat it as local path.

Let's work around the Konsole bug by omitting the hostname for now. This
may not be fully correct when using a remote desktop tool to access a
system running Konsole but I guess that's unlikely and understandable.
We're using KONSOLE_VERSION, so it the workaround should not leak into SSH
sessions where a hostname component is important.

Closes #11198

Proposed upstream fix https://invent.kde.org/frameworks/kio/-/merge_requests/1820

(cherry picked from commit c926a87bdb)
2025-03-02 05:47:00 +01:00
Johannes Altmanninger
c926a87bdb Work around Konsole not recognizing file:://$hostname/path as local
Konsole has a bug: it does not recognize file:://$hostname/path as directory.
When we send that via OSC 7, that breaks Konsole's "Open Folder With"
context menu entry.

OSC 7 producers are strongly encouraged to set a non-empty hostname, but
it's not clear if consumers are supposed to accept an empty hostname (see
https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20).
I think it should be fine; implementations should treat it as local path.

Let's work around the Konsole bug by omitting the hostname for now. This
may not be fully correct when using a remote desktop tool to access a
system running Konsole but I guess that's unlikely and understandable.
We're using KONSOLE_VERSION, so it the workaround should not leak into SSH
sessions where a hostname component is important.

Closes #11198

Proposed upstream fix https://invent.kde.org/frameworks/kio/-/merge_requests/1820
2025-03-02 05:44:36 +01:00
Peter Ammon
692e14ec82 Fix some silly clipply 2025-03-01 13:27:07 -08:00
Johannes Altmanninger
b8934318f3 Harmonize iTerm kitty keyboard feature gating, fix confusingly named flag
As reported in b5736c5535 (Extend iTerm CSI u workaround to < 3.5.12,
2025-02-20), iTerm 3.5.12 has resolved our issues related to the kitty
keyboard protocol. Enable it here too, matching the release branch.

The flag to gate this is set for versions of iTerm that don't have sufficient
support for the kitty keyboard protocol. CSI u is (more or less) the encoding
used by that protocol.  Let's name things accordingly. My bad.
2025-03-01 16:20:37 +01:00
Johannes Altmanninger
fe7f13e5ad Fix fish_key_reader regression causing kitty protcol not being requested
Commit 2d234bb676 (Only request keyboard protocols once we know if kitty kbd
is supported, 2025-01-26) queries support for the kitty protocol and acted
upon it after having read next character.

Unfortunately this meant that we don't turn on the kitty protocol until after
we read a character -- since the CSI ? u response does not generate a char
event.  Let's query for primary DA additionally, matching what fish does.
In future, we should do a timed wait as well, to avoid terminal responses
leaking when there we exit fish_key_reader too quickly.
2025-03-01 14:31:53 +01:00
Johannes Altmanninger
b401aee4ce Reserve the ability to read XTVERSION
Whenever we add logic to print a control sequence that we hadn't printed
before, there is a nonzero risk that a terminal mishandles it.

Terminal-specific workarounds cause pain but are probably better than not
being able to use any new commands provided by terminals.

There is no universal way to identify a terminal. Device attributes (primary
through tertiary) typically get spoofed responses, likely not good enough
for working around bugs in specific versions of a terminal.

The de-facto standard for the terminal name and version is XTVERSION.
It's usually specific to the terminal, except for something like VTE-based
terminals, where we get this (which seems good enough also)

	printf '\x1b[>0q'; cat
	^[P>|VTE(7803)^[\

Of course querying for XTVERSION can trigger terminal bugs just as well. Let's
start querying for it now -- even without a concrete use case -- to increase
the chance we can use it during crunch time when we don't want to test
anymore. (We typically discover buggy terminals only very late in the release
cycle, most prominently after a release).
2025-03-01 13:03:04 +01:00
Johannes Altmanninger
7c2388fbfc Fix bracketed paste potentially not being disabled on SIGTERM
When we enable/disable terminal protocols,
we use atomic operations because of issues like
1. halfway through enabling, we might be interrupted by a signal handler.
2. our SIGTERM handler runs the (idempotent) disabling sequences,
   so the operations must be async-signal safe.

The flags to keep track of whether things like kitty keyboard protocol are enabled
are "mirrored" between the enabling and disabling logic:

- the enabling logic marks it as enabled *before* enabling anything
- the disabling logic marks it as disabled *after* everything has been disabled

This ensures that we are well-behaved in issue 1; we will always (perhaps
redundantly) disable the kitty keyboard protocol.

We forgot to use the same ordering for bracketed paste.
If we get SIGTERM after this line

	BRACKETED_PASTE.store(false, Ordering::Release);

we might exit with bracketed paste still turned on.
2025-03-01 12:45:11 +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
303af078f3 Actually disable CSI u in iTerm < 3.5.12
Fixes #11192
2025-02-28 21:15:44 +01:00
Johannes Altmanninger
84eb06ac14 Remove unused export in Ast 2025-02-28 07:50:14 +01:00
Johannes Altmanninger
fa390f1b14 CHANGELOG: fix RST syntax for nested lists
These would all be rendered in one line.
2025-02-28 03:47:19 +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
Fabian Boehm
a9c61394a8 README: Update Ubuntu PPA version
Fixes #11180
2025-02-27 19:43:45 +01:00
David Adam
ede3f81eef Merge branch 'Integration_4.0.0' 2025-02-27 22:51:11 +08:00
David Adam
5e2ddaace9 debian packaging: use the correct test target 2025-02-27 22:46:23 +08:00
Mo Bitar
11b6fad7ba Fix tag 2025-02-27 22:18:50 +08:00
David Adam
1e069b0fff Cargo metadata: bump version number 2025-02-27 21:32:23 +08:00
David Adam
eb336889b7 Release 4.0.0 2025-02-27 16:00:33 +08:00
Laurențiu Nicola
1c57144f8b Fix create-base-directories.fish with SELinux
(cherry picked from commit f224ff1d28)
2025-02-27 11:37:17 +08:00
Fabian Boehm
6d30751f1c 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

(cherry picked from commit 414293521e)
2025-02-27 11:37:17 +08:00
Laurențiu Nicola
f224ff1d28 Fix create-base-directories.fish with SELinux 2025-02-27 10:33:22 +08:00
David Adam
d33b967196 CHANGELOG: finalise 4.0.0 / 4.0b1 release notes
The majority of users will be going straight from 3.7 to 4.0. The 4.0 notes
should reflect this transition, rather than the changes that were only in 4.0b1.
2025-02-26 23:55:49 +08:00
David Adam
ea115f8595 CHANGELOG: fix syntax error 2025-02-26 22:56:15 +08:00
David Adam
def40ff34d CHANGELOG: work on 4.0.0 2025-02-26 21:41:58 +08:00
David Adam
bfa1e0dafb docs/source: document changes from #10774
(cherry picked from commit b82d0fcbcc)
2025-02-26 21:31:33 +08:00
David Adam
b52173c854 docs/bind: improve description of cancel binding
Closes #9644

(cherry picked from commit 8ec1a3e7b9)
2025-02-26 21:31:33 +08: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
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
Fabian Boehm
750fe3bcc1 docs/bind: More on how default mode is normal mode 2025-02-20 19:08:24 +01:00
Fabian Boehm
b5736c5535 Extend iTerm CSI u workaround to < 3.5.12
iTerm has a bug where it'll send Option-Left as Left instead of the
proper Alt-Left. This was reported upstream and fixed in

480f059bce

which is contained in the 3.5.12-beta2 tag, so let's assume that fixes
it.

Fixes #11025

(not necessary in 4.1)
2025-02-20 17:11:08 +01:00
Fabian Boehm
6c9e6b3baf functions/help: Fix version number for betas 2025-02-19 21:47:00 +01:00
Johannes Altmanninger
e2a0b0e2b8 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

(cherry picked from commit afbdb9f268)
2025-02-19 10:47:28 +01:00
Johannes Altmanninger
ebc460b9f9 Fix search field state not resetting after search field is hidden
Commit 4f536d6a9b (Update commandline state snapshot lazily,
2024-04-13) add an optimization to update the search field only if
necessary.  The optimization accidentally prevents us from resetting
the search field.

Fixes #11161

(cherry picked from commit 72f2433120)
2025-02-19 10:47:21 +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
Johannes Altmanninger
72f2433120 Fix search field state not resetting after search field is hidden
Commit 4f536d6a9b (Update commandline state snapshot lazily,
2024-04-13) add an optimization to update the search field only if
necessary.  The optimization accidentally prevents us from resetting
the search field.

Fixes #11161
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
Fabian Boehm
8657362d86 Staticbuilds: Only build the fish binary
These are supposed to be small, so we dump the redundant fish_indent
and fish_key_reader - the fish binary can do those jobs too (both as
builtins and if called via symlinks of that name).

We still keep tarballs instead of just compressing so that we have a
file called "fish" and not "fish-amd64-linux"
2025-02-13 20:57:17 +01:00
David Adam
df56f7155e docs/interactive: add ctrl-n Vi mode documentation
Noted missing in #11082.

(cherry picked from commit b2eebbe194)
2025-02-13 00:13:11 +08:00
David Adam
b2eebbe194 docs/interactive: add ctrl-n Vi mode documentation
Noted missing in #11082.
2025-02-13 00:12:34 +08:00
Dmitry Gerasimov
40b63c35ab 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

(cherry picked from commit dfa77e6c19)
2025-02-13 00:02:13 +08:00
Dmitry Gerasimov
b72dc096f9 completions/git: update supported git format options
--format=reference is supported since git 2.25
--format=mboxrd is supported since git 2.27

(cherry picked from commit 9752b83e65)
2025-02-13 00:02:13 +08:00
Ilya Grigoriev
c571b65221 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/
(cherry picked from commit 4208798585)
2025-02-13 00:01:07 +08:00
Łukasz Wieczorek
82750bbaec Reformat with black. 2025-02-12 22:59:27 +08:00
David Adam
d32c455269 src/env_dispatch: add clarifying comment for setenv 2025-02-12 22:27:53 +08:00
David Adam
4cb5927e7a rename curses module to terminal
There's no actual use of curses here, just terminfo.
2025-02-12 22:26:23 +08:00
David Adam
ffdec4b485 src/curses: drop CURSES_INITIALIZED lock
setupterm/cur_term does not get used any more
2025-02-12 21:57: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
b4b0b42792 Tweak replacing completions for directory-variable name
If we're only inserting a prefix of the variable name we're not gonna
add a space. We don't want to add a slash either.
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
David Adam
fab273cf4d BSD/GNUmakefile: update to use new fish_run_tests target
(cherry picked from commit 15ca164773)
2025-02-12 12:09:00 +08:00
David Adam
0f346991e4 Revert "CI: Use renamed test target"
CI targets the GNUmakefile in the build root, which is probably worth keeping
working.

This reverts commit 3469fd25ec.
2025-02-12 12:09:00 +08:00
David Adam
15ca164773 BSD/GNUmakefile: update to use new fish_run_tests target 2025-02-12 08:56:38 +08:00
Fabian Boehm
9c2bfec150 CHANGELOG keyboard-protocols feature flag 2025-02-11 22:23:31 +01:00
Fabian Boehm
9c40f72643 Add feature flag for turning off keyboard protocols
To work around terminal bugs.

The flag "keyboard-protocols" defaults to "on" and enables keyboard protocols,
but can be turned off by setting "no-keyboard-protocols".

This has downsides as a feature flag - if you use multiple terminals and
one of them can't do it you'll have to disable it in all,
but anything else would require us to hook this up to env-dispatch,
and ensure that we turn the protocols *off* when the flag is disabled.

Since this is a temporary inconvenience, this would be okay to ask
zellij and Jetbrains-with-WSL users.
2025-02-11 22:22:08 +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
Fabian Boehm
3350145371 Reader: Fix crash completing incomplete variable name
Regression in 4.1, not present in 4.0.

Fixes #11148
2025-02-11 22:17:09 +01:00
David Adam
774ad16404 CHANGELOG: work on 4.0.0 2025-02-11 23:28:07 +08:00
idealseal
6d7a7c2254 feat(comp): update to systemd 257
(cherry picked from commit 7accf4ffa1)
2025-02-11 22:53:09 +08:00
idealseal
7accf4ffa1 feat(comp): update to systemd 257 2025-02-11 22:52:42 +08:00
Max Jacobson
e1349b9c4a Fix formatting of abbr example
I'm running fish 4.0b1 locally and I tried running `help abbr` and
browsing the docs. I noticed one example which wasn't formatted
correctly.

I'm not too familiar with rst, but based on looking at the file, it
seems that this is how example code should be represented.

(cherry picked from commit d47a4899b4)
2025-02-11 22:51:24 +08:00
Max Jacobson
d47a4899b4 Fix formatting of abbr example
I'm running fish 4.0b1 locally and I tried running `help abbr` and
browsing the docs. I noticed one example which wasn't formatted
correctly.

I'm not too familiar with rst, but based on looking at the file, it
seems that this is how example code should be represented.
2025-02-11 22:51:06 +08:00
Ilya Grigoriev
0677c03689 completions/tmux: replace embedded tabs with \t
(cherry picked from commit 5dd6759d01)
2025-02-11 22:32:22 +08:00
David Adam
1b6e107131 completions/elm: remove = in long options
elm's argument parser copes just fine without them

Review comment from
https://github.com/fish-shell/fish-shell/pull/10759#discussion_r1786918645

(cherry picked from commit 2849cd11ae)
2025-02-11 22:29:03 +08:00
Kemel Zaidan
7ea368b6d3 adds completion for the default Elm cli tool
(cherry picked from commit df6bd36e82)
2025-02-11 22:29:03 +08:00
Roland Fredenhagen
00b2009851 Complete entries for bootctl
Uses `jq` to parse and doesn't add these extra completions if not available.

(cherry picked from commit d862e7bf26)
2025-02-11 22:29:03 +08:00
David Adam
2849cd11ae completions/elm: remove = in long options
elm's argument parser copes just fine without them

Review comment from
https://github.com/fish-shell/fish-shell/pull/10759#discussion_r1786918645
2025-02-11 22:27:53 +08:00
Kemel Zaidan
df6bd36e82 adds completion for the default Elm cli tool 2025-02-11 22:21:18 +08:00
Roland Fredenhagen
d862e7bf26 Complete entries for bootctl
Uses `jq` to parse and doesn't add these extra completions if not available.
2025-02-10 22:15:57 -08: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
d418d7638a docs: Document split0 and command substitutions harder 2025-02-08 20:09:43 +01:00
Fabian Boehm
ba458052ea Staticbuilds: Update for test_driver.py
(and check for it because github workflows run from the main branch and we
might want to use this to build 4.0)
2025-02-08 18:51:47 +01:00
Fabian Boehm
a1e8628c21 docs: Document fish_clipboard_copy's OSC 52 support 2025-02-08 12:17:55 +01:00
Fabian Boehm
47d3189614 abbr: Print optional set-cursor arg correctly
Allows the output to round-trip.

Fixes #11141

(cherry picked from commit b50c832a35)
2025-02-07 12:40:33 +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
65ac71edcc Make alt-{b,f} move in directory history if commandline is empty
alt-{left,right} move in the directory history (like in browsers).
Arrow keys can be inconvenient to reach on some keyboards, so
let's alias this to alt-{b,f}, which already have similar behavior.
(historically the behavior was the same; we're considering changing
that back on some platforms).

This happens to fix alt-{left,right} in Terminal.app (where we had
a workaround for some cases), Ghostty, though that alone should not
be the reason for this change.

Cherry-picked from commit f4503af037.

Closes #11105
2025-02-06 19:15:03 +01:00
Johannes Altmanninger
f4503af037 Make alt-{b,f} move in directory history if commandline is empty
alt-{left,right} move in the directory history (like in browsers).
Arrow keys can be inconvenient to reach on some keyboards, so
let's alias this to alt-{b,f}, which already have similar behavior.
(historically the behavior was the same; we're considering changing
that back on some platforms).

This happens to fix alt-{left,right} in Terminal.app (where we had
a workaround for some cases), Ghostty, though that alone should not
be the reason for this change.

Closes #11105
2025-02-06 19:12:00 +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
Fabian Boehm
a11b9e5af7 CHANGELOG: Fix some formatting 2025-02-05 22:13:17 +01:00
Fabian Boehm
db244e0492 reader: Only maintain cursor position in non-empty prefix search
Otherwise this would always move the cursor to the beginning.

Fixes #11133
2025-02-05 22:13:14 +01:00
Fabian Boehm
3469fd25ec CI: Use renamed test target
Because CMake no longer allows making a custom "test" target, we
removed it and now need to run "fish_run_tests" instead
2025-02-05 19:22:26 +01:00
Fabian Boehm
378f452eaa 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
2025-02-05 19:06:37 +01:00
Fabian Boehm
9490c74746 Remove tparm0
This does not do anything
2025-02-05 17:00:25 +01:00
ridiculousfish
49c848ed42 Optimize wcstod_underscores
Prior to this change, wcstod_underscores would create a "pruned" string without
underscores, and then parse that. Switch instead to a filtered Iterator, which
can ignore underscores as it traverses the string.

Add a test that completes in a reasonable time only if wcstod_underscores is not
quadratic.

(cherry picked from commit b4577c10e5cf9239bc93c605f431a56d98266a1e)
2025-02-05 17:00:25 +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
kerty
c1c23269d2 Don't restart search if we maintain search mode
Currently, the search always restarts when moving from the present.
For example:
1. Do a few backward searches.
2. Use PageDown to return to the present.
3. Do another backward search.
4. Now, PageUp does nothing because the search was restarted, even if we maintained search mode.
2025-02-04 10:12:30 +01:00
Peter Ammon
8a86b4e4fc Remove some stale comments 2025-02-03 15:55:55 -08:00
Fabian Boehm
04151d758b 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

(cherry picked from commit 8d6fdfd9de)
2025-02-03 13:39:22 +01:00
phanium
bf91da5979 Fix twice tokenize editor_cmd
```fish
export VISUAL='nvim --cmd let\ g:flatten_wait=1'
funced -s fish_prompt
```

`editor_cmd[3]` would be `let` rather than `let g:flatten_wait=1`
2025-02-02 16:21:12 -08:00
phanium
1d827d1d2d Fix twice tokenize editor_cmd
```fish
export VISUAL='nvim --cmd let\ g:flatten_wait=1'
funced -s fish_prompt
```

`editor_cmd[3]` would be `let` rather than `let g:flatten_wait=1`
2025-02-02 16:20:12 -08:00
Peter Ammon
7c32cb1b44 Put back noun form of "licence" in mksquashfs comment 2025-02-02 11:48:37 -08: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
ccoVeille
0df6fa7915 Fix typos in completions scripts 2025-02-02 17:15:11 +08:00
Ilya Grigoriev
5dd6759d01 completions/tmux: replace embedded tabs with \t 2025-02-01 17:37:38 -08:00
Ilya Grigoriev
2b6f6b8cbc completions/tmux: basic window argument completions 2025-02-01 17:37:38 -08:00
Ilya Grigoriev
5d0e2244bb completions/tmux: add ability to complete buffer names and commands
This adds the ability to complete (and therefore preview) buffer names,
and adds incomplete (aiming to maximize utility/effort, similarly to
b1064ac) bindings to the `tmux` buffer commands.

The main benefit is, IMO, is the tab completion for `tmux paste-buffer
-b` and `tmux show-buffer -b`.
2025-02-01 17:37:38 -08: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
Fabian Boehm
2f2ea729a7 completions/csvlens: Fix missing option
(cherry picked from commit bba15c6d14)
2025-01-31 19:34:51 +01:00
Mahmoud Al-Qudsi
cbedfc8a64 Use Write::write_all(), not write()
There is no guarantee that Write::write() will write the entirety of the
provided buffer in one go, regardless of how short it is, because that depends
on the semantics of the underlying write handle (even if it was a
single byte, though in this case that would be because of an interrupt).

The only case I'm aware of that would guarantee a single Write::write() call
would suffice is when writing into a high-level memory-backed buffer, and we
can't make that guarantee (now or in perpetuity).
2025-01-31 11:25:56 -06:00
Fabian Boehm
9a46b66d04 Increase default read limit to 1GiB
The current limit can be reached in actual use and still be a usable shell.

E.g. in #11095 someone had `git status` print over 100MiB of file
information.
2025-01-31 16:44:25 +01:00
Fabian Boehm
5eee4fc2c7 completions/git: Don't set the read limit
This isn't propagated correctly:

If $fish_read_limit is set globally, it won't apply to the completion
command substitution, *unless* you set fish_read_limit inside of that
function.

I'm not entirely sure how that happens, but let's work around it for
now by removing that limit.

I'm going to increase the default limit in a future commit, because
it's not something supposed to be reachable in ordinary code.

See #11106
2025-01-31 16:37:26 +01:00
Fabian Boehm
db48cd547b Reset read_limit back to default
Regression introduced in 6638c78b30

Reintroduces #9129

It's unclear why the tests didn't fail

(cherry picked from commit 6d8f1aeb27)
2025-01-31 16:31:55 +01:00
Fabian Boehm
6d8f1aeb27 Reset read_limit back to default
Regression introduced in 6638c78b30

Reintroduces #9129

It's unclear why the tests didn't fail
2025-01-31 16:31:39 +01:00
kerty
acadf00718 Fix regression causing variable completions to not have description
Regressed in 17bd7d0 (Switch completion_request_options_t from a list of flags to a struct, 2022-06-07).
2025-01-31 13:41:02 +01:00
kerty
bfb32cdbd9 Improve calculation of offset for width 2025-01-31 13:37:27 +01:00
kerty
c54131c8c5 Make at least one character of the autosuggestion always shown
Previously, there were situations where an autosuggestion existed but was not shown at all. This commit guarantees that at least the `ellipsis_char` is shown, regardless of the situation.
2025-01-31 13:37:27 +01:00
kerty
0ecf4b1ce0 Fix inconsistent autosuggestion truncation on soft wrapped lines
This commit ensures that autosuggestions cannot soft wrap. Previous behavior:
- If the first line is not soft wrapped, the autosuggestion will be truncated and not shown on soft-wrapped lines.
- If the first line is soft-wrapped, the autosuggestion will not have any limit.
2025-01-31 13:37:27 +01:00
kerty
be95b176bc Fix incorrect first line checks in rendering
The right prompt was rendered even if scrolled.
The command line wasn't rendering on the first line, starting from 0 to the left prompt length. Steps to reproduce:
fish -C 'bind ctrl-g \'commandline $(printf %0"$(math $COLUMNS)"d0) $(seq $(math $LINES - 1))\''
# use ctrl-g
# observe that only one '0' is rendered
2025-01-31 13:37:27 +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
kerty
9915a07741 Convert Screen::write_char() to usize 2025-01-31 13:37:27 +01:00
kerty
7acc2b7223 Fix pager occupying empty soft wrapped lines
We need to add a line to the desired screen if the previous line was full or non-existent to prevent the pager from being drawn on empty soft wrapped or new lines.
Steps to reproduce:
fish -C '
    function fish_prompt; printf \>; end
    bind ctrl-g \'commandline  "ls $(printf %0"$(math $COLUMNS - 5)"d 0) "\''
# use ctrl-g and tab
# observe that the pager starts on the line with the cursor
2025-01-31 13:37:27 +01:00
kerty
5ecf5aef8a Fix regression causing variable completions to not have description
Regressed in 17bd7d0 (Switch completion_request_options_t from a list of flags to a struct, 2022-06-07).
2025-01-31 13:37:27 +01:00
kerty
1339da330e Fix crash when clicking on empty lines
This fixes a crash that occurred in Kitty when clicking on lines without characters, such as soft wrapped lines or first line without a prompt.
2025-01-31 13:37:27 +01:00
kerty
6bb19cf1f4 Fix not emitting osc_133_prompt_start without prompt
If the left prompt is defined to be empty, osc_133_prompt_start would not be emitted at all.
2025-01-31 13:37:27 +01:00
kerty
d667ec5061 Remove space for prompt if it occupies full line
If the prompt occupies the full width of the first line, each new line will soft wrap, leaving empty lines between. This change removes the indentation that matches the start of the line to the end of the prompt if the prompt width equals the terminal width.

Steps to reproduce:
fish -C 'function fish_prompt; printf %0"$COLUMNS"d 0; end'
# type "begin" and Enter
# observe that there was a spurious empty line
2025-01-31 13:37:27 +01:00
Fabian Boehm
e63fea1127 reader: only flash entire commandline if token is empty
So `git add dsfiojdsoif<TAB>` flashes the token, `git add <TAB>`
flashes the entire commandline because there is no token to flash
2025-01-30 17:13:09 +01:00
Fabian Boehm
93ac5d0eb3 pager: fix selected color regression
To check:

```fish
fish_config theme choose None
set -g fish_pager_color_selected_completion blue
```

Now the selected color will only apply to the parentheses

Missed in 43e2d7b48c (Port pager.cpp)

(cherry picked from commit 6c4d658c15)
2025-01-30 16:27:31 +01:00
Fabian Boehm
4ae3c487a6 reader: flash entire commandline if there's no completion
This is often the case if the token is empty, e.g `git add <TAB>`
outside of a git repo.
2025-01-30 16:24:35 +01:00
Fabian Boehm
6c4d658c15 pager: fix selected color regression
To check:

```fish
fish_config theme choose None
set -g fish_pager_color_selected_completion blue
```

Now the selected color will only apply to the parentheses

Missed in 43e2d7b48c (Port pager.cpp)
2025-01-30 16:22:07 +01:00
Fabian Boehm
ba193665e2 completions: Add missing options for our builtins 2025-01-29 20:38:41 +01:00
Fabian Boehm
66f1aba0f2 completions/commandline: Add missing options 2025-01-29 20:17:46 +01:00
Fabian Boehm
ef4fad763f Remove fish.desktop harder 2025-01-29 17:21:14 +01:00
Justin Zobel
a42c5b4025 Remove fish.desktop file as it was only needed for AppImages which were decided against. 2025-01-29 17:19:39 +01:00
David Adam
5aec9e3b47 docs/fish: minor style/proofing edits
(cherry picked from commit be48d73599)
2025-01-29 22:47:06 +08:00
David Adam
d7fb0308a7 docs/language: update target release for feature flags from 3.8 to 4.0
see also 24abbb6de7

(cherry picked from commit 1cf71656ef)
2025-01-29 22:47:05 +08:00
Ilya Grigoriev
fa5de3ece8 language.rst: make description of features more consistent (minor)
The version where a feature became the default is now described inline,
to make it a single source of truth. I could have fixed the other
section where this was described, but this seemed easier.

I also removed a few details that seem no longer relevant.

(cherry picked from commit 064d867873)
2025-01-29 22:46:29 +08:00
David Adam
be48d73599 docs/fish: minor style/proofing edits 2025-01-29 20:28:00 +08:00
David Adam
1cf71656ef docs/language: update target release for feature flags from 3.8 to 4.0
see also 24abbb6de7
2025-01-29 20:27:14 +08:00
Johannes Altmanninger
29e69bd113 Fix broken completions for "mount -ouid="
Cherry-picked from b46417c77b (Fix broken completions for "mount
-ouid=", 2024-11-21).
2025-01-29 10:33:20 +01:00
Johannes Altmanninger
4d6544591e Fix regression breaking automatic history saving after adding ephemeral items
Cherry-picked from acf9ba4195 (Fix regression causing missing automatic
history saving after adding ephemeral items, 2025-01-29)
2025-01-29 10:32:24 +01:00
Johannes Altmanninger
acf9ba4195 Fix regression causing missing automatic history saving after adding ephemeral items
Commit f36f757fa6 (Never rewrite history file when adding ephemeral
items, 2024-10-06) has a glaring bug: when adding to history ephemeral
items that has potential paths, we fail to re-enable automatic saving,
which effectively disables automatic saving for the entire session.

Only a call to history::save_all() at exit saves us from losing data.
But until exit, other fish will see our history (unless we run history
save/merge or similar).

Fix the imbalanced enable/disable and restructure the code a bit.
Also, extend the change from f36f757fa6 (never vacuum on ephemeral
items) to private mode.
2025-01-29 10:16:19 +01:00
Ilya Grigoriev
064d867873 language.rst: make description of features more consistent (minor)
The version where a feature became the default is now described inline,
to make it a single source of truth. I could have fixed the other
section where this was described, but this seemed easier.

I also removed a few details that seem no longer relevant.
2025-01-28 21:23:45 -08:00
David Adam
bfbee7a7ff CHANGELOG: work on 4.0.0 2025-01-28 23:32:38 +08:00
David Adam
3400844f9a completions/acpi: correct the -c option as cooling
Closes #11068.

(cherry picked from commit 2184aaf9b4)
2025-01-28 21:56:54 +08:00
David Adam
2184aaf9b4 completions/acpi: correct the -c option as cooling
Closes #11068.
2025-01-28 21:47:05 +08:00
Ilya Grigoriev
f1bb4e02fe completions/tmux: some windows and panes boolean flag completions
This documents some non-argument options for the window and panes
commands. The choice of what to document is somewhat arbitrary,
this commit is biased towards options that I find confusing or
misleading without documentation (is `-a` "all" or "after"?)
and the command that seem more useful to me.

I also didn't cover the options that would be covered by
#10855 (though this PR can be used independently). I'm not
sure how much difference this made, it might not matter at
all.

(cherry picked from commit f241187c4a)
2025-01-28 21:42:24 +08:00
Ilya Grigoriev
9385a25c22 completions/tmux: complete commands inside tmux lscm
Make `tmux lscm <tab>` work.

(cherry picked from commit 77406ddd11)
2025-01-28 21:42:14 +08:00
Ilya Grigoriev
323bddcce6 completions/tmux: complete all flags when tmux lscm is available
These dynamic completions are exhaustive, but not as well-documented or
as ergonomic as the manual completions. So, any manual completions
should override them.

(cherry picked from commit 183e20cc3a)
2025-01-28 21:42:06 +08:00
Ilya Grigoriev
d29d63d930 completions/tmux: complete all subcommands when tmux lscm works
For example, `tmux shell<tab>` now completes to `if-shell` and
`run-shell`, though no additional information is provided.

(cherry picked from commit 27e5ed7456)
2025-01-28 21:41:43 +08:00
Ilya Grigoriev
a62bae9e8f tmux completions: complete shell commands
(cherry picked from commit bcc69da569)
2025-01-28 21:41:32 +08:00
Ilya Grigoriev
f241187c4a completions/tmux: some windows and panes boolean flag completions
This documents some non-argument options for the window and panes
commands. The choice of what to document is somewhat arbitrary,
this commit is biased towards options that I find confusing or
misleading without documentation (is `-a` "all" or "after"?)
and the command that seem more useful to me.

I also didn't cover the options that would be covered by
#10855 (though this PR can be used independently). I'm not
sure how much difference this made, it might not matter at
all.
2025-01-28 21:38:34 +08:00
Ilya Grigoriev
77406ddd11 completions/tmux: complete commands inside tmux lscm
Make `tmux lscm <tab>` work.
2025-01-28 21:37:16 +08:00
Ilya Grigoriev
183e20cc3a completions/tmux: complete all flags when tmux lscm is available
These dynamic completions are exhaustive, but not as well-documented or
as ergonomic as the manual completions. So, any manual completions
should override them.
2025-01-28 21:37:16 +08:00
Ilya Grigoriev
27e5ed7456 completions/tmux: complete all subcommands when tmux lscm works
For example, `tmux shell<tab>` now completes to `if-shell` and
`run-shell`, though no additional information is provided.
2025-01-28 21:37:16 +08:00
Johannes Altmanninger
d2b2c5286a Fix regression decoding function keys
Commit 109ef88831 (Add menu and printscreen keys, 2025-01-01)
accidentally broke an assumption by inverting f1..f12.  Fix that.

Fixes #11098
2025-01-27 21:49:29 +01:00
Fabian Boehm
9116c61736 completions/nmcli: Complete at runtime
This used to get all the interfaces and ssids when the completions
were loaded. That's obviously wrong, given that ssids especially can, you know, change
2025-01-27 20:46:38 +01:00
Fabian Boehm
4370fb755d completions/git: Handle untracked files separately
This uses `git ls-files`, which has a simpler format (just the
filenames on separate lines), in order to print the untracked files.

This allows us to skip them in the `git status` call, which reduces
the output a lot and removes two `string match`.

In a repository with over half a million files (my home directory, if
I made it one), this improves time by a third (12s to 8s).

In a smaller repo (fish-shell) it's barely measurable.
2025-01-27 18:24:08 +01:00
kerty
514f4b9e23 Rename some methods of ReaderHistorySearch to improve clarity 2025-01-27 18:19:04 +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
Fabian Boehm
5c81e18b2e completions/git: Handle gigantic repos better
Determine if untracked files are off via `__fish_git`, so we get the
repo used on the commandline etc,

and if it isn't, at least don't error out. Yes, this *can* print a
hundred megabytes of filenames.
2025-01-27 17:52:32 +01:00
Fabian Boehm
bba15c6d14 completions/csvlens: Fix missing option 2025-01-27 17:51:35 +01:00
Johannes Altmanninger
28d4fc33d8 fixup missing function 2025-01-27 06:59:18 +01:00
Johannes Altmanninger
7dc046b959 Fix regression causing crash in token history search
I'm not yet sure how to reproduce 4dfcd4cb4e (reader: Check bounds
for color, 2022-08-26).  Commit 55fd43d86c (Port reader, 2023-12-22)
accidentally changed historical behavior, fix that.

Fixes #11096
2025-01-27 06:34:35 +01:00
Johannes Altmanninger
d7354880e3 Fix regression causing crash in token history search
I'm not yet sure how to reproduce 4dfcd4cb4e (reader: Check bounds
for color, 2022-08-26).  Commit 55fd43d86c (Port reader, 2023-12-22)
accidentally changed historical behavior, fix that.

Fixes #11096
2025-01-27 06:32:15 +01:00
Johannes Altmanninger
fff421ad9c Work around mc and dvtm not responding to Primary DA
The two terminals Midnight Commander and dvtm are special in that
they filter requests (or perhaps responses) like

	printf "\x1b[0c"

and don't implement the response themselves -- so we never get
one. Let's work around that until we can fix it.

Disable the kitty protocol in mc for now (to keep the code simple),
though we could certainly re-enable it.

Fixes 64859fc242 (Blocking wait for responses to startup queries, 2025-01-25).
2025-01-27 06:32:15 +01:00
ccoVeille
90e916e164 Fix typo in tests 2025-01-26 20:30:48 -08:00
ccoVeille
0047abbe7a Fix typo in code 2025-01-26 20:30:48 -08:00
ccoVeille
b6a1bedab9 Fix typos in comments 2025-01-26 20:30:48 -08:00
Mahmoud Al-Qudsi
88c8992cc3 Add inline attribute 2025-01-26 17:21:49 -06:00
Fabian Boehm
2b2f824b94 completions/git: Handle huge repositories for "add" better
`git add` may have to go through literal megabytes of file information
because of tons of untracked files.

So, if the repository is set to not show untracked files (because it's
too slow for the prompt), let's fall back on regular file completions.

(the alternative is to go back to `while read`, but that takes much
longer in repositories of a sensible size)

Fixes #11095
2025-01-26 21:41:36 +01:00
Johannes Altmanninger
9882849fda Fix regression causing builtin commandline to report wrong relative cursor
Regressed in 55fd43d86c (Port reader, 2023-12-22).

Cherry-picked from c651a79c
2025-01-26 15:55:35 +01: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
4c28a7771e Sanitize some inputs in CSI parser
This was copied from C++ code but we have overflow checks, which
forces us to actually handle errors.

While at it, add some basic error logging.

Fixes #11092
2025-01-26 15:39:21 +01:00
Johannes Altmanninger
2d234bb676 Only request keyboard protocols once we know if kitty kbd is supported
Today we might
1. enable modifyOtherKeys
2. get a reply indicating the kitty keyboard protocol is supported
3. because of 2, we never turn off modifyOtherKeys again

Let's get rid of this weird issue by enabling either modifyOtherKeys
or the kitty enhancements only after we know whether the kitty protocol
is supported.

This means we need to call terminal_protocols_enable_ifn() before every
call to readch() until the querying is done.  Fortunately, this is
already in place in read_normal_chars(); there are other places that
call readch() but none of those is executed until querying has completed.
2025-01-26 15:39:21 +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
Johannes Altmanninger
630a06cf8f Work around st terminal resetting cursor on CSI ? u
The st terminal wrongly parses CSI ? u as DECRC. A fix has been
proposed upstream.  Let's also work around it I guess (not to mention
that querying in the first place is also sort of a workaround).
2025-01-26 14:19:40 +01:00
Johannes Altmanninger
95d61ea0fb Split /etc/{,man}path by colons too
I don't know how /etc/manpath ends up containing lines like
"path1:path2".  But path_helper splits them so we should do too.

4ea11424b8/path_helper/path_helper.c (L149)

Fixes #10684
2025-01-26 14:19:40 +01:00
Johannes Altmanninger
6e2c5d4365 Add trailing slash (not space) to variable name completions that produce valid paths
Closes #5798
2025-01-26 14:19:40 +01:00
Fabian Boehm
545a23734e Remove some ffi wrappers 2025-01-25 20:03:13 +01:00
Mahmoud Al-Qudsi
d69a9296a6 completions/llm: Complete model alias target 2025-01-25 12:50:03 -06:00
kerty
3fdd2d3fc2 Small refactor of HighlightSpec 2025-01-23 17:09:29 +01:00
kerty
db546da3ca Made undo/redo not update autosuggestion if failed 2025-01-23 17:09:29 +01:00
kerty
6a9f1b925d Make flash highlight autosuggestion on failed deletion 2025-01-23 17:09:29 +01:00
kerty
bffbf0cd57 Make flash highlight relevant commandline section 2025-01-23 17:09:29 +01:00
kerty
b5c869d5e7 Make parse_util_token_extent return its output instead of mutating input. 2025-01-23 17:09:29 +01:00
kerty
4994000a27 Small refactor of Reader::flash 2025-01-23 17:09:29 +01:00
ccoVeille
d5fdcc96c8 Fix typos in .rst files 2025-01-23 22:06:12 +08:00
Johannes Altmanninger
aee729bd44 Update changelog for cancel-commandline 2025-01-23 02:28:00 +01:00
Johannes Altmanninger
92582d5b1f Back out "Escape : and = in file completions"
If you don't care about file paths containing '=' or ':', you can
stop reading now.

In tokens like

	env var=/some/path
	PATH=/bin:/usr/local/b

file completion starts after the last separator (#2178).

Commit db365b5ef8 (Do not treat \: or \= as file completion anchor,
2024-04-19) allowed to override this behavior by escaping separators,
matching Bash.

Commit e97a4fab71 (Escape : and = in file completions, 2024-04-19)
adds this escaping automatically (also matching Bash).

The automatic escaping can be jarring and confusing, because separators
have basically no special meaning in the tokenizer; the escaping is
purely a hint to the completion engine, and often unnecessary.

For "/path/to/some:file", we compute completions for "file" and for
"/path/to/some:file".  Usually the former already matches nothing,
meaning that escaping isn't necessary.

e97a4fab71 refers us to f7dac82ed6 (Escape separators (colon and
equals) to improve completion, 2019-08-23) for the original motivation:

	$ ls /sys/bus/acpi/devices/d<tab>
	$ ls /sys/bus/acpi/devices/device:
	device:00/ device:0a/ …

Before automatic escaping, this scenario would suggest all files from
$PWD in addition to the expected completions shown above.

Since this seems to be mainly about the case where the suffix after
the separator is empty,

Let's remove the automatic escaping and add a heuristic to skip suffix
completions if:
1. the suffix is empty, to specifically address the above case.
2. the whole token completes to at least one appending completion.
   This makes sure that "git log -- :!:" still gets completions.
   (Not sure about the appending requirement)

This heuristic is probably too conservative; we can relax it later
should we hit this again.

Since this reverts most of e97a4fab71, we address the code clone
pointed out in 421ce13be6 (Fix replacing completions spuriously quoting
~, 2024-12-06). Note that e97a4fab71 quietly fixed completions for
variable overrides with brackets.

	a=bracket[

But it did so in a pretty intrusive way, forcing a lot of completions
to become replacing. Let's move this logic to a more appropriate place.

---

Additionally, we could sort every whole-token completion before every
suffix-completion.  That would probably improve the situation further,
but by itself it wouldn't address the immediate issue.

Closes #11027

(cherry picked from commit b6c249be0c)
2025-01-23 09:03:07 +08:00
Johannes Altmanninger
8eb5e36aa6 Swap code blocks for completing separator suffix resp. whole token
Mainly to make the next commit's diff smaller. Not much functional
change: since file completions never have the DONT_SORT flag set,
these results will be sorted, and there are no data dependencies --
unless we're overflowing the max number of completions.  But in that
case the whole-token completions seem more important anyway.

(cherry picked from commit 0cfc95993a)
2025-01-23 09:03:07 +08:00
Fabian Boehm
fd3ed7cfa5 functions/__fish_cancel_commandline: Follow rename of bind function
See #10935
2025-01-22 17:44:28 +01:00
Fabian Boehm
4e13ce33c5 functions/__fish_cancel_commandline: Follow rename of bind function
See #10935
2025-01-22 17:43:59 +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
Fabian Boehm
e67819f532 Wrap libc::umask 2025-01-21 17:31:15 +01:00
Johannes Altmanninger
29cddabfe4 Fix regression causing fish_key_reader to not request kitty flags
Fixes 081c3282b7 (Refresh TTY timestamps also in some rare cases,
2025-01-15).
2025-01-21 14:09:33 +01:00
David Adam
4c9dfcc5d7 CHANGELOG: work on 4.0.0 2025-01-21 00:06:40 +08:00
David Adam
945a535570 fish_default_key_bindings: remove duplicate ctrl-k binding
It's in the shared bindings since f9b7992.
2025-01-20 19:48:57 +08:00
Johannes Altmanninger
4024d82412 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 19:08:38 +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
a7fdd8d002 Back out "Back out "Remove awkward assert""
This backs out commit e0c6384ed3.
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
98a96f5b58 Revert "Swap alt-{left,right,backspace,delete} with ctrl-* on macOS"
This reverts commit ebdc3a0393.

Not discussed, includes a new thing that queries the terminal for the client OS
when what is really needed is just a `uname` - which would also work on Terminal.app.
2025-01-19 18:52:10 +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
97db461e7f README for this fork 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
45a2017580 Allow foo=bar global variable assignments
override fixes
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
0199583435 Interpret () in command position as subshell 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
4a71ee1288 Allow special variables $?,$$,$@,$# 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
4b99fe2288 Allow $() in command position 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
b1213f1385 Turn off full LTO 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
f43abc42f9 Back out "bind: Remove "c-" and "a-" shortcut notation"
This backs out commit 6d76b938c7.
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
485201ba2e Un-hide documentation of non-fish shell builtins
This makes "man exec" show the documentation from Linux man-pages.
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
e32572e4e6 Allow if/then/fi, while/do/done and for/do/done 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
ebdc3a0393 Swap alt-{left,right,backspace,delete} with ctrl-* on macOS
See https://github.com/fish-shell/fish-shell/issues/ 10926
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
e0c6384ed3 Back out "Remove awkward assert"
This backs out commit 6126237bc4.
2025-01-19 18:29:07 +01:00
Johannes Altmanninger
98750e1ae5 Always treat brace at command start as compound statement 2025-01-19 18:29:07 +01:00
Johannes Altmanninger
efce176ceb Support help argument in "{ -h"
Unlike other builtins, "{" is a separate token, not a keyword-string
token.

Allow the left brace token as command string; produce it when parsing
"{ -h"/"{ --help" (and nowhere else).  By using a decorated statement,
we reuse logic for redirections etc.

Other syntax elements like "and" are in the builtin list, which
- adds highlighting logic
- adds it to "builtin --names"
- makes it runnable as builtin
  (e.g. "builtin '{'" would hypothetically print the man page)

These don't seem very important (highlighting for '{' needs to match
'}' anyway).

Additionally, making it a real builtin would mean that we'd need to
deactivate a few places that unescape "{" to BRACE_BEGIN.

Let's not add it to the built in list. Instead, simply synthesize
builtin_generic in the right spot.

I'm assuming we want "{ -h" to print help, but '"{" -h' to run an
external command, since the latter is historical behavior.  This works
naturally with the above fake builtin approach which never tries to
unescape the left brace.
2025-01-19 18:29:07 +01:00
kerty
f26ebac8dd Fix macOS quotation issue in test tmux-multiline-prompt.fish 2025-01-19 18:29:07 +01:00
kerty
4ce8037e73 Fix grep regex in test locale-numeric.fish 2025-01-19 18:29:07 +01:00
kerty
8116e80140 Add test for history pager 2025-01-19 18:29:07 +01:00
kerty
3436836b94 Add automatic history search page change when deleting last element on last page 2025-01-19 18:29:07 +01:00
kerty
4e965cba47 Separate SelectionMotion from HistoryPagerInvocation 2025-01-19 18:29:07 +01:00
kerty
9b14408b1b Make history search banner display start and end indexes 2025-01-19 18:29:07 +01:00
kerty
f28e43717b Fix history pager inconsistent ordering and skipping 13th elements 2025-01-19 18:29:07 +01:00
kerty
059e7424c1 Fix refreshing from deletion after forward search 2025-01-19 18:29:07 +01:00
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
Fabian Boehm
1c11055241 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-17 10:02:32 +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
28fb5b5207 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 09:52:53 +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
45439f07d7 Update tests and docs for 4.0 target 2025-01-16 13:38:26 +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
452aa6c614 feature_flags: update target release for 3.8 flags to 4.0
(cherry picked from commit 24abbb6de7)
2025-01-15 22:12:22 +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
Daniel Fleischer
8c92ea1642 Add lazygit completions (#11019)
(cherry picked from commit 29c45100fa)
2025-01-15 21:08:12 +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 2025-01-15 00:52:15 +01:00
kerty
a0e687965e Fix unsaved screen modification 2025-01-15 00:52:15 +01:00
kerty
644c3a87e3 Refactor mtime_stdout and mtime_stderr into mtime_stdout_stderr 2025-01-15 00:52:15 +01:00
kerty
153300f6d1 Fix incorrect line count calculation 2025-01-15 00:52:15 +01:00
Fabian Boehm
2508cc9de6 Disable some more tests under CI
tmux-commandline can fail with

```
prompt 4>     commandline -i "echo $(printf %0"$COLUMNS"d)"
```

And I just can't even.

job_summary is annoyingly tight.

Also count cancel_event as a *skip*, not success.
2025-01-14 20:31:48 +01:00
Fabian Boehm
d2bfb51611 Workaround Kitty spamming the log for ModifyOtherKeys
Fixes #11040
2025-01-14 20:10:33 +01:00
Fabian Boehm
28233b0711 Make new ctrl-c behavior "clear-commandline"
And leave the old behavior under the name "cancel-commandline".

This renames "cancel-commandline-traditional" back to
"cancel-commandline", so the old name triggers the old behavior.

Fixes #10935
2025-01-14 20:01:56 +01:00
Fabian Boehm
806734cc56 Make new ctrl-c behavior "clear-commandline"
And leave the old behavior under the name "cancel-commandline".

This renames "cancel-commandline-traditional" back to
"cancel-commandline", so the old name triggers the old behavior.

Fixes #10935
2025-01-14 20:00:31 +01:00
Fabian Boehm
021b18335c cmake/Tests: Default to half the cores
Saturating all cores easily leads to timeouts.

The system might be doing something else, and it only leaves at most
one core per-test.

E.g. this will cause 90% of runs to fail on a raspberry pi 4.

Note that we set CTEST_PARALLEL_LEVEL on our CI machines anyway, so
this will not affect them.
2025-01-14 17:55:09 +01:00
Fabian Boehm
23f218eb8e pexpects/bind_mode_events: Increase a timeout 2025-01-14 17:55:09 +01:00
Branch Vincent
8e141070b2 completions: add fish-lsp (#11017)
(cherry picked from commit 7970ca55af)
2025-01-14 23:48:48 +08:00
Fabian Boehm
d32257c2d5 pexpects/wait: wait on the same line as the background jobs
The issue here is we start some short `sleep`s in the background, wait
for a prompt, and only *then* wait for jobs, and *then* check for the
job end output.

That means if the prompt takes too long, we'll read the job end
messages with the `expect_prompt`.

Instead of increasing the timeouts, just wait on the same line and
remove that prompt.
2025-01-14 16:19:07 +01:00
Fabian Boehm
37a1611b54 tests/pexpects/history: Remove a weird match
Bit of a shot in the dark, I've seen this fail and there's no real
need to match the prompt *and* the command you just ran.

(plus wc -l | string trim is unnecessary when we have count)
2025-01-14 10:57:22 +01:00
Johannes Altmanninger
24e216ae82 Fix regression causing missing autosuggestions after (
Commit 4f3d6427ce (Fix regression causing crash in "commandline -j",
2025-01-12) wasn't quite right; it mishandles the edge case where
the current process has no token, fix that.
2025-01-13 22:22:42 +01:00
Johannes Altmanninger
c77c35152d Work around old Zellij by parsing unsolicited DECRQM
Zellij 0.41.2 has a bug where it responds to

	 printf '\x1b[?2026$p'; cat -v

with '^[[2026;2$y' (DECRQM) instead of '^[[?2026;2$y' (DECRPM).

This is fixed by https://github.com/zellij-org/zellij/pull/3884

We fail to parse it, leading to an extra y added to the input queue.
Since it seems easy to work around for us, let's do that, I guess.
2025-01-13 21:58:21 +01:00
Fabian Boehm
cbbf95ee55 tests: Increase another timeout
Failed on Cirrus Alpine.

The only explanation I can come up with here is that this took over
100ms to start `true | sleep 6`.

The alternative is that it started it and then did not regain control
in 6 seconds to kill that sleep.

Part of #11036
2025-01-13 15:17:16 +01:00
Fabian Boehm
723943fd1f fish_jj_prompt: Return false if nothing was generated
That means we go on to try git etc
2025-01-13 14:54:00 +01:00
Johannes Altmanninger
b6c249be0c Back out "Escape : and = in file completions"
If you don't care about file paths containing '=' or ':', you can
stop reading now.

In tokens like

	env var=/some/path
	PATH=/bin:/usr/local/b

file completion starts after the last separator (#2178).

Commit db365b5ef8 (Do not treat \: or \= as file completion anchor,
2024-04-19) allowed to override this behavior by escaping separators,
matching Bash.

Commit e97a4fab71 (Escape : and = in file completions, 2024-04-19)
adds this escaping automatically (also matching Bash).

The automatic escaping can be jarring and confusing, because separators
have basically no special meaning in the tokenizer; the escaping is
purely a hint to the completion engine, and often unnecessary.

For "/path/to/some:file", we compute completions for "file" and for
"/path/to/some:file".  Usually the former already matches nothing,
meaning that escaping isn't necessary.

e97a4fab71 refers us to f7dac82ed6 (Escape separators (colon and
equals) to improve completion, 2019-08-23) for the original motivation:

	$ ls /sys/bus/acpi/devices/d<tab>
	$ ls /sys/bus/acpi/devices/device:
	device:00/ device:0a/ …

Before automatic escaping, this scenario would suggest all files from
$PWD in addition to the expected completions shown above.

Since this seems to be mainly about the case where the suffix after
the separator is empty, 

Let's remove the automatic escaping and add a heuristic to skip suffix
completions if:
1. the suffix is empty, to specifically address the above case.
2. the whole token completes to at least one appending completion.
   This makes sure that "git log -- :!:" still gets completions.
   (Not sure about the appending requirement)

This heuristic is probably too conservative; we can relax it later
should we hit this again.

Since this reverts most of e97a4fab71, we address the code clone
pointed out in 421ce13be6 (Fix replacing completions spuriously quoting
~, 2024-12-06). Note that e97a4fab71 quietly fixed completions for
variable overrides with brackets.

	a=bracket[

But it did so in a pretty intrusive way, forcing a lot of completions
to become replacing. Let's move this logic to a more appropriate place.

---

Additionally, we could sort every whole-token completion before every
suffix-completion.  That would probably improve the situation further,
but by itself it wouldn't address the immediate issue.

Closes #11027
2025-01-13 09:50:13 +01:00
Johannes Altmanninger
0cfc95993a Swap code blocks for completing separator suffix resp. whole token
Mainly to make the next commit's diff smaller. Not much functional
change: since file completions never have the DONT_SORT flag set,
these results will be sorted, and there are no data dependencies --
unless we're overflowing the max number of completions.  But in that
case the whole-token completions seem more important anyway.
2025-01-13 09:50:13 +01:00
Johannes Altmanninger
b46417c77b Fix broken completions for "mount -ouid="
Regressed in 2e55e34544 (Reformat, 2020-11-22).
2025-01-13 09:47:34 +01:00
Johannes Altmanninger
33d92d2a1f ctrl-u to suppress autosuggestion
ctrl-w and {ctrl,alt}-backspace do the same.
2025-01-13 09:47:34 +01:00
Johannes Altmanninger
0f4e195819 fish_jj_prompt: remove change ID
This is not really helpful because it's somewhat transient; also we
can usually use the @ alias.
2025-01-13 09:47:34 +01:00
Peter Ammon
9785824794 Factor file testing out of highlighting
Syntax highlighting wants to underline arguments that are files, and in other
cases do disk I/O (such as testing if a command is valid). Factor out this I/O
logic to untangle highlighting, and add some tests. No functional change
expected.
2025-01-12 15:10:11 -08:00
Johannes Altmanninger
4f3d6427ce Fix regression causing crash in "commandline -j"
Commit 3fcc6482cb (Fix parse_util_process_extent including too much
on the left, 2024-12-24) changed the process extent based on the
observation that "A\n\n\nB" comprises three tokens with ranges 0..1,
1..2 and 4..5. Prior to that commit, the second process extent was
2..5, which seems a bit weird because it includes newlines.

Weirdness aside, the real reason for changing it was this snippet in
the autosuggestion performer, where we compute the process extent
around cursor, and check if the line at process start matches the
cached search string.

        // Search history for a matching item unless this line is not a continuation line or quoted.
        if range_of_line_at_cursor(
            &command_line,
            parse_util_process_extent(&command_line, cursor_pos, None).start,
        ) == search_string_range

Given "A\n\n\nB" and cursor_pos=1 commit 3fcc6482cb changed the output
from 2..5 to 4..5. This brings problems:
1. leading spaces will not be included (which is probably
   inconsequential but still ugly).
2. the specified cursor position is not included in the given range.

We could paper over 2 by computing min(cursor_pos)
but that would leave 1.

For now let's revert and solve the autosuggestion issue in a less
brittle way.
2025-01-12 19:55:17 +01:00
Fabian Boehm
a1b7c36db5 cmake: Explicitly have tests depend on indent and key_reader 2025-01-12 18:05:50 +01:00
Fabian Boehm
f0eb599ff1 cmake: Remove some more dead gunk
We no longer check for in tree builds anywhere (tests set up their own
tmpdir),
and we no longer support xcode.
2025-01-12 17:52:59 +01:00
Fabian Boehm
7b30745800 cmake: Stop setting up temporary test directory
We already set up a temporary directory for each test in the
test_driver,
so let's stop doing that here.

It took a weirdly long time anyway.
2025-01-12 17:44:31 +01:00
Fabian Boehm
afb1cc21b6 Compile fish_test_helper in CMake again
That means we don't have to recompile it for every test
2025-01-12 17:40:46 +01:00
Fabian Boehm
aa77892be4 fish_indent: Read from stdin, take two
This needs to work both in builtin and command mode.

We should probably clarify how we're passing FDs around, and I suspect
we may close fds in places we don't expect.
2025-01-12 16:17:49 +01:00
David Adam
b009c0d480 Debian packaging: update dependencies
Ubuntu Focal calls the package with col "bsdmainutils", which is a
transitional package on newer version of both Debian and Ubuntu.

Closes #11037.

(Adapted from commit 54fef433e9)
2025-01-12 21:21:50 +08:00
David Adam
54fef433e9 Debian packaging: update dependencies
Ubuntu Focal calls the package with col "bsdmainutils", which is a
transitional package on newer version of both Debian and Ubuntu.

Closes #11037.
2025-01-12 21:19:59 +08:00
Fabian Boehm
b2fe405365 Revert "fish_indent: Correctly read from builtin stdin"
Using Arguments here breaks the `command fish_indent` case.

Probably needs to directly use a BufReader.

This reverts commit ab1b6bcea5.
2025-01-12 13:43:51 +01:00
Fabian Boehm
ab1b6bcea5 fish_indent: Correctly read from builtin stdin
This still used read_file, but we don't *really* have an fd if we're
connected to another builtin.
2025-01-12 13:15:39 +01:00
David Adam
1b0c53e30e .gitattributes: fixup e4674cd7
Actually set the attribute on the file 🤦 and also exclude the
directory.
2025-01-12 11:32:34 +08:00
David Adam
44555de69a update .gitattributes
Reflect the current state of the codebase
2025-01-12 10:46:34 +08:00
David Adam
e4674cd7b5 .cargo/config.toml: exclude from tarball
Various commits have added bits to .cargo/config.toml. Unfortunately,
this file needs to be changed by the Linux package builds (debuild, RPM,
OBS etc) with the results of `cargo vendor`, to support building in
isolated environments.

These environments - especially Debian's dpkg-buildpackage/debuild - do
not make it easy to alter a file which already exists in the tarball in
an automatic way. dpkg-buildpackage in particular requires all changes
to be made in the form of patches.

Just exclude .cargo/config.toml from the tarballs for now. This means
that the stanzas it includes _will not apply_ to builds made from
tarballs, which includes releases and development builds made using the
OBS/Launchpad PPAs.
2025-01-12 10:34:16 +08:00
Fabian Boehm
a2c48539cd cmake: Remove cachedir for test_driver
This can race when compiling fish_test_helper (one process compiles,
the other checks, ...)

Part of #11036
2025-01-11 22:08:18 +01:00
Fabian Boehm
d9f3cf332c deny.toml: Add Unicode license 2025-01-11 21:14:01 +01:00
Fabian Boehm
b43b0e0195 Rewrite test driver in python (#11028)
This replaces the test_driver.sh/test.fish/interactive.fish system with a test driver written in python that calls into littlecheck directly and runs pexpect in a subprocess.

This means we reduce the reliance on the fish that we're testing, and we remove a posix sh script that is a weird stumbling block (see my recent quest to make it work on directories with spaces).

To run specific tests, e.g. all the tmux tests and bind.py:

tests/test_driver.py target/release/ tests/checks/tmux*.fish tests/pexpects/bind.py
2025-01-11 21:13:19 +01:00
Johannes Altmanninger
51adba6ee0 Restore autosuggestion after corrected typo
Backspace signals that the user is not happy with the commandline,
and by extension the autosuggestion.

For this reason, backspace suppresses autosuggestions until the next
text insertion.

However if I
1. type something that has an autosuggestion
2. type *one* wrong letter (removing the autosuggestion)
3. type backspace

backspace does not visibly suppress any autosuggestion but rhater
signal that the user wants to go back to the previous state of the
commandline, which does have an autosuggestion.

Enable this scenario by caching the autosuggestion when it's
invalidated. On certain edits that make the cached autosuggestion
valid again, restore it from the cache.  Currently, only do this up
to a single backspace.  Could extend that in future.

This implementation is really bad.. but it's a start.
Weirdly, it does not restore the cache on undo; but that's
inconsequential because undo doesn't suppress autosuggestion as
of today.

Closes #3549
2025-01-11 18:58:49 +01:00
kerty
d06ee1ee9c Fix .cpp to .rs and redundant closure 2025-01-11 18:58:49 +01:00
Johannes Altmanninger
7c539b9539 Rename the readline function for deleting active history item
history-pager-delete now also works for regular history search,
so rename it.
2025-01-11 18:58:49 +01:00
Mahmoud Al-Qudsi
f8b245eb31 completions/zfs: Add encryption-related completions 2025-01-11 10:44:40 -06:00
Johannes Altmanninger
4a6d8d0b3a Allow alt-enter and friends to insert into search field
Since this is user-visible, copy the logic rather than extracting
a function.
2025-01-11 13:50:08 +01:00
Johannes Altmanninger
0f1408e0ea Also autosuggest lines from multi-line command lines in history
My history often has erroneous single-line commands followed by
corrected versions. Sometimes the corrected versions only exist within
a multi-line commandline.  This means that autosuggestion skips over
the corrected versions and return a false positive.

Fix that by splitting the commandline into lines and suggesting those,
in reverse chronological order.

One other wart: shift-delete won't delete such autosuggestions from
history; instead it will flash the screen.

Line boundaries are not the best heuristic but they are an
improvement for the most part and fits with the current approach
where autosuggestion always operates on the entire line.

In future we should operate on processes and jobs.  But it may be
tricky - a backgrounding `&` should probably be included (in both?)
but `&&` or `;` probably not.

See also the discussion in
1c4e5cadf2 (diff-267c9f4da66412a9f439ac08d224356fe24265b5e1cebb6c44c2d55b96414513R59)
2025-01-11 13:50:08 +01:00
Johannes Altmanninger
411745ebce shift-delete to only delete from history if cursor at autosuggestion
If there is no history search or autosuggestion, shift-delete acts
as backspace, matching native macOS behavior.

I'm not sure if we want to keep that amount of overloaded behavior,
but let's assume so for now.

If that assumption holds, it may be confusing that shift-delete
deletes the autosuggestion if the cursor is here

	echo some command with autosuggstion
		^

So let's only do that if the cursor is actually at the autosuggestion,
I guess.
2025-01-11 13:50:08 +01:00
Johannes Altmanninger
f448ddd579 shift-delete to stop trying to delete completion-based autosuggestions from history
shift-delete attempts to delete the autosuggestion from history even
if the autosuggestion is not from history.

This is weird. We probably shouldn't do this. Let's flash the
commandline instead to try to reduce confusion.
2025-01-11 13:50:08 +01:00
Daniel Fleischer
29c45100fa Add lazygit completions (#11019) 2025-01-10 21:21:54 -06:00
Mahmoud Al-Qudsi
a4f91a8543 Don't override CTEST_PARALLEL_LEVEL env variable
I think the dynamic detection patch ends up overriding the environment variable
set by CI (if present), because `if(NOT CTEST_PARALLEL_LEVEL)` would define to
false even if an environment variable of that name existed then we end up
explicitly assigning the environment variable by that name upon invocation with
`env`.
2025-01-10 19:21:28 -06:00
Fabian Boehm
1f45ab63d1 staticbuilds: Build pcre2 statically for macos 2025-01-10 14:44:31 +01:00
Fabian Boehm
0f6e85466a CHANGELOG key_reader/indent as builtins 2025-01-10 14:16:01 +01:00
Mahmoud Al-Qudsi
417b2eb8c6 Re-add dynamic CTEST_PARALLEL_LEVEL detection
When it is not hard-coded in the environment variable of the same name.
2025-01-10 14:12:46 +01:00
Mahmoud Al-Qudsi
3bbfaf532e Bump CTEST_PARALLEL_LEVEL to match CTEST_BUILD_PARALLEL_LEVEL
This is an experiment to see if it causes any of the tests to flake and/or if it
even appreciably speeds up CI to begin with.

I note that there are tests added in 8bf8b10 that mutate global terminal state
but also note that local tests without CTEST_PARALLEL_LEVEL set at all have been
running to completion just fine without any observed flakiness *and* that our
Cirrus CI tests have this hard-coded to 6.
2025-01-10 14:12:46 +01:00
Fabian Boehm
c7358d14c8 Make fish_indent available as a builtin 2025-01-10 14:12:19 +01:00
Fabian Boehm
67eb0e8317 Make fish_key_reader available as a builtin
This brings us closer to making fish available as a single file.
2025-01-10 14:12:19 +01:00
Benjamin Weis
83586aebcc Update German translation 2025-01-10 14:10:36 +01:00
Mahmoud Al-Qudsi
c1a43b896c Skip select ebadf test under WSLv1 due to a WSL bug
WSLv1 won't return EBADF (or any error) if the fd was closed mid-select.
2025-01-09 17:30:08 -06:00
Mahmoud Al-Qudsi
0fcb2f7590 completions/cargo: Add --ignore-rust-version
New to 1.85; bypasses MSRV checks specified by `resolver = 3` or in
.cargo/config.toml
2025-01-09 17:06:31 -06:00
Mahmoud Al-Qudsi
e3868effe1 Update cargo dependencies 2025-01-09 17:00:30 -06:00
Mahmoud Al-Qudsi
b9c6806e45 Configure cargo to respect MSRV
The new 1.84 release has a new feature that makes `cargo update` MSRV-aware.

This is what it looks like in practice:

    Updating crates.io index
    Updating git repository `https://github.com/fish-shell/rust-pcre2`
From https://github.com/fish-shell/rust-pcre2
 * [new tag]         0.2.9-utf32 -> origin/tags/0.2.9-utf32
     Locking 7 packages to latest Rust 1.70 compatible versions
    Updating cc v1.2.6 -> v1.2.7
    Updating phf v0.11.2 -> v0.11.3
    Updating phf_codegen v0.11.2 -> v0.11.3
    Updating phf_generator v0.11.2 -> v0.11.3
    Updating phf_shared v0.11.2 -> v0.11.3
    Updating siphasher v0.3.11 -> v1.0.1
    Updating syn v2.0.94 -> v2.0.95
2025-01-09 16:50:13 -06:00
Fabian Boehm
b8208d72f7 Remove test for broken tmux output
Quite flaky on CI.

See #11036
2025-01-09 21:06:15 +01:00
Fabian Boehm
52cb42ba3d Remove unused fish_iswgraph 2025-01-09 20:20:28 +01:00
Klaus Hipp
b3aa79e9aa Fix completion typos
(cherry picked from commit 5c25d3c3b1)
2025-01-09 16:51:39 +01:00
Klaus Hipp
5c25d3c3b1 Fix completion typos 2025-01-09 16:51:39 +01:00
phanium
ef7aa793c6 Fix missing of builtin token description 2025-01-09 16:49:41 +01:00
phanium
fbf9ac8046 Fix missing of builtin token description
(cherry picked from commit ef7aa793c6)
2025-01-09 16:49:38 +01:00
Fabian Boehm
fac29e775a type: Do not translate the type "builtin"
This is a functional string, it should not be translated.

And we do not translate the others.
2025-01-09 16:42:28 +01:00
Fabian Boehm
fb6d3c3669 type: Do not translate the type "builtin"
This is a functional string, it should not be translated.

And we do not translate the others.
2025-01-09 16:41:44 +01:00
César Sagaert
d6dccc3c88 DNF5 completion support (#11035)
* dnf5 completions

* address comments

(cherry picked from commit 00c7baf68c)
2025-01-09 16:36:23 +01:00
César Sagaert
00c7baf68c DNF5 completion support (#11035)
* dnf5 completions

* address comments
2025-01-09 16:35:46 +01:00
Johannes Altmanninger
0e512f8033 Fix spurious blank lines when executing scrolled commandline
The result of

	commandline -i ": '$(seq $LINES)"\n"first scrolled line'"

is a commandline that is scrolled by one line.

Before executing that commandline, we move the cursor down by one
too many line. This is a regression from 610338cc70 (On undo after
execute, restore the cursor position, 2024-12-21). Fix that.

The test also demonstrates an unrelated problem, probably specific
to tmux.
2025-01-09 14:43:21 +01:00
Fabian Boehm
8304fd0fd0 tmux-job: Add more sleeps 2025-01-08 19:10:38 +01:00
Fabian Boehm
f4f786633d pexpects/bind: Add missing expect_prompt 2025-01-08 19:10:38 +01:00
Fabian Boehm
ec3b3fe321 pexpects/signals: Decrease a timeout that should be reached
Saves ~10% of the *total* testing time (except for `cargo test`)
2025-01-08 19:10:38 +01:00
Fabian Boehm
d3762f11b5 tmux-commandline: Print $LINES
Maybe this'll show us what the issue on NetBSD is
2025-01-08 19:10:38 +01:00
Fabian Boehm
6db0f39676 exit_nohang: Harden a bit 2025-01-08 19:10:38 +01:00
Branch Vincent
7970ca55af completions: add fish-lsp (#11017) 2025-01-08 11:25:36 -06:00
David Adam
ccbbae95ef update copyright years to be unbounded
There is no legal need to have the year written here and it's a chore to
keep it up to date.
2025-01-08 20:38:43 +08:00
Johannes Altmanninger
6d551b4459 Fix status buildinfo error on invalid args 2025-01-08 12:06:28 +01:00
Johannes Altmanninger
cc9083e220 Add some logging for XTGETTCAP 2025-01-08 12:06:28 +01:00
Johannes Altmanninger
14df28382d Work around terminals that echo DCS queries
Some terminals such as conhost and putty cannot parse DCS commands,
and will echo them back.

Work around this by making sure that this echoed text will not
be visible.

Do so by temporarily enabling the alternative screen buffer when
sending DCS queries (in this case only XTGETTCAP).  The alternative
screen buffer feature seems widely supported, and easier to get right
than trying to clear individual lines etc.

The alternative screen may still be visible for a
short time.  Luckily we can use [Synchronized Output](
https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036)
to make sure the screen change is never visible to the user.

Querying support for that is deemed safe since it only requires a
CSI command.

Note that it seems that every terminal that supports Synchronized
Output also parses DCS commands successfully.  This means that we
could get away without the alternative screen buffer in practice.
Not sure yet.

The implementation is slightly more complex than necessary in that it
defines a redundant ImplicitEvent. This is for two reasons: 1. I have
a pending change that wants to use it, so this removes diff noise and
2. we historically have sc/input_common.rs not depend on src/output.rs.
I dont' think any are strong reasons though.
2025-01-08 12:06:28 +01:00
Johannes Altmanninger
e6d57f2fb2 Minor style fix 2025-01-08 12:06:28 +01:00
Klaus Hipp
f36a7262db Revert "Fix typo in npm completions: isntall -> install" (#11014)
* Revert "Fix typo in npm completions: isntall -> install"

This reverts commit f4b01bb638.

* Add comments about typos in `npm` completions

(cherry picked from commit 4def0ac616)
2025-01-08 08:53:33 +08:00
Fabian Boehm
8a5b1ccc17 Revert "Probe for kitty keyboard protocol support"
This needs to be tested more, it has shown issues in MS conhost,
and potentially others.

Changing strategy after beta isn't the greatest idea.

This reverts commit 4decacb933.

See #10994
2025-01-07 20:28:24 +01:00
Klaus Hipp
4def0ac616 Revert "Fix typo in npm completions: isntall -> install" (#11014)
* Revert "Fix typo in npm completions: isntall -> install"

This reverts commit f4b01bb638.

* Add comments about typos in `npm` completions
2025-01-07 12:32:16 -06:00
Steve Walker
52a2bed38c fix python completion #10943
(cherry picked from commit b574a5e4f6)
2025-01-07 23:30:56 +08:00
Steve Walker
b574a5e4f6 fix python completion #10943 2025-01-07 23:30:27 +08:00
Klaus Hipp
cbfbac2198 Fix completion typos for apt-build, htop and wget (#11016)
(cherry picked from commit ea4e4a4279)
2025-01-07 21:48:23 +08:00
Klaus Hipp
a9b7dd1a9b Fix typos in docs (#11015)
(cherry picked from commit 9b67b2ae07)
2025-01-07 21:32:23 +08:00
Klaus Hipp
9b67b2ae07 Fix typos in docs (#11015) 2025-01-06 19:40:30 -06:00
Klaus Hipp
ea4e4a4279 Fix completion typos for apt-build, htop and wget (#11016) 2025-01-06 19:39:47 -06:00
Johannes Altmanninger
4decacb933 Probe for kitty keyboard protocol support
I believe this fixes more cases than it breaks.  For example
this should fix Termux which seems to be popular among fish
users. Unfortunately I haven't yet managed to test that one.

Cherry-pick of all of
- e49dde87cc (Probe for kitty keyboard protocol support, 2025-01-03)
- 10f1f21a4f (Don't send kitty kbd protocol probe until ECHO is disabled, 2025-01-05)
- dda4371679 (Stop sending CSI 5n when querying for kitty keyboard support, 2025-01-05)
2025-01-06 11:20:10 +01:00
Johannes Altmanninger
620eed466b Retry writing some escape sequences on EINTR
Cherry-picked from bc26481558.
2025-01-06 11:20:10 +01:00
Johannes Altmanninger
3405621dee Update littlecheck to fix spurious "not found" error on exit 127
Commit b6d76ae: we now use lines like "# RUN: fish=%fish %fish".
If a test exits with 127 we try to look up the command but use the
wrong name, which leads to unintelligible errors if the test exits
with 127 for other reasons.
2025-01-06 06:40:43 +01:00
Johannes Altmanninger
834001087d Disable kitty keyboard protocol on iTerm again for now
It causes alt-left to be sent as left in some cases; see #11004.

Upstream issue: https://gitlab.com/gnachman/iterm2/-/issues/12105
2025-01-06 06:24:13 +01:00
Johannes Altmanninger
e697add5b5 Feature flag to prevent executing off buffered keys
If I run "sleep 3", type a command and hit enter, then there is no
obvious way to cancel or edit the imminent command other than ctrl-c
but that also cancels sleep, and doesn't allow editing. (ctrl-z sort
of works, but also doesn't allow editing).

Let's try to limit ourselves to inserting the buffered command
(translating enter to a newline), and only execute once the user
actually presses enter after the previous command is done.
Hide it behind a new feature flag for now.

By making things less scary, this might be more user-friendly, at
the risk of breaking expectations in some cases.

This also fixes a class of security issues where a command like
`cat malicious-file.txt` might output escape sequences, causing
the terminal to echo back a malicious command; such files can still
insert into the command line but at least not execute it directly.
(Since it's only fixed partially I'm not really sure if the security
issue is a good enough motivation for this particular change.)

Note that bracketed paste probably has similar motivation as this feature.

Part of #10987
Closes #10991
2025-01-06 06:24:13 +01:00
Johannes Altmanninger
704b911168 Back out "Bind ctrl-l to clear-screen again for now"
As of the parent commits this should no longer cause breakage.

This backs out commit 07dd088d76.
2025-01-06 06:24:13 +01:00
Johannes Altmanninger
af137e5e96 scrollback-push to query for indn/cuu via XTGETTCAP
Some terminals like the Linux console don't support indn (scroll
forward). Let's query for the presence of these features, and fall
back to the traditional behavior if absent.

For now, break with the tradition of using the terminfo database that
we read ourselves. Instead ask the terminal directly via XTGETTCAP.
This is a fairly young feature implemented by terminals like xterm,
foot and kitty, however xterm doesn't expose these capabilities at
this point.

This is a good opportunity to try XTGETTCAP, since these are
capabilities we haven't used before. Advantages of XTGETTCAP are that
it works across SSH and is independent of $TERM (of course ignoring
$TERM may also be breaking to some users). Let's see if it sees
adoption in practice.

Tested to work on foot and kitty, allowing the default ctrl-l binding
to work without erasing any screen content.

See #11003
2025-01-06 06:24:13 +01:00
Johannes Altmanninger
75832b3c5d scrollback-push to fall back to clear-screen if missing CPR feature
The new ctrl-l implementation relies on Cursor Position Reporting (CPR)
This may not work on exotic terminals that don't support CSI 6n yet

As a workaround, probe for this feature by sending a CSI 6n (CPR)
on startup.  Until the terminal responds, have scrollback-push fall
back to clear-screen.

The theoretical problem here is that we might handle scrollback-push
before we have handled the response to our feature probe. That seems
fairly unlikely; also e49dde87cc has the same characteristics.

This could query a capability instead (via XTGETTCAP or otherwise)
but I haven't found one; and this seems at least as reliable.

While at it, change the naming a bit.

See #11003
2025-01-06 05:53:24 +01:00
Johannes Altmanninger
dda4371679 Stop sending CSI 5n when querying for kitty keyboard support
After we query kitty keyboard protocol support,
we send CSI 5n, to also receive a response if
the protocol is not supported.

However we don't bother to wait for the response, so this extra
message is not really useful (only to get better logs).  Remove it.
2025-01-06 05:51:38 +01:00
Johannes Altmanninger
10f1f21a4f Don't send kitty kbd protocol probe until ECHO is disabled
With tmux 3.0 (from 2019) inside SSH, the CSI 5n response is echoed.
I guess with all other terminals we were just lucky.  Move it to
right after where we disable ECHO I guess.

In general, asynchronous requests create a lot of potential for error,
we should try to get away from them.
2025-01-06 05:51:38 +01:00
Johannes Altmanninger
109ef88831 Add menu and printscreen keys
These aren't typically used in the terminal but they are present on
many keyboards.

Also reorganize the named key constants a bit.  Between F500 and
ENCODE_DIRECT_BASE (F600) we have space for 256 named keys.
2025-01-06 05:43:22 +01:00
Lzu Tao
33fe575112 Add more convenient key bindings for VI mode
To make it more familiar to vi/vim users.

In all mode, ctrl-k is bind to kill-line.

In Vi visual mode:
* press v or i turn into normal or insert mode respectively.
* press I turn to insert mode and move the cursor to beginning of line.
* because fish doesn't have upcase/locase-selection, and most people reach for
  g-U rather than g-u, g-U binds to togglecase-selection temporarily.

(cherry picked from commit f9b79926f1)
2025-01-05 23:00:55 +08:00
Lzu Tao
f9b79926f1 Add more convenient key bindings for VI mode
To make it more familiar to vi/vim users.

In all mode, ctrl-k is bind to kill-line.

In Vi visual mode:
* press v or i turn into normal or insert mode respectively.
* press I turn to insert mode and move the cursor to beginning of line.
* because fish doesn't have upcase/locase-selection, and most people reach for
  g-U rather than g-u, g-U binds to togglecase-selection temporarily.
2025-01-05 23:00:21 +08:00
David Adam
13f7e6d0a5 docs/interactive: update key bindings added for 4.0
(cherry picked from commit 6c3150aa05)
2025-01-05 22:28:45 +08:00
David Adam
6c3150aa05 docs/interactive: update key bindings added for 4.0 2025-01-05 22:27:00 +08:00
cornmander
44a8344da1 Add completions for Google Cloud commands. (#11005)
The `gcloud` and `gsutil` Google Cloud commands use argcomplete, so integrating them is easy with the `__fish_argcomplete_complete` function.

(cherry picked from commit d842a6560e)
2025-01-05 15:25:23 +08:00
Johannes Altmanninger
07dd088d76 Bind ctrl-l to clear-screen again for now
Testing has revealed some problems on BSD and Windows terminals and
the Linux Console, let's revert to the old implementation until these
are fixed.  Leaving the changelog entry for now since it shouldn't
take long.

See #11003
2025-01-05 08:20:53 +01:00
Johannes Altmanninger
93e0a33d41 Log human-readable values also for not-yet-decoded bytes 2025-01-05 03:37:31 +01:00
Stefan Boca
dcddffd222 refactor: misc cleanup (#10998)
* refactor EnvVar: Arc<Box<[WString]>> -> Arc<[WString]>

* remove unnecessary `&mut` from EnvVar methods

* clippy: use eq_ignore_ascii_case instead of manual comparison

see https://rust-lang.github.io/rust-clippy/master/index.html#manual_ignore_case_cmp

* clippy: use `is_some_and` and `is_ok_and` instead of `map_or`

see https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or

* clippy: use `assert!()` instead of `assert_eq!()` with booleans
2025-01-04 19:49:44 -06:00
cornmander
d842a6560e Add completions for Google Cloud commands. (#11005)
The `gcloud` and `gsutil` Google Cloud commands use argcomplete, so integrating them is easy with the `__fish_argcomplete_complete` function.
2025-01-04 19:45:05 -06:00
Mahmoud Al-Qudsi
b4e8cc8b79 Use explicit Timeout enum instead of magic constants
The FdReadableSet api was always intended to be converted to use Duration
instead of usec/msec once the ffi was removed. This lets us be explicit about
forever/infinite timeouts and removes the (small) chance of a collision between
u64::MAX and INFINITE.

I tried this out with `type Timeout = Option<Duration>` (only without the alias)
but was unhappy with easy it is to accidentally use `None` when you meant a
timeout of zero.
2025-01-04 18:40:36 -06:00
Mahmoud Al-Qudsi
83eb25d45f Mark function as test-only 2025-01-04 17:29:09 -06:00
David Adam
92919effc5 CHANGELOG: work on 4.0.0 2025-01-04 21:53:32 +08:00
Lzu Tao
046cadb53a Add completion for gem-fetch
(cherry picked from commit 7eb254f2ba)
2025-01-04 21:26:26 +08:00
Lzu Tao
7eb254f2ba Add completion for gem-fetch 2025-01-04 21:26:03 +08:00
idealseal
a5f99afa47 feat(comp): Update completions for resolvectl
(cherry picked from commit 2e12a2b6c4)
2025-01-04 20:42:44 +08:00
idealseal
2e12a2b6c4 feat(comp): Update completions for resolvectl 2025-01-04 20:42:31 +08:00
idealseal
24397c71cd feat(comp): Update completion for md5sum
(cherry picked from commit a780e4da15)
2025-01-04 20:39:56 +08:00
idealseal
a780e4da15 feat(comp): Update completion for md5sum 2025-01-04 20:39:33 +08:00
Johannes Altmanninger
566ff38fee Mention lack of support for ctrl-backspace and alternatives
Closes #10936

(cherry picked from commit cde503b0a8)
2025-01-04 20:32:06 +08:00
Thayne McCombs
7ea2ab4ebb fix[completions]: Add set-timeout to bootctl
(cherry picked from commit 33dd823f45)
2025-01-04 20:18:12 +08:00
Johannes Altmanninger
e6e647092d Fix off-by-one error in Vi-style upcase-word at commandline end
cursor_selection_mode=inclusive means the commandline position is
bounded by the last character. Fix a loop that fails to account
for this.

Fixes d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

This change looks very odd because if the commandline is like

	echo foo.

it makes us try to uppercase the trailing period even though that's
not part of word range.  Hopefully this is harmless.

Note that there seem to be more issues remaining, for example Vi-mode
paste leaves the cursor in an out-of-bounds odd position.

Fixes #10952
Closes #10953

Reported-by: Lzu Tao <taolzu@gmail.com>

(cherry picked from commit 69f0d960cf)
2025-01-04 20:17:32 +08:00
Thayne McCombs
33dd823f45 fix[completions]: Add set-timeout to bootctl 2025-01-04 20:15:53 +08:00
Johannes Altmanninger
e11e62674f Fix bad layout computation with right prompt
Commit 1c4e5cadf2 (Autosuggestions in multi-line
command lines, 2024-12-15) accidentally passed an empty
"commandline_before_suggestion" to compute_layout() when there is
no autosuggestion.

Closes #10996
2025-01-04 00:54:06 +01:00
Johannes Altmanninger
e49dde87cc Probe for kitty keyboard protocol support
We unconditionally request kitty keyboard protocol's progressive
enhancements.

It seems that a lot of terminals fail to parse CSI commands that
contain '=' such as \x1b[=5u.

1. [Midnight Commander](0ea77d2ec7)
2. Prompt 3 App (private bug tracker)
3. JetBrains IDEs https://youtrack.jetbrains.com/issue/IJPL-166234
4. Termux https://github.com/termux/termux-app/issues/4338
5. Amazon Linux Web Console https://github.com/amazonlinux/amazon-linux-2023/issues/871

It is difficult to fix the four remaining ones in a
timely manner, so let's query for support as described in
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#detection-of-support-for-this-protocol
This uses CSI 5 n (device status report), which is the older brother
of CSI 6 n (cursor position report) we use as of recently.

Query asynchronously and enable progressive enhancements as soon
as we get a response. In theory this allow `cat malicious-file.txt`
leading us to believe the protocol is supported.

See #10994
2025-01-03 23:20:19 +01:00
Fabian Boehm
5845a3f7ad __fish_complete_subcommand: Just complete -C for a given commandline
Fixes #10980.

This would, if a commandline was given, still revert to checking
the *real* commandline if it was empty.

Unfortunately, in those cases, it could have found a command and tried
to complete it.

If a commandline is given, that is what needs to be completed.

(note this means this is basically useless in completions that use it
like `sudo` and could just be replaced with `complete -C"$commandline"`)

(cherry picked from commit d5efef1cc5)
2025-01-03 19:35:14 +01:00
Fabian Boehm
edfdf210c4 Remove unnecessary use of errno 2025-01-03 19:34:57 +01:00
Johannes Altmanninger
996fec87f4 Demote logs about unexpected cursor position
As reported in
https://github.com/fish-shell/fish-shell/issues/10992#issuecomment-2568954940,
the user may reset the terminal and run scrollback-push without
repainting in between.  This means that the terminal will report
the cursor position y=0 x=0 which doesn't match what fish renders.
Fortunately, y=0 is a safe fallback value for the scrollback-push
use case.

While at it, fix an off-by-one error in a log.
2025-01-03 12:57:00 +01:00
Johannes Altmanninger
870a8f77a0 completions/scp: replace version detection
Version detection seems unreliable (see
https://github.com/fish-shell/fish-shell/issues/10445#issuecomment-2566232705
) so let's test for the actual feature.  On modern versions,"scp -O"
means "Use  the legacy SCP protocol for file transfers instead",
so presence of this feature indicates we are good.
2025-01-03 12:57:00 +01:00
Johannes Altmanninger
d823444c6e Apply autosuggestions from completions also if cursor is not at EOL
Before 1c4e5cadf2 (Autosuggestions in multi-line command lines,
2024-12-15), the completion code path in the autosuggestion performer
used to do something weird: it used to request completions for the
entire command line (with the implied cursor at end) but try to apply
the same completion at the actual cursor.

That commit changed this to request completions only up to the cursor
position, which could in theory make us produce valid completions even
if the cursor is not at end of the line.  However, that doesn't really
work since autosuggestions can only be rendered at the end of the line.
And the worst of it, that commit tries to compute

	line_at_cursor(&full_line, search_string_range.end)

which crashes as out-of-bounds if the completion needs to replace the token
(like a case-correcting completion does).

Let's apply completions to the end, matching how autosuggestions work
in general.
2025-01-03 12:56:04 +01:00
Johannes Altmanninger
abaeb4af2a scrollback-push to sanitize cursor position
I believe it's possible that the cursor position reported by the
terminal does not match fish's cursor.  In that case, overflow. Fix
that since we should not trust the terminal.

Also rename a confusingly named variable.

Mouse-click handling has a similar issue, fix that too.

FWIW, tmux always reports cursor position zero (\x1b[1;1R) when
querying from fish (but not when querying with printf).
Will investigate that next, see the linked issue.

Fixes #10992
2025-01-03 07:55:50 +01:00
David Adam
670541eec8 fish_jj_prompt: don't error if jj not installed 2025-01-03 12:38:14 +08:00
Johannes Altmanninger
0debddc9e5 Add a simple fish_jj_prompt
jj is often colocated with Git so the Git prompt also works, but
jj is always in a detached HEAD state, which is atypical for Git.
The jj prompt improves things by showing the revision ID which is
usually more useful than the commit ID.

This prompt is mostly adapted from the defaults for "jj log -r @".

Showing conflicting/empty commits seems useful.
Also perhaps bookmarks and tags, not sure.

The main problem with this prompt is that due to --ignore-working-copy,
the information may be stale.  That will be rectified after every jj
command, so hopefully this doesn't cause issues.
2025-01-03 00:03:58 +01:00
Erick Howard
837c32f150 Move getrusage wrapper in timer.rs to shared nix wrapper module
Closes #10988
2025-01-02 23:40:41 +01:00
Alexei Mikhailov
ff8a879e80 completions/exercism: use generate script
Exercism ships with it's own completions and a generation script, so let's use
that one instead.

(cherry picked from commit 9b26fff278)
2025-01-02 21:57:57 +08:00
Alexei Mikhailov
9b26fff278 completions/exercism: use generate script
Exercism ships with it's own completions and a generation script, so let's use
that one instead.
2025-01-02 21:57:17 +08:00
Klaus Hipp
6749a44d0f Update code completions
(cherry picked from commit 2b46d97c68)
2025-01-02 14:12:00 +08:00
Klaus Hipp
2b46d97c68 Update code completions 2025-01-02 14:11:24 +08:00
David Adam
65ced4e2bb Cargo.lock: update downstream dependencies 2025-01-02 13:20:15 +08:00
David Adam
3710142d1d Cargo.lock: update errno 2025-01-02 13:18:54 +08:00
David Adam
0c9c5e3a34 Cargo.toml/lock: upgrade serial_test
Slims the dependency tree down a bit; no breaking changes affect fish.
2025-01-02 13:09:54 +08:00
David Adam
53912777af Cargo.lock: upgrade cc 2025-01-02 12:38:50 +08:00
David Adam
70bd49f612 drop confstr implementation
Added in libc 0.2.163.

The constants for _CS_PATH are not implemented for some of the BSDs yet
(rust-lang/cmake#3612), so we need to keep our linking of this via the C
compiler for now.
2025-01-02 11:06:29 +08:00
David Adam
6714818e5d Cargo.toml: update libc 2025-01-02 10:44:23 +08:00
Peter Ammon
7e9b35be48 Fix a clippy 2025-01-01 17:42:25 -08:00
Peter Ammon
7af9844de0 highlight: make PathFlags an ordinary struct
No need for fancy bitflags.
2025-01-01 17:42:14 -08:00
EmilyGraceSeville7cf
550a076fa3 feat(completion) support batsh command
(cherry picked from commit 1bda6043c8)
2025-01-02 09:16:26 +08:00
EmilyGraceSeville7cf
c28659a045 feat(completion): support folderify command
(cherry picked from commit d8d5913159)
2025-01-02 09:16:26 +08:00
Benjamin Kellermann
d2608588fc add completion for btrbk (#10752)
* add completion for btrbk

completions for btrbk https://github.com/digint/btrbk/

* change indent + spaces

(cherry picked from commit 2ac1523e54)
2025-01-02 09:16:26 +08:00
Ilya Grigoriev
dd333cdc82 completions/tmux: add skeleton "Windows and Panes" bindings (#10854)
These are quite mechanical, but include all the commands (as of tmux
3.5a) in the "Windows and Panes" section of `man tmux`. For these
commands, I included the target-pane/session/client/window flags and the
-F formatstring flags (but not the less generic flags specific to
individual commands).

Nice completion is implemented for those flags where the helper
functions were already implemented previously.

After this, tmux pane<tab> will hopefully be useful.

A few TODOs mention low-hanging fruit for somebody who better
understands fish's `complete` command syntax (or a future me).

Another piece of low-hanging fruit would be completion for all the
target-window flags. This PR merely lists them.

(cherry picked from commit b1064ac3a0)
2025-01-02 09:14:37 +08:00
tranzystorekk
3129c9e939 environment_impl: drop usage of lazy_static 2025-01-01 12:23:24 -08:00
Erick Howard
967c4b2272 Code cleanup in src/bin/fish.rs to make it more idiomatic (#10975)
Code cleanup in `src/bin/fish.rs` to make it more idiomatic
2025-01-01 12:17:48 -06:00
Johannes Altmanninger
1c4e5cadf2 Autosuggestions in multi-line command lines
If I run

	$ command A
	$ command B
	$ command C

and find myself wanting to re-run the same sequence of commands
multiple times, I like to join them into a single command:

	$ command A &&
	    command B &&
	    command C

When composing this mega-commandline, history search can recall the
first one; the others I usually inserted with a combination of ctrl-k,
ctrl-x or the ctrl-r (since 232483d89a (History pager to only operate
on the line at cursor, 2024-03-22), which is motivated by exactly
this use case).

It's irritating that autosuggestions are missing, so try adding them.

Today, only single-line commands from history are suggested. In
future, we should perhaps also suggest any line from a multi-line
command from history.
2025-01-01 17:22:50 +01:00
Johannes Altmanninger
532abaddae Invalidate stale autosuggestions eagerly
If I type something that invalidates the autosuggestion, the
autosuggestion is still kept around in memory. This is used if
1. there is no valid autosuggestion for the new commandline
2. the user types something like "backspace backspace a"
   that both makes the cached autosuggestion valid again, and does
   not trigger autosuggestion suppression (hence backspace alone is
   not anough)

The fact that an autosuggestion might not match the current command
line makes it more difficult to implement autosuggestions on multiline
command lines.

For now let's invalidate autosuggestions eagerly, to enable the
next commit.  This heuristic invalidates too much but I don't think
that matters. We'll simply recompute the autosuggestion in those few
cases which.
2025-01-01 17:22:50 +01:00
Johannes Altmanninger
7049352e61 Extract function for potentially case-insensitive prefix check 2025-01-01 17:22:50 +01:00
Fabian Boehm
a4f4ae76cb staticbuilds: Run tests 2025-01-01 16:45:56 +01:00
Fabian Boehm
c3de539d46 test_driver: Error out if $FISHDIR isn't given
This avoids confusion when you forget to set it and run it on the
wrong fish.
2025-01-01 16:45:43 +01:00
Fabian Boehm
7bb38355e8 test_driver: Some more errors 2025-01-01 16:45:43 +01:00
Fabian Boehm
5520ee3c65 Document 2025-01-01 16:45:43 +01:00
Fabian Boehm
e66f6878b5 Make tests usable with path with spaces
This is somewhat subtle:

The #RUN line in a littlecheck file will be run by a posix shell,
which means the substitutions will also be mangled by it.

Now, we *have* shell-quoted them, but unfortunately what we need is to
quote them for inside a pre-existing layer of quotes, e.g.

    # RUN: fish -C 'set -g fish %fish'

here, %fish can't be replaced with `'path with spaces/fish'`, because
that ends up as

    # RUN: fish -C 'set -g fish 'path with spaces/fish''

which is just broken.

So instead, we pass it as a variable to that fish:

    # RUN: fish=%fish fish...

In addition, we need to not mangle the arguments in our test_driver.

For that, because we insist on posix shell, which has only one array,
and we source a file, we *need* to stop having that file use
arguments.

Which is okay - test_env.sh could previously be used to start a test,
and now it no longer can because that is test_*driver*.sh's job.

For the interactive tests, it's slightly different:

pexpect.spawn(foo) is sensitive to shell metacharacters like space.

So we shell-quote it.

But if you pass any args to pexpect.spawn, it no longer uses a shell,
and so we cannot shell-quote it.

There could be a better way to fix this?
2025-01-01 16:45:43 +01:00
Fabian Boehm
e9b9ee8d63 Fix docs if binary dir has a space
For some reason this is double-quoted if we quote this.
2025-01-01 16:45:43 +01:00
Fabian Boehm
17d57b70d0 littlecheck: Update to shell-quote replacements
Commit bb07435e3e4cbd34fcb667ec927353d176a0b2e8
2025-01-01 16:45:43 +01:00
Fabian Boehm
cb3d004a5a tests: Run filter-ctrl with %fish explicitly 2025-01-01 16:45:43 +01:00
Fabian Boehm
5e10d75a19 Tests: Don't cd to the tests directory!
We:

1. Set up a nice TMPDIR for our tests to use
2. Immediately `cd` to the directory containing the test runner.

So instead we don't do (2), and stay in the temp directory, and
explicitly use all the things from the test runner directory.

I am fairly certain that cmake papered over this by adding a second
layer of temp dir.
2025-01-01 16:45:43 +01:00
Fabian Boehm
050fe09af1 Compile fish_test_helper in the test driver 2025-01-01 16:45:43 +01:00
Fabian Boehm
b531cc8b43 tests: Specifically #require fish_test_helper when needed 2025-01-01 16:45:43 +01:00
Fabian Boehm
63e705a778 Let tests find fish and associated binaries via $FISHDIR
The default is still "../test/root/bin/", but we now pass this
through,
so you *can* run

`FISHDIR=$PWD ../tests/test_driver.sh $PWD/../tests/test.fish`
2025-01-01 16:45:43 +01:00
Fabian Boehm
1df8de06c1 Move littlecheck/pexpect to tests
This removes the need for a bunch of setup, and makes it easier to
make the tests agnostic to our test root setup.
2025-01-01 16:45:43 +01:00
Erick Howard
943adf4dd0 Avoid traversing wait handle list if searching by PID 2025-01-01 16:40:53 +01:00
Erick Howard
53dc7772eb Remove unnecessary clone when opening File for debug output 2025-01-01 16:34:40 +01:00
Hong Xu
64ed47bf4e Update .editorconfig to use "unset" instead of "off" (#10972)
This is inline with the [EditorConfig spec](https://spec.editorconfig.org/). The [EditorConfig Wiki](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length) was outdated and misleading, but have updated now.
2024-12-31 15:04:37 -06:00
Fabian Boehm
57a7920e15 CHANGELOG since 4.0b1 2024-12-31 14:35:55 +01:00
Fabian Boehm
6848e70e87 Disable two tests on NetBSD
One doesn't compile, the other's just borked for weird reasons
possibly related to tmux and $LINES?

With this, the test suite passes on NetBSD.
2024-12-31 13:04:28 +01:00
Fabian Boehm
d5efef1cc5 __fish_complete_subcommand: Just complete -C for a given commandline
Fixes #10980.

This would, if a commandline was given, still revert to checking
the *real* commandline if it was empty.

Unfortunately, in those cases, it could have found a command and tried
to complete it.

If a commandline is given, that is what needs to be completed.

(note this means this is basically useless in completions that use it
like `sudo` and could just be replaced with `complete -C"$commandline"`)
2024-12-30 21:01:21 +01:00
Fabian Boehm
e715c3e3ff help: Add special error for $BROWSER/$fish_help_browser being wrong 2024-12-30 21:01:21 +01:00
Johannes Altmanninger
13763fa318 Fix assertion error in when scrollback-push is enqueued from script
As soon as we start processing a scrollback-push readline command, we
pause execution of all other readline commands until scrollback-push
retires.  This means that we never get into a situation with two
active scrollback-push commands -- unless we are executing readline
commands via a script running "commandline -f":
since the first part of scrollback-push handling returns immediately,
the script will proceed before scrollback-push retires.

A second scrollback-push fails an assertion.  Work around that for now.
In future, scrollback-push should block when invoked by such a script,
just like it does when invoked from bindings.
2024-12-30 14:20:05 +01:00
Johannes Altmanninger
8910390602 Work around broken macOS CI seemingly missing parm_index in terminfo
Commit 83b0294fc9 (ctrl-l to scroll content instead of erasing screen,
2024-12-21) broke tests like tests/checks/tmux-autosuggestion.fish
on macOS CI.

I didn't get to the bottom of this but it's probably because terminfo
is broken on that CI system.

A (related?) failure mode can be observed using

	TERM=linux-m ssh my-mac tmux

ctrl-l moves the cursor but fails to scroll the text.

The only reason for using terminfo here was to be consistent with
the rest of the code base.  Let's use a hardcoded value instead;
I don't see why any terminal would deviate from xterm here.

This fixes macOS CI and the TERM=linux-m "misconfiguration".

It is possible that we should be using a different escape sequence
here; I'm not sure.
2024-12-30 14:20:05 +01:00
Johannes Altmanninger
b6c2a4c5db Remove trivial splice() call 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
a88de9d345 Remove unused data from autosuggestion cache 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
e8801d2ced Minor refactoring to reuse autosuggestion contructor 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
1d620356f8 Deduplicate command line update step when accepting autosuggestions 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8bb6597b9b Deduplicate layout computation logic 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8ae12973df Try to simplify commandline change hooks 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
459fc3c887 Fix failing history pager search replacing all lines
History pager search operates only on the current line, so a failing
search should only replace the current line with the search string.
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
a719f9d537 Minor refactoring in handle_execute
A failing ctrl-r search term is inserted back into the command line.
This should go through the same code path as other editions.
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
da0a93b24b Minor optimization in pager_selection_changed 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
8bb442f135 Minor cleanup in push_edit 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
3fcc6482cb Fix parse_util_process_extent including too much on the left 2024-12-30 10:50:38 +01:00
Johannes Altmanninger
83b0294fc9 ctrl-l to scroll content instead of erasing screen
On ctrl-l we send `\e[2J` (Erase in Display).  Some terminals interpret
this to scroll the screen content instead of clearing it. This happens
on VTE-based terminals like gnome-terminal for example.

The traditional behavior of ctrl-l erasing the screen (but not the
rest of the scrollback) is weird because:

1. `ctrl-l` is the easiest and most portable way to push the prompt
   to the top (and repaint after glitches I guess). But it's also a
   destructive action, truncating scrollback. I use it for scrolling
   and am frequently surprised when my scroll back is missing
   information.
2. the amount of lines erased depends on the window size.
   It would be more intuitive to erase by prompts, or erase the text
   in the terminal selection.

Let's use scrolling behavior on all terminals.

The new command could also be named "push-to-scrollback", for
consistency with others. But if we anticipate a want to add other
scrollback-related commands, "scrollback-push" is better.

This causes tests/checks/tmux-history-search.fish to fail; that test
seems pretty broken; M-d (alt-d) is supposed to delete the current
search match but there is a rogue "echo" that is supposed to invalidate
the search match.  I'm not sure how that ever worked.

Also, pexepect doesn't seem to support cursor position reporting,
so work around that.

Ref: https://codeberg.org/dnkl/foot/wiki#how-do-i-make-ctrl-l-scroll-the-content-instead-of-erasing-it
as of wiki commit b57489e298f95d037fdf34da00ea60a5e8eafd6d

Closes #10934
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
84f19a931d Also ignore invalid recursive escape sequences
We parse "\e\e[x" as alt-modified "Invalid" key.  Due to this extra
modifier, we accidentally add it to the input queue, instead of
dropping this invalid key.

We don't really want to try to extract some valid keys from this
invalid sequence, see also the parent commit.

This allows us to remove misplaced validation that was added by
e8e91c97a6 (fish_key_reader: ignore sentinel key, 2024-04-02) but
later obsoleted by 66c6e89f98 (Don't add collateral sentinel key to
input queue, 2024-04-03).
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
3201cb9f01 Stop parsing invalid CSI/SS3 sequences as alt-[/alt-o
This situation can be triggered in practice inside a terminal like tmux
3.5 by running 

	tmux new-session fish -C 'sleep 2' -d reader -o log-file

and typing "alt-escape x"

The log shows that we drop treat this as alt-[ and drop  the x on the floor.

	reader: Read char alt-\[ -- Key { modifiers: Modifiers { ctrl: false,
	alt: true, shift: false }, codepoint: '[' } -- [27, 91, 120]

This input ("\e[x") is ambiguous.

It looks like it could mean "alt-[,x".  However that conflicts with a
potential future CSI code, so it makes no sense to try to support this.

Returning "None" from parse_csi() causes this weird behavior of
returning "alt-[" and dropping the rest of the parsed sequence.
This is too easy; it has even crept into a bunch of places
where the input sequence is actually valid like "VT200 button released"
but where we definitely don't want to report any key.

Fix the default: report no key for all unknown sequences and
intentionally-suppressed sequences.  Treat it at "alt-[" only when
there is no input byte available, which is more or less unambiguous,
hence a strong enough signal that this is a actually "alt-[".
2024-12-30 10:50:38 +01:00
Johannes Altmanninger
e1e963ae66 Move cursor on mouse click via kitty's OSC 133 click_events=1
When the user clicks somewhere in the prompt, kitty asks the shell
to move the cursor there (since there is not much else to do).

This is currently implemented by sending an array of
forward-char-passive commands.  This has problems, for example it
is really slow on large command lines (probably because we repaint
everytime).

Implement kitty's `click_events=1` flag to set the
position directly.  To convert from terminal-coordinates
to fish-coordinates, query [CSI 6 n Report Cursor
Position](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
and use it to compute the left prompt's terminal-coordinates (which
are (0, 0) in fish-coordinates).

Unfortunately this doesn't yet work correctly while the terminal
is scrolled.  This is probably because the cursor position is wrong
if off-screen.  To fix that we could probably record the cursor
position while not scrolled, but it doesn't seem terribly important
(the existing implementation also doesn't get it right).

We still turn off mouse reporting.  If we turned it on, it
would be harder to select text in the terminal itself (not fish).
This would typically mean that mouse-drag will alter fish's
selection and shift+mouse-drag or alt+mouse-drag can be used.

To improve this, we could try to synchronize the selection: if parts
of the fish commandline are selected in the terminal's selection,
copy that to fish's selection and vice versa.

Or maybe there is an intuitive criteria, like: whenever we receive a
mouse event outside fish, turn off mouse reporting, and turn it back on
whenver we receive new keyboard input.  One problem is that we lose
one event (though we could send it back to the terminal). Another
problem is we would turn it back on too late in some scenarios.

Closes #10932
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
ca9c5f4cec Move some fake readline commands to a separate type 2024-12-30 10:50:01 +01:00
Johannes Altmanninger
48ae19b4b1 Update some stale doc comments 2024-12-30 10:50:01 +01:00
Johannes Altmanninger
7ec1487016 Deduplicate call to select() 2024-12-30 10:50:01 +01:00
Johannes Altmanninger
bc26481558 Retry writing some escape sequences on EINTR
Maybe we should be using SA_RESTART?
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
41e82c8c9e Protect some cursor movements against untimely ctrl-c
Commit 01dbfb0a3f (replace writestr() with fwprintf() in reader.cpp,
2016-12-20) accidentally replaced a retry-on-EINTR write with a
non-retrying version. Commit 7f31acbf9b (Prevent fish_title output
from triggering a bel, 2022-02-02) fixed this for some cases but
not all, fix that.
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
376bf3a982 Remove redundant return value from write_loop()
This function ought to match the standard write_all().
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
1e384900fa kitty kbd: stop parsing CSI R as F3
This has been removed, see kitty commit cd92d50a0 (Keyboard protocol:
Remove CSI R from the allowed encodings of the F3 key as it conflicts
with the *Cursor Position Report* escape code, 2022-12-24).
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
cde503b0a8 Mention lack of support for ctrl-backspace and alternatives
Closes #10936
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
69f0d960cf Fix off-by-one error in Vi-style upcase-word at commandline end
cursor_selection_mode=inclusive means the commandline position is
bounded by the last character. Fix a loop that fails to account
for this.

Fixes d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

This change looks very odd because if the commandline is like

	echo foo.

it makes us try to uppercase the trailing period even though that's
not part of word range.  Hopefully this is harmless.

Note that there seem to be more issues remaining, for example Vi-mode
paste leaves the cursor in an out-of-bounds odd position.

Fixes #10952
Closes #10953

Reported-by: Lzu Tao <taolzu@gmail.com>
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
ca28d0a78f Add missing test for Vi mode $
PR #10953 reports missing coverage for the change to update_buff_pos()
in d51f669647 (Vi mode: avoid placing cursor beyond last character,
2024-02-14).

Add a case demonstrating how $ should not move the cursor past the
last character. Goes without saying that it's really ugly that we
update_buff_pos() must be so defensive here, ideally we wouldn't pass
it out-of-bounds positions.
2024-12-30 10:50:01 +01:00
Johannes Altmanninger
6043644f52 completions/status: add buildinfo 2024-12-30 10:50:01 +01:00
Grant Hutchins
2f99a82700 Improve documentation for string escape
Before, it unnecessarily stated that there are three `--style` options, when
there are actually four.

I also align the default `--style=script` argument to the beginning of the line
to match the other options visually for easier scanning.
2024-12-29 13:49:05 -08:00
Grant Hutchins
1227b6765c Improve documentation for string escape
Before, it unnecessarily stated that there are three `--style` options, when
there are actually four.

I also align the default `--style=script` argument to the beginning of the line
to match the other options visually for easier scanning.
2024-12-29 13:48:34 -08:00
Fabian Boehm
905c7310c6 checks/type: Relax sh path even more
Fixes #10970
2024-12-29 22:11:34 +01:00
Ilya Grigoriev
b1064ac3a0 completions/tmux: add skeleton "Windows and Panes" bindings (#10854)
These are quite mechanical, but include all the commands (as of tmux
3.5a) in the "Windows and Panes" section of `man tmux`. For these
commands, I included the target-pane/session/client/window flags and the
-F formatstring flags (but not the less generic flags specific to
individual commands).

Nice completion is implemented for those flags where the helper
functions were already implemented previously.

After this, tmux pane<tab> will hopefully be useful.

A few TODOs mention low-hanging fruit for somebody who better
understands fish's `complete` command syntax (or a future me).

Another piece of low-hanging fruit would be completion for all the
target-window flags. This PR merely lists them.
2024-12-29 15:37:21 +01:00
EmilyGraceSeville7cf
1bda6043c8 feat(completion) support batsh command 2024-12-29 15:36:00 +01:00
EmilyGraceSeville7cf
d8d5913159 feat(completion): support folderify command 2024-12-29 15:35:25 +01:00
Benjamin Kellermann
2ac1523e54 add completion for btrbk (#10752)
* add completion for btrbk

completions for btrbk https://github.com/digint/btrbk/

* change indent + spaces
2024-12-29 15:33:29 +01:00
Łukasz Wieczorek
9cea5e0732 Remove redundant newlines, add .idea to gitignore
* Add .idea/ to git ignored directories.

* Remove redundant newline.

* Remove redundant newline.

* Remove redundant newlines.

* Remove redundant newline.

* Remove redundant newline.

* Add missing newline at end of file.

* Remove redundant newline.

* Remove redundant newlines.
2024-12-29 15:31:03 +01:00
Fabian Boehm
5f76fc3e41 Add status buildinfo (#10896)
This can be used to get some information on how fish was built - the
version, the build system, the operating system and architecture, the
features.

(cherry picked from commit 6f9ca42a30)
2024-12-29 13:37:29 +01:00
Fabian Boehm
6f9ca42a30 Add status buildinfo (#10896)
This can be used to get some information on how fish was built - the
version, the build system, the operating system and architecture, the
features.
2024-12-29 13:37:28 +01:00
Joan Bruguera Micó
c0a2b55efd Create new base directories with mode 0700
If base directories (e.g. $HOME/.config/fish) need to be created,
create them with mode 0700 (i.e. restricted to the owner).
This both keeps the behavior of old fish versions (e.g. 3.7.1) and is
compliant with the XDG Base Directory Specification.

See: https://specifications.freedesktop.org/basedir-spec/0.8/#referencing
2024-12-28 12:14:14 -08:00
Joan Bruguera Micó
b8df9648f2 Create new base directories with mode 0700
If base directories (e.g. $HOME/.config/fish) need to be created,
create them with mode 0700 (i.e. restricted to the owner).
This both keeps the behavior of old fish versions (e.g. 3.7.1) and is
compliant with the XDG Base Directory Specification.

See: https://specifications.freedesktop.org/basedir-spec/0.8/#referencing
2024-12-28 12:13:48 -08:00
Fabian Boehm
f75912d205 Create release-with-debug cargo profile, hook it up with cmake
Fixes #10959

(cherry picked from commit 66b80041cc)
2024-12-28 16:04:18 +01:00
Fabian Boehm
66b80041cc Create release-with-debug cargo profile, hook it up with cmake
Fixes #10959
2024-12-28 16:03:40 +01:00
Kid
701853fdd3 docs: Distinguish documents in sidebar
(cherry picked from commit a579abb81b)
2024-12-28 08:42:59 +01:00
Kid
a579abb81b docs: Distinguish documents in sidebar 2024-12-28 08:42:46 +01:00
Peter Ammon
b97598fa6c Clean up some logic around handling the parser blocks
Fix a todo. Enforce reverse iteration order.
2024-12-27 16:42:38 -08:00
Peter Ammon
64cb86ac26 Stop copying node sources so aggressively in parse_execution
Eliminates some allocations and fixes a TODO.
2024-12-27 15:47:34 -08:00
Peter Ammon
a14906f52f Fix a todo!
Stop cloning the delimiter unnecessarily in builtin read.
2024-12-27 15:00:59 -08:00
Peter Ammon
36d7049749 Minor cleanup of other unsafe impl 2024-12-27 14:46:46 -08:00
Peter Ammon
4b9767ce83 Remove as_ptr from IoData
We don't need this. Also improve IoChain::remove().
2024-12-27 14:36:55 -08:00
Peter Ammon
f6d76d2057 Remove some unsafe impls of Send / Sync
We no longer have C++ so we don't need these; Rust does the right thing by
default.
2024-12-27 14:14:47 -08:00
Peter Ammon
659c926dbd Additional cleanup of io buffering
Eliminate some ugly bits. No functional change expected.
2024-12-27 14:09:07 -08:00
Peter Ammon
56da15d11f Rework the file descriptor monitor
[Do NOT cherry-pick to 4.0 - this needs more time to be tested]

fish sometimes needs to capture the output of a command or block of
commands. Examples include fish_prompt or any command substitution
("cmdsubs"). It does this the obvious way: by creating a pipe, using dup2
to replace stdout of the command with the write end of the pipe, and then
reading from the read end into a buffer, until EOF or the command
substitution completes. Importantly, this task also overlaps with waiting
for the process to exit; that is when executing:

    set var (some_cmd)

fish needs to both wait on `some_cmd` and ALSO read its output into memory.
This is awkward to do in a portable way in a single thread (though maybe
doable on Linux with pidfd). So we wait and read on different threads.

To make things worse, command substitutions may themselves create
additional command substitutions (recursion, etc). Creating a read thread
for every command substitution would result in excessive threads. So rather
than a thread per cmdsub, we have a single dedicated thread that handles
ALL command substitutions, by multiplexing multiple file descriptors via
select/poll. This is the "fd monitor." You hand it a file descriptor and it
lets you know when it's readable, and then you can read from it (via a
callback). Also, it has a "wakeup" fd: if you write to that then the fd
monitor wakes up, figures out what it has to do, and resumes.

When the command substitution ends, we need to remove the fd from the fd
monitor, because we intend to close it. You might object "the commands in
the cmdsub have all completed so the write end of the pipe has been closed
so the fd monitor can just notice that the pipe is closed" but it's not so:
consider the horrible case of `set var (yes &)` and abandon all hope.

The current mechanism for removing the fd from the monitor is called a
"poke." We tell the fd monitor (through a "control" self-pipe) to
explicitly wake up the item. It then invokes the callback ("pokes") the
item on the dedicated fd monitor thread. The item notices that the command
substitution is complete, and it returns a value meaning "remove me" and
the fd monitor does so. The client thread is stuck waiting for this process
to complete.

So basically removing a fd from the monitor requires a round trip to its
dedicated thread. This is slow and also complicated (Rust doesn't have
futures)!

So let's not do that.

The big idea is to remove this round-trip synchronization. That is, when we
intend to remove the fd from the fd monitor, we _just do it_ and then close
the fd. Use a lock rather than a round-trip to the thread. Crucially that
lock is unlocked while the monitor thread waits in select/poll.

This invites all sorts of races:

1. fish might remove and close the fd right before the monitor polls it. It
   will thus attempt to poll a closed fd.
2. fish might remove and close the fd, and then something else opens a file
   and receives the same fd. Now the fd monitor will poll an fd that was
   never added.
3. fish might remove and close the fd _while the fd monitor is polling it_.
   What happens then? (Turns out on macOS we get EBADF, and on Linux the fd is
   marked readable).

The Big Idea is that *all of these races are benign*. As long as
poll/select doesn't crash or hang, we don't care *what* it returns, because
the source of truth are the set of items stored in the fd monitor and these
item IDs are never recycled. (This also assumes that it's OK to select/poll
on random file descriptors; there ought to be no side effects).

Not only is this a large simplification since we no longer need that round
trip, it's a substantial performance improvement as well. The
"aliases.fish" benchmark goes from 164 to 154 msec on my Mac, and from 124
to 112 msec on my Linux machine - nearly 10%.

Add some tests to verify our assumptions about the behavior of closing or
replacing a file descriptor during poll. But even if these fail, all we
care about is that poll/select doesn't crash or hang.
2024-12-27 13:23:11 -08:00
Peter Ammon
5e59762117 FdMonitor: Use a HashMap instead of Vec of items
Preparing for a substantial optimization.
2024-12-27 13:23:11 -08:00
Peter Ammon
69fdbc89d6 Refactor FdMonitorItem readability checks
No functional change. Preparing for an optimization.
2024-12-27 13:21:44 -08:00
Peter Ammon
244c55f9ce FdMonitor: change_signaller to be held strongly not weakly
There's no reason to use Weak here, especially since we just unwrap it. There's
no reference cycles, so just share the data via Arc.
2024-12-27 13:21:44 -08:00
Peter Ammon
b7ae159824 Remove the ability for FdMonitorItems to have timeouts
FdMonitor is used to monitor a set of file descriptors and invoke a callback
when one becomes readable. Prior to this commit, they coudl also have the
callback invoked on timeout. fish used to use this feature but no longer does;
remove it.
2024-12-27 13:03:49 -08:00
Peter Ammon
6dad396498 Clean up some stale comments 2024-12-27 13:03:49 -08:00
Fabian Boehm
f5a02e590d Fix tmux-multiline-prompt check 2024-12-27 21:02:38 +01:00
Fabian Boehm
36c632889b pexpects: Fix some escapes
Python has become stricter about unknown `\x` in strings, firing a
SyntaxWarning right now.

They need to be `\\x`.
2024-12-27 20:05:10 +01:00
Dmitry Gerasimov
ea2c53ca85 completions/dnf: Fix completions for DNF5 (#9862)
Since DNF5 there's no implicit \n in repoquery output. For DNF4 this change
leaves blank lines in the output, but they are ignored anyway.
2024-12-26 12:02:22 -08:00
Dmitry Gerasimov
c473aa60a7 completions/dnf: Fix completions for DNF5 (#9862)
Since DNF5 there's no implicit \n in repoquery output. For DNF4 this change
leaves blank lines in the output, but they are ignored anyway.
2024-12-26 12:01:49 -08:00
David Adam
6515862095 Debian packaging: move comments to their own lines 2024-12-26 14:53:04 +08:00
phanium
06105e9207 Fix alt-e cursor position restore on Vim <= 8 (#10946)
Cherry-picked from commit 94dfe1b053
2024-12-26 06:40:41 +01:00
David Adam
e858322749 Debian packaging: add some missing runtime dependencies
(cherry picked from commit eade6a5672)
2024-12-26 13:37:30 +08:00
David Adam
bd2ddda9a4 update CMake requirement
find_rust uses LIST(POP_BACK), which was added in 3.15.

(cherry picked from commit 044cea1bf3)
2024-12-26 13:37:30 +08:00
David Adam
6db110916b Debian packaging: reformat dependencies
(cherry picked from commit 74b1247461)
2024-12-26 13:37:30 +08:00
phanium
94dfe1b053 Fix alt-e cursor position restore on Vim <= 8 (#10946) 2024-12-26 06:35:37 +01:00
David Adam
0b52b72ebc Debian packaging: comment on reason for runtime dependencies 2024-12-26 13:22:30 +08:00
David Adam
eade6a5672 Debian packaging: add some missing runtime dependencies 2024-12-26 13:21:33 +08:00
David Adam
044cea1bf3 update CMake requirement
find_rust uses LIST(POP_BACK), which was added in 3.15.
2024-12-26 13:20:00 +08:00
David Adam
74b1247461 Debian packaging: reformat dependencies 2024-12-26 13:19:41 +08:00
Fabian Boehm
d707a516d2 docs: Use grid in the CSS (#10942)
Instead of hardcoded 230px margin.

This also makes the ToC only take up a third of the screen when
narrow, and lets you scroll the rest.

Without, you'd have to scroll past the *entire* ToC, which is awkward

Remaining issue is the search box up top. Since this disables the one
in the sidebar once the window gets too narrow, that one is important,
and it isn't *great*

(cherry picked from commit 9b8793a2df)
2024-12-25 14:50:29 +01:00
Fabian Boehm
9b8793a2df docs: Use grid in the CSS (#10942)
Instead of hardcoded 230px margin.

This also makes the ToC only take up a third of the screen when
narrow, and lets you scroll the rest.

Without, you'd have to scroll past the *entire* ToC, which is awkward

Remaining issue is the search box up top. Since this disables the one
in the sidebar once the window gets too narrow, that one is important,
and it isn't *great*
2024-12-25 14:50:27 +01:00
Blair Noctis
6c63139d23 refactor: macroize SIGNAL_TABLE entries
reducing boilerplate and chance of typo
2024-12-24 15:25:10 +01:00
Mahmoud Al-Qudsi
f3dd4ee022 Fix typo in hard-coded name of SIGSTKFLT 2024-12-23 14:29:00 -06:00
Mahmoud Al-Qudsi
7bafb0d1ae CHANGELOG: Fix Sphinx error on unnamed section 2024-12-23 13:54:21 -06:00
Mahmoud Al-Qudsi
46072e0fd6 completions/llm: Add completions for all subcommands 2024-12-23 13:50:10 -06:00
Mahmoud Al-Qudsi
c09a9246a1 completions/llm: Fix broken completion 2024-12-23 13:47:19 -06:00
Fabian Boehm
e2596d13cd Remove SIGUNUSED
It is, as the name implies, unused - it became SIGSYS, which we
already check.

Since it is entirely undefined on some architectures it causes a build
failure there, see discussion in #10633
2024-12-23 17:06:22 +01:00
Fabian Boehm
aed52049ab Remove SIGUNUSED
It is, as the name implies, unused - it became SIGSYS, which we
already check.

Since it is entirely undefined on some architectures it causes a build
failure there, see discussion in #10633
2024-12-23 17:01:04 +01:00
Johannes Altmanninger
0153579a4c Fix build in non-colocated jj workspaces 2024-12-23 15:14:13 +01:00
Johannes Altmanninger
5fed900b94 Temporary workaround for BSD WEXITSTATUS libc bug
The libc crate has a bug on BSD where WEXITSTATUS is not an 8-bit
value, causing assertion failures.

Any libc higher than our 0.2.155 would increase our MSRV, see libc
commit 5ddbdc29f (Bump MSRV to 1.71, 2024-01-07), so we want to
woraround this anyway.  It's probably not worth using a patched
version of libc since it's just one line.

While at it, tighten some types I guess.

Upstream fix: https://github.com/rust-lang/libc/pull/4213

Closes #10919

Cherry-picked from c1b460525c
2024-12-23 14:43:37 +01:00
Johannes Altmanninger
70ba81e5b3 Provide old implementation of cancel-commandline as fallback
__fish_cancel_commandline was unused (even before) and has some issues
on multiline commandlines. Make it use the previously active logic.

Closes #10935

Cherry-picked from 5de6f4bb3d
2024-12-23 14:43:33 +01:00
Johannes Altmanninger
c1b460525c Temporary workaround for BSD WEXITSTATUS libc bug
The libc crate has a bug on BSD where WEXITSTATUS is not an 8-bit
value, causing assertion failures.

Any libc higher than our 0.2.155 would increase our MSRV, see libc
commit 5ddbdc29f (Bump MSRV to 1.71, 2024-01-07), so we want to
woraround this anyway.  It's probably not worth using a patched
version of libc since it's just one line.

While at it, tighten some types I guess.

Upstream fix: https://github.com/rust-lang/libc/pull/4213

Closes #10919
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
5de6f4bb3d Provide old implementation of cancel-commandline as fallback
__fish_cancel_commandline was unused (even before) and has some issues
on multiline commandlines. Make it use the previously active logic.

Closes #10935
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
54cc932215 Attempt to fix clippy lints 2024-12-23 14:34:59 +01:00
Johannes Altmanninger
e3864c752a Changelog: move integration branch entries there
See f237fb7b on the integration branch.
2024-12-23 14:34:59 +01:00
Johannes Altmanninger
f237fb7b9f Changelog: move over the bits that apply to this branch
This seems more logical, especially since these need not be mentioned
in the "final" 4.0.  When we merge the integration branch back into
master, we can combine changelog additions, so it won't be lost
from master.
2024-12-23 14:32:30 +01:00
Johannes Altmanninger
03a9f4a775 sourcehut builds: remove obsolete "env"
As of efe4083dce (fish.spec/.builds: drop SHOW_INTERACTIVE_LOG,
2022-06-08) this is no longer necessary.
2024-12-23 08:40:02 +01:00
Johannes Altmanninger
7e5af914be Remove interactive-only completion hacks
I don't think these characters cause problems in filenames?
2024-12-23 08:40:02 +01:00
Johannes Altmanninger
ab4606430e Sort parser keywords 2024-12-23 08:40:02 +01:00
Fabian Boehm
774b7c7b5b staticbuilds: Make mac builds statically linked
This is the default on musl, but not other libcen
2024-12-22 22:25:27 +01:00
Fabian Boehm
6b1a9ef7ce staticbuilds: Add macos job 2024-12-22 22:21:42 +01:00
Fabian Boehm
c74afd4198 CHANGELOG 2024-12-22 18:16:07 +01:00
Fabian Boehm
3dc49d9d93 Allow installable builds to be installed into a specific path (#10923)
* Pass path to install()

It was dirty that it would re-get $HOME there anyway.

* Import wcs2osstring

* Allow installable builds to use a relocatable tree

If you give a path to `--install`, it will install fish into a
relocatable tree there, so

PATH/share/fish contains the datafiles
PATH/bin/fish contains the fish executable
PATH/etc/fish is sysconf

I am absolutely not sold on that last one - the way I always used
sysconfdir is that it is always /etc. This would be easy to fix but
should probably also be fixed for "regular" relocatable builds (no
idea who uses them).

An attempt at #10916

* Move install path into "install/" subdir

* Disable --install harder if not installable
2024-12-22 18:16:07 +01:00
Fabian Boehm
7069f3fe40 Allow installable builds to be installed into a specific path (#10923)
* Pass path to install()

It was dirty that it would re-get $HOME there anyway.

* Import wcs2osstring

* Allow installable builds to use a relocatable tree

If you give a path to `--install`, it will install fish into a
relocatable tree there, so

PATH/share/fish contains the datafiles
PATH/bin/fish contains the fish executable
PATH/etc/fish is sysconf

I am absolutely not sold on that last one - the way I always used
sysconfdir is that it is always /etc. This would be easy to fix but
should probably also be fixed for "regular" relocatable builds (no
idea who uses them).

An attempt at #10916

* Move install path into "install/" subdir

* Disable --install harder if not installable
2024-12-22 18:13:29 +01:00
Integral
b19a467ea6 Replace some PathBuf with Path avoid unnecessary heap allocation (#10929) 2024-12-21 12:34:27 -06:00
Johannes Altmanninger
381b38af0a Skip tmux multiline prompt test for BusyBox less
BusyBox less is present on alpine CI; it doesn't support the "+q"
command passing style, so it's not directly usable by this test.
2024-12-21 14:41:41 +01:00
Johannes Altmanninger
965bc78d33 Work around weird CI failures due to missing pre-execute \r\n
I forgot that 610338cc70 (On undo after execute, restore the cursor
position, 2024-12-21) would cause a fallout to tests:

It makes us reuse in another place our usual cursor-movement sequences.

This causes failures like this (linebreaks added for readability):

	Testing file pexpects/bind.py:Failed to match pattern: (?:\r\n|\x1b\[2 q)[^\n]*def abc\r\n
	bind.py:45: timeout from expect_prompt(TO_END + "def abc\r\n")  # emacs transpose words, default timeout: no delay

	Escaped buffer:
	\x1b[?2004h\x1b[>4;1m\x1b[=5u\x1b=\rprompt 2>echo \rprompt 2>echo abc \rprompt 2>echo def abc\r
	prompt 2>echo def abc\x1b[?2004l\x1b[>4;0m\x1b[=0u\x1b>\x1b]133;C\x07def abc\r\n\x1b]133;D;0\x07\x1b[?25h⏎
	\r⏎ \r\rprompt 3>\x1b[?2004h\x1b[>4;1m\x1b[=5u\x1b=

It seems that we don't print anything where we should print something
like "\r\n" or "\e[2 q" to move the cursor below the command line.

I haven't gotten to the bottom of this but it might be related to
terminfo. Once we get rid of that, we can unconditionally print
our canonical movement sequences.

This issue seems to only affect tests, since fish operates fine in
a sourcehut CI system. Let's ignore it for now.
2024-12-21 14:37:57 +01:00
Johannes Altmanninger
610338cc70 On undo after execute, restore the cursor position
Ever since 149594f974 (Initial revision, 2005-09-20), we move the
cursor to the end of the commandline just before executing it.

This is so we can move the cursor to the line below the command line,
so moving the cursor is relevant if one presses enter on say, the
first line of a multi-line commandline.

As mentioned in #10838 and others, it can be useful to restore the
cursor position when recalling commandline from history. Make undo
restore the position where enter was pressed, instead of implicitly
moving the cursor to the end. This allows to quickly correct small
mistakes in large commandlines that failed recently.

This requires a new way of moving the cursor below the command line.
Test changes include unrelated cleanup of history.py.
2024-12-21 13:10:34 +01:00
Johannes Altmanninger
f9fb026085 Document possible CMake/Rust versions usable for Git bisect
rustc and CMake are usually backwards compatible but with Corrosion
in the mix this is often not the case.
Here's the canonical place to document it.
2024-12-21 13:07:01 +01:00
Johannes Altmanninger
1e7de063bd Fix regression of builtin read not exiting on ctrl-c
Commit 8bf8b10f68 (Extended & human-friendly keys, 2024-03-30) stopped
ctrl-c from exiting without a motivation. Unfortunately this was
only noticeable on terminals that speak the kitty keyboard protocol,
which is probably no one had noticed so far.

Closes #10928
2024-12-21 05:54:52 +01:00
David Adam
541f8b47bf Revert "Add completions for dust"
This reverts commit 27c7578760.

dust generates its own completions (which are shipped in the wrong spot
in the Debian packages, but which are also more up-to-date).

Closes #10922.
2024-12-19 19:49:01 +08:00
David Adam
6eec2db292 fish.spec: update dependencies for the terminfo database
RH/Fedora and openSUSE use different package names.

Closes #10920.
2024-12-19 14:48:01 +08:00
Johannes Altmanninger
039011bc81 Make full autosuggestions case-correcting again
Fixes ca21872d14 (Clean up the accept-autosuggestion code path a
little bit, 2024-11-14).
Fixes #10915
2024-12-18 19:02:27 +01:00
metamuffin
9abec243a4 Completions for mksquashfs (#10909) 2024-12-18 10:36:30 -06:00
Fabian Boehm
f89e26b06e installable: Reword $HOME error 2024-12-18 17:26:25 +01:00
David Adam
80d53b129f macOS codesigning: use stable Rust
The apple-codesign crate has a fairly aggressive MSRV policy, and the
compiler itself still targets 10.12 which is well below the minimum
version of macOS for aarch64. Just use stable.
2024-12-18 23:38:13 +08:00
Ilya Grigoriev
7162822486 rclone.fish: assume a recent version if the version cannot be parsed
The version of rclone is set during compilation and could be any crazy string depending on the packager, whether it's a dev build, etc. If it cannot be parsed, let's assume a recent version.

Follows up on cc8fa0f7
2024-12-18 15:31:51 +01:00
David Adam
7c2a379674 RPM/Debian packaging: add find dependency
Closes #10913
2024-12-18 11:04:41 +08:00
Klaus Hipp
25534bf657 Add tex-fmt completions 2024-12-18 02:21:57 +08:00
David Adam
687001f8b7 Merge branch 'Integration_4.0.0'
This merge throws away a commit from master which was a duplicate of one on
Integration_4.0.0, and just allows the history to remain mostly-linear.
2024-12-17 23:54:00 +08:00
David Adam
e6fea730e2 Update Cargo.lock with version number bump from Cargo.toml 2024-12-17 23:48:48 +08:00
Fabian Boehm
b56bb80a14 tests/version: Update for "-beta"
We used to call our beta versions "...b1", but cargo doesn't like
that.

So we need to adjust the regex here.
2024-12-17 16:44:34 +01:00
Fabian Boehm
5fc47f37a6 Update Cargo.lock
This includes the crate version, so any build would otherwise claim
it's "dirty"
2024-12-17 16:44:10 +01:00
David Adam
8557c3c48c Release 4.0b1 2024-12-17 22:51:11 +08:00
David Adam
c54dfa12c1 CHANGELOG: work on 4.0.0 2024-12-17 22:23:32 +08:00
Klaus Hipp
67fa71a94d Update zed completions (#10907)
Add uninstall option.
2024-12-16 19:42:57 -06:00
Johannes Altmanninger
0275c5e803 Swap variable overrides and time in not statement
This is allowed

	time a=b echo 123

but -- due to an oversight in 3de95038b0 (Make "time" a job prefix,
2019-12-21) -- this is not allowed:

	not time a=b echo 123

Instead, this one one works:

	not a=b time echo 123

which is weird because without the "not" this would run "/bin/time".

It seems wrong that "not" is not like the others. Swap the order
for consistency.

Note that unlike "not", "time" currently needs to come before variable
assignments, so "a=b time true" is disallowed. This matches zsh. POSIX
shells call "/bin/time" here. Since it's ambiguous, erroring out seems
fine. It's weird that we're inconsistent with not here but I guess
"command not" is not expected to have subtly different behavior.

Closes #10890
2024-12-16 06:33:47 +01:00
Johannes Altmanninger
8fd0399ed3 Remove runaway kw_builtin in not statement definition
This was added accidentally in 971d257e67 (Port AST to Rust,
2023-04-02).  It does not seem to be causing an observable effect
(although I didn't try hard).
2024-12-16 06:33:47 +01:00
Johannes Altmanninger
ac951427af Fix alt-l on multiline tokens
This would invoke test with extra arguments.
2024-12-16 06:33:47 +01:00
Fabian Boehm
95f4c9c07e One more FreeBSD-only-in-CI 2024-12-15 17:38:37 +01:00
Fabian Boehm
8add30e3bf pexpects: Disable exit on CI Darwin/FreeBSD 2024-12-15 17:33:12 +01:00
Fabian Boehm
cb3fbd3a5c pexpects: Disable 2 only on CI
As the comment says
2024-12-15 17:32:47 +01:00
Fabian Boehm
9b9663ea44 CHANGELOG: We need a C compiler even for the main binary
Not just libc.c, but also the rsconf tests.
2024-12-15 17:15:35 +01:00
David Adam
a23cd62ec7 RPM/Debian packaging: update dependencies to match reality 2024-12-15 23:53:55 +08:00
David Adam
489d6b9dd8 CHANGELOG: work on 4.0.0 2024-12-15 23:52:30 +08:00
Fabian Boehm
10ac98e2ea installable: Only panic without sphinx if FISH_BUILD_DOCS=1
It's pretty annoying that this panics without sphinx, because the
install itself would be *working*.

So instead we tell the user that they need to clean or set
$FISH_BUILD_DOCS if they want to try again.
2024-12-15 09:00:16 +01:00
Fabian Boehm
46ce01223b staticbuilds: Fix aarch64 cross-compile
We get "undefined reference to `__memmove_chk'" when compiling
pcre2 (via pcre2-sys) on newer Ubuntu.

That one is used with higher fortify_source levels, and Ubuntu 24.04
defaults to 3, while my arch system (where I cannot reproduce)
defaults to 2.
2024-12-14 13:39:20 +01:00
Fabian Boehm
50c737fa55 CHANGELOG 2024-12-14 12:14:55 +01:00
Fabian Boehm
a98997fab0 curses: Just use our hardcoded xterm-256color entry as the fallback
The values we would try are:

xterm-256color, xterm, ansi, dumb

This is a pretty useless list, because systems without
"xterm-256color" but with "ansi" basically don't exist,
and it is very likely that the actual terminal is more
xterm-compatible than it is ansi.

So instead we just use our xterm-256color definition, which has a high
likelihood of being basically correct.
2024-12-14 12:10:34 +01:00
Fabian Boehm
cc8fa0f780 completions/rclone: Make version check more lenient
This has been observed to be "rclone 1.68.2" instead of "rclone
v1.68.2", missing the "v".
2024-12-14 11:20:29 +01:00
Fabian Boehm
378e9b236a Silence time_t deprecation
This is not something that affects us or we can do anything about.
2024-12-14 09:34:52 +01:00
Johannes Altmanninger
0a145cff3c Fix clippy lints 2024-12-14 09:31:20 +01:00
Johannes Altmanninger
f9febba2b0 Fix replacing completions with a -foo prefix
Fixes #10904
2024-12-14 09:31:20 +01:00
Fabian Boehm
84d8655677 fmt! 2024-12-13 21:57:07 +01:00
Fabian Boehm
abc1a45ea1 Shorten error for broken $TERM 2024-12-13 21:46:17 +01:00
Fabian Boehm
be16eeef69 Make --install install without confirmation, and not exit 2024-12-13 19:19:26 +01:00
Fabian Boehm
6d28845c2b Automatically attempt to install
This is fairly subtle.

When installable, and we either can't find the version file or it is
outdated, we ask the user to confirm installation (just like `--install`).

We do that only if we are really truly interactive (with a tty!) to
avoid `fish -c` running into problems.
This check could be tightened even more, because currently:

```fish
fish -ic 'echo foo'
```

asks, while

```fish
fish -ic 'echo foo' < /dev/null
```

does not.

`fish -c` will still error out if it can't find the config, but it
will just run if it is out of date.
2024-12-13 19:19:26 +01:00
Fabian Boehm
99fa8aaaa7 Really hide install() from clippy 2024-12-11 17:21:34 +01:00
Fabian Boehm
fa298c41e0 Hide install() from clippy
Not checkable because it would require sphinx
2024-12-11 17:18:34 +01:00
Fabian Boehm
327aa964e9 Disable default features for cargo test
Unfortunately it does not appear like #[cfg(test)] works for build.rs?

Investigating a better solution, but this is a good idea anyway (or `make
test` would generate man pages via build.rs!)
2024-12-11 17:05:38 +01:00
Fabian Boehm
6c852655dd Disable man page building in clippy
This would otherwise break any clippy run if you didn't have sphinx installed.
2024-12-11 16:56:14 +01:00
Fabian Boehm
0e0d56d805 format 2024-12-11 16:51:25 +01:00
Fabian Boehm
2d2f18c159 installable builds: Fail when building man pages fails
This is unfortunately necessary, because otherwise it would not rerun
the build script just because you installed sphinx.

Because we use the man pages for --help output, they're pretty
necessary.

To override it, you can set $FISH_BUILD_DOCS=0, like

```fish
FISH_BUILD_DOCS=0 cargo install --path .
```
2024-12-11 16:49:49 +01:00
David Adam
c58313fb2b README: minor formatting update 2024-12-11 08:04:52 +08:00
David Adam
662607fb2a README: minor formatting update 2024-12-11 08:04:15 +08:00
David Adam
6ae887383c README: improve instructions on building from source
Closes #10894.
2024-12-11 08:04:00 +08:00
David Adam
1b33e4b9a6 CHANGELOG: work on 4.0.0 2024-12-11 08:03:26 +08:00
Fabian Boehm
0083192fcb Read git SHA ourselves if it is unavailable
`git describe` *may* fail e.g. for `sudo make install`,
so we just read the SHA ourselves.
2024-12-09 16:57:47 +01:00
Peter Ammon
5c8b6adc2c Fix infinite prompt loop if status message is printed in prompt
fish will print messages for some jobs when they exit abnormally, such as
with SIGABRT. If a job exits abnormally inside the prompt, then (prior to
this commit) fish would print the message and re-trigger the prompt, which
could result in an infinite loop. This has existed for a very long time.

Fix it by reaping jobs after running the prompt, and NOT triggering a
redraw based on that reaping. We still print the message but the prompt is
not executed.

Add a test.

Fixes #9796
2024-12-08 18:12:59 -08:00
Peter Ammon
c97b1a992c Remove some unused code from the tests 2024-12-08 13:57:10 -08:00
Fabian Boehm
56a1403350 Revert "Enable gettext without the _nl_msg_cat_cntr gnuism"
This built on my test system, might be version differences.

(it's also not enough to make it *work*, but a necessary step)

This reverts commit 6fded249cd.
2024-12-08 22:04:59 +01:00
Fabian Boehm
6fded249cd Enable gettext without the _nl_msg_cat_cntr gnuism
This should allow e.g. musl to be translated.
2024-12-08 21:53:20 +01:00
Johannes Altmanninger
421ce13be6 Fix replacing completions spuriously quoting ~
Commit 29dc30711 (Insert some completions with quotes instead of
backslashes, 2024-04-13) wrongly copmletes

	$ cat ~/space

to

	$ cat '~/path with spaces'

Today completions can be either replacing or appending.  We never quote
(but backslash-escape) appending completions (unless they "append"
to an empty token).  We always quote replacing completions. The
assumption in this part of the code is that replacing completions
can be quoted without changing meaning.

This assumption is wrong for tildes.  For the backslash-escaping code
path, we take care of this edge case via a special DONT_ESCAPE_TILDES
flag. However that flag does not take effect when using quotes for
escaping. Fix that.

Unfortunately, e97a4fab7 (Escape : and = in file completions,
2024-04-19) introduced a (hopefully temporary) code clone in
escape_separators, which made added an extra step to debugging here.
2024-12-08 15:27:08 +01:00
Fabian Boehm
99b5e6e0e7 completions/cargo: Complete packages to uninstall 2024-12-08 09:13:20 +01:00
Fabian Boehm
004953a3b2 Revert "BuiltinData to use const constructor function"
Unfortunately, this does not work with rust 1.70.

This reverts commit 7e516925e9.
2024-12-08 07:52:57 +01:00
Peter Ammon
7e516925e9 BuiltinData to use const constructor function
This makes the list of builtins one line per builtin. No functional change.
2024-12-07 10:37:53 -08:00
Peter Ammon
0b68fbfd85 Clean up some stale comments 2024-12-07 10:37:53 -08:00
Fabian Boehm
fcf8ed0628 Clarify docs on self-installing builds 2024-12-07 13:13:18 +01:00
Fabian Boehm
210d687b2b CHANGELOG installable fish 2024-12-06 22:13:34 +01:00
Fabian Boehm
74e0436c3c Document installable builds 2024-12-06 22:12:26 +01:00
Fabian Boehm
3360dcbebc Make static builds on Github Actions
For x86_64 and cross-compiled for aarch64, manually triggered

It *seems* to work, but I had to explicitly disable gettext for it (which is AFAICT currently non-functional under musl anyway).

Also it will create one .zip containing two .tar.xzs. It is about 8MB, which should be fine, tbh.
2024-12-06 22:12:26 +01:00
Fabian Boehm
1599293796 Build man pages into installable fish
This calls sphinx-build from build.rs to include the man pages in the binary.

We don't abort if sphinx doesn't exist, but we do if it failed.
2024-12-06 22:12:26 +01:00
Fabian Boehm
2343a6b1f1 docs: Read version from the version file
Makes it possible to generate the man pages without fish_indent
available.

(not the html docs because they highlight via fish_indent!)
2024-12-06 22:12:26 +01:00
Fabian Boehm
7c73c5fec0 Make fish installable
When built with the default "installable" feature, the data files (share/) are
included in the fish binary itself.

Run `fish --install` or `fish --install=noconfirm` (for
non-interactive use) to install fish's data files into ~/.local/share/fish/install

To figure out if the data files are out of date, we write the current version
to a file on install, and read it on start.

CMake disables the default features so nothing changes for that, but this allows installing via `cargo install`,
and even making a static binary that you can then just upload and have extract itself.

We set $__fish_help_dir to empty for installable builds, because we do not have
a way to generate html docs (because we need fish_indent for highlighting).
The man pages are found via $__fish_data_dir/man
2024-12-06 22:12:26 +01:00
Fabian Boehm
7827a8e533 Make bin path an Option
It is possible we cannot acquire this
2024-12-06 22:12:26 +01:00
Fabian Boehm
aa30b4db4b Set crate version to 4.0.0-alpha1
The next version is gonna be 4.0.0
2024-12-06 22:12:26 +01:00
Fabian Boehm
378dc9123a git_version_gen: Just print the version
This was needed because we #included it in C++, but now it's easier to
have just the version in there
2024-12-06 22:12:26 +01:00
Fabian Boehm
5abd0e46f5 build.rs: Panic if version could not be found
We don't want "fish --version" to print "unknown" or any other fake version
2024-12-06 22:12:26 +01:00
Fabian Boehm
e24823dd6c Signals: Compute signal set once on startup
Really the only thing we're looking for here is if we're started with
HUP ignored or not.

Saves a syscall per external process.

Continuation of #10869
2024-12-04 20:18:16 +01:00
Ambrose Bonnaire-Sergeant
3012020af3 doc: expand &| reference to full example (#10885)
* doc: expand &| reference to full example

* feedback
2024-12-04 20:13:00 +01:00
Fabian Boehm
7b2cc9dca2 CI: Disable cargo-deny again
I am not a fan of CI tools that make the checks fail for reasons
unrelated to the patch at hand.
2024-12-04 18:42:20 +01:00
Himadri Bhattacharjee
d124c31958 refactor: remove unnecessary copied() for Utf32Str reference 2024-12-02 19:12:39 +01:00
Fabian Boehm
b2e6609367 builtin random: Be less strict about arguments
This now allows:

- Same argument (`random 5 5`)
- Swapped ends (`random 10 2`)
- One possibility (`random 0 5 4`)

This makes it easier to use with numbers generated elsewhere instead
of hard-coded, so you don't need to check as much before running it.

Fixes #10879
2024-12-02 19:06:14 +01:00
Fabian Boehm
1cad9898d6 Refactor some more .unwrap/asserts
No use in asserting and then unwrapping, just .expect()
2024-11-30 23:11:04 +01:00
Fabian Boehm
4859606e0c posix_spawn: Unconditionally default all signals (except HUP)
We don't really care if the process has a custom handler installed, we
can just set it to default.

The one we check is SIGHUP, which may be given to us via `nohup`.

This saves ~30 syscalls *per process* we spawn, so:

```fish
for f in (seq 1000)
    command true
end
```

has ~30000 fewer rt_sigaction calls. These take up about ~30% of the
total time spent in syscalls according to strace.

We could also compute this set once at startup and then reuse it.
2024-11-30 23:00:44 +01:00
Peter Ammon
5d10bc6a02 Fix/suppress some clippies
needless_lifetimes is annoying; supress that. Fix some spacing that clippy was
complaining about.
2024-11-30 12:21:30 -08:00
Fabian Boehm
eee44b7469 ulimit: Fix multiplication overflow 2024-11-30 15:40:48 +01:00
Fabian Boehm
8736d9b1e7 CI: Add cargo-deny 2024-11-29 18:17:11 +01:00
Fabian Boehm
f5e71063d7 Add cargo-deny configuration 2024-11-29 18:17:00 +01:00
Fabian Boehm
2d1ad1c3cc Mostly Revert "cmake: Remove code to resolve rustup toolchains"
Apparently needed on our FreeBSD CI setup.

This reverts commit 281df5daad.
2024-11-28 20:00:34 +01:00
Fabian Boehm
8b464d96af Remove reference to static mut
This is what UnsafeCell is for: Providing interior mutability.

The docs at https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
give an example just like this - `&mut *ptr.get()`

Without, rustc may complain - https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html
2024-11-28 19:36:50 +01:00
Fabian Boehm
281df5daad cmake: Remove code to resolve rustup toolchains
We turned it off, but for some reason (cmake version?) that stopped working on my system.

So instead we just remove all the code that does it.

To be honest I do not know why this exists anyway.
2024-11-27 22:29:13 +01:00
Johannes Altmanninger
3ed031c149 Update Kakoune completions 2024-11-27 08:44:36 +01:00
Johannes Altmanninger
644171fac6 fix: check whether a function is tombstoned during highlight
exists_no_autoload() wrongly thinks that tombstoned functions can be
autoloaded; fix that.

While at-it replace the use of get_props() with something simpler.

Co-authored-by: Himadri Bhattacharjee

Closes #10873
2024-11-27 08:44:36 +01:00
Fabian Boehm
c625a324ba docs/string-trim: Double down on the set of chars vs string thing 2024-11-25 17:53:14 +01:00
Fabian Boehm
4101bb30bf Remove unused variables
Never set since the introduction in 61686aff34
2024-11-25 16:29:00 +01:00
Johannes Altmanninger
b89619330b Disable terminal protocols before cancellable operations
The [disambiguate flag](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) means that:

> In particular, ctrl+c will no longer generate the SIGINT signal,
> but instead be delivered as a CSI u escape code.

so cancellation only works while we turn off disambiguation.

Today we turn it off while running external commands that want to
claim the TTY.  Also we do it (only as a workaround for this issue)
while expanding wildcards or while running builtin wait.

However there are other cases where we don't have a workaround,
like in trivial infinite loops or when opening a fifo.

Before we run "while true; end", we put the terminal back in ICANON
mode. This means it's line-buffered, so we won't be able to detect
if the user pressed ctrl-c.

Commit 8164855b7 (Disable terminal protocols throughout evaluation,
2024-04-02) had the right solution: simply disable terminal protocols
whenever we do computations that might take a long time.
eval_node() covers most of that; there are a few others.

As pointed out in #10494, the logic was fairly unsophisticated then:
it toggled terminal protocols many times.  The fix in 29f2da8d1
(Toggle terminal protocols lazily, 2024-05-16) went to the extreme
other end of only toggling protocols when absolutely necessary.

Back out part of that commit by toggling in eval_node() again,
fixing cancellation.  Fortunately, we can keep most of the benefits
of the lazy approach from 29f2da8d1: we toggle only 2 times instead
of 8 times for an empty prompt.

There are only two places left where we call signal_check_cancel()
without necessarily disabling the disambiguate flag
1. open_cloexec() we assume that the files we open outside eval_node()
   are never blocking fifos.
2. fire_delayed(). Judging by commit history, this check is not
   relevant for interactive sessions; we'll soon end up calling
   eval_node() anyway.

In future, we can leave bracketed paste, modifyOtherKeys and
application keypad mode turned on again, until we actually run an
external command.  We really only want to turn off the disambiguate
flag.

Since this is approach is overly complex, I plan to go with either
of these two alternatives in future:
- extend the kitty keyboard protocol to optionally support VINTR,
  VSTOP and friends.  Then we can drop most of these changes.
- poll stdin for ctrl-c. This promises a great simplification,
  because it implies that terminal ownership (term_steal/term_donate)
  will be perfectly synced with us enabling kitty keyboard protocol.
  This is because polling requires us to turn off ICANON.
  I started working on this change; I'm convinced it must work,
  but it's not finished yet. Note that this will also want to
  add stdin polling to builtin wait.

Closes #10864
2024-11-24 16:11:57 +01:00
Fabian Boehm
f0a5f8738b Silence clippy lints 2024-11-24 11:17:34 +01:00
Mahmoud Al-Qudsi
1347df898e Add ascii fast path for fish_wcswidth(&wstrw)
chars.all(|c| c.is_ascii()) is autovectorizable but this outperforms even when
it's not vectorized.
2024-11-22 21:35:39 -06:00
Mahmoud Al-Qudsi
2fd51355c3 Speed up wcscasecmp by approximately 30-40%
Moving the "make empty ToLowercase iterator" logic to within the
`unwrap_or_else()` instead of always generating it brings most of the speedup;
unrolling the recursive call brings in the rest.
2024-11-22 21:34:25 -06:00
Mahmoud Al-Qudsi
8c8da78cf8 Speed up get_case_fold() 5x
Using `c.is_uppercase()` instead of getting the iterator and checking if the
first (and only) lowercase letter of the sequence is the same as the original
input is 5-8x faster (measured via criterion against `/usr/share/dict/words`).

(Additional benefit of forcibly inlining the now iterator-based comparison not
taken into account; this necessitated changing from a closure to a local
function as the inline attribute on closures is not yet supported with the
stable compiler toolchain.)
2024-11-22 16:30:10 -06:00
Mahmoud Al-Qudsi
b949497bc1 Use idiomatic names for CaseSensitivity and ContainType 2024-11-22 16:28:33 -06:00
Mahmoud Al-Qudsi
b570c7f6a6 Reduce allocations when deduping completions in place
This is still suboptimal because we are allocating a vector of indices to be
removed (but allocation-free in the normal case of no duplicates) but
significantly better than the previous version of the code that duplicated the
strings (which are larger and spread out all over the heap).

The ideal code (similar to what we had in the C++ version, iirc) would look like
this, but it's not allowed because the borrow checker hates you:

```
fn unique_in_place_illegal(comps: &mut Vec<Completion>) {
    let mut seen = HashSet::with_capacity(comps.len());
    let mut idx = 0;
    while idx < comps.len() {
        if !seen.insert(&comps[idx].completion) {
            comps.remove(idx);
            continue;
        }
        idx += 1;
    }
}
```
2024-11-22 14:11:01 -06:00
Fabian Boehm
36c5ee045c fixup! filter control sequences 2024-11-21 21:20:35 +01:00
Fabian Boehm
2d07aa2686 tests: Move control sequences filtering to fish directly
This was an sh-script that just invoked fish again.

I can see how we could implement it in another language to avoid the
fish under test corrupting the results, but it literally invoked the
fish under test anyway.
2024-11-21 21:08:56 +01:00
Fabian Boehm
8dcde27e0b functions/history: Put back some checks for clear{,-session}
Mostly we pass on the options - otherwise they would be ignored.

For `clear`, we do need the full checks, because that will
prompt *before* running the builtin.

But this makes it easier to eventually move that logic into the builtin
2024-11-21 18:55:03 +01:00
Fabian Boehm
212dd6ec37 builtins/history: Use the enum nicer
Name it so it's not SHOUTY CASE, make a `panic!` unrepresentable

No functional change
2024-11-21 18:33:32 +01:00
Fabian Boehm
fcab68c591 docs/faq: Fix some broken keys 2024-11-21 18:28:43 +01:00
Fabian Boehm
6fe192606a functions/history: Set variables in function-scope explicitly
```fish
set -g LESS foo

history search bar
```

changes the global $LESS and exports it.
2024-11-21 18:27:10 +01:00
Fabian Boehm
11f11e27a1 functions/history: Remove unnecessary code
These things are all handled in the builtin
2024-11-21 18:26:47 +01:00
Kid
31b15405e9 Add completion for path basename -E/--no-extension (#10863) 2024-11-20 15:06:53 -06:00
Mahmoud Al-Qudsi
edd82be58d Fix crash on invalid CSI parameters
If a semicolon-delimited list of CSI parameters contained an (invalid) long
sequence of ascii numeric characters, the original code would keep multiplying
by ten and adding the most recent ones field until the `params[count][subcount]`
u32 value overflowed.

This was found via automated fuzz testing of the `try_readch()` routine against
a corpus of some proper/valid CSI escapes.
2024-11-20 15:01:34 -06:00
Mahmoud Al-Qudsi
b92830cb17 Change readch() into try_readch()
This lets us call into the entirety of the prior `readch()` with an exhaustible
input stream without panicking on the `unreachable!()` call. The previous
functionality is kept under the old name by calling `try_readch()` with the
`blocking` parameter set to `true` (100% same behavior as before).

While the `try_readch(false)` entrypoint isn't used directly by the current fish
codebase, it is required in order to automate input reader tests without the
overhead and complexity of running the test harness in a tty emulator emulator
like pexpect or tmux, which moreover necessitates out-of-process testing – which
is incompatible with most perf-guided testing harnesses.

I hope to be able to upstream harness integrations using this entry point in the
near future.
2024-11-20 14:53:07 -06:00
Fabian Boehm
b3108c0cee CHANGELOG 2024-11-19 21:12:44 +01:00
Fabian Boehm
7a667b4f6d Add basic completions for firejail
These are pretty basic, but get us roughly up to the level of the
official completions (that are also incomplete and offer disabled
options).

Fixes #10858
2024-11-18 16:16:07 +01:00
Peter Ammon
c4bc6b6f09 Clean up print_help
`print_help` is a hacky-wacky function used to support the `--help` command
of `fish_key_reader` and others. The Rust version panics on an error; fix
that and make it print more useful help messages.
2024-11-17 17:03:34 -08:00
Unbelievable Mystery
262e2d5fe6 Update completions for: wine (#10789)
* feat(function): move cmd completion function to a separate file

* feat(completion): support wine cmd subcommand

* feat(completion): support wine control subcommand

* feat(completion): support wine eject subcommand

* feat(completion): support wine explorer subcommand

* feat(completion): support wine explorer subcommand for desktops

* feat(completion): support wine start subcommand

* feat(completion): support wine winemenubuilder subcommand

* feat(completion): support wine winepath subcommand

* fix(function): rename function for cmd argument completion

* feat(function): implement function to complete registry keys

* feat(completion): support wine regedit subcommand

* feat(function): add top-level key descriptions

* fix(completion): remove redundant comment

* feat(completion): support wine msiexec subcommand

* refactor(completion): group code into functions

* feat(completion): enhance subcommand descriptions
2024-11-17 14:58:21 -08:00
Unbelievable Mystery
93aa5a9376 Add completions for: guile, guild (#10792)
* feat(completion): support guile command

* feat(completion): support guild command

* feat(completion): support guild subcommand

* feat(completion): squeeze code
2024-11-17 14:08:19 -08:00
Peter Ammon
642eff9e1f Fix some clippies and remove some dead code 2024-11-17 12:37:45 -08:00
Next Alone
723e5a8417 completions(ollama): ollama need no files as i know (#10851)
Closes #10851.

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
2024-11-17 10:05:42 -06:00
David Adam
0e6171b63e CHANGELOG: work on 4.0.0 2024-11-17 23:12:46 +08:00
David Adam
98fcb1c6ba completions/diskutil: list all volumes, not just the writeable ones
Discussion in #10574.
2024-11-17 22:06:54 +08:00
Xiretza
421e27b1bf Add completions for iftop 2024-11-17 21:59:08 +08:00
Johannes Altmanninger
13f0c9b0c6 Remove accidentally added file 2024-11-17 05:20:35 +01:00
Johannes Altmanninger
2d8fcbcdcd Fix regression causing mbrtowc(argv) to be called before setlocale()
Fixes #10847
2024-11-16 20:46:06 +01:00
Mahmoud Al-Qudsi
68b9f96f84 Add completions for simonw/llm 2024-11-16 13:27:29 -06:00
Johannes Altmanninger
913860bd1c Fix regression causing alt-right to stop at autosuggestion
Fixes #10839
2024-11-16 13:05:44 +01:00
Johannes Altmanninger
ca21872d14 Clean up the accept-autosuggestion code path a little bit
It's still a bit too complex unfortunately.
2024-11-16 13:05:44 +01:00
vp2177
2b19e1a09b completion(apt-mark): Add missing minimize-manual command & --color options (#10825)
* Update apt-mark.fish
2024-11-14 16:01:54 -06:00
Mahmoud Al-Qudsi
cdeb3977c3 Re-enable tmux-prompt test under FreeBSD
It passes now that we have uvar notifications working under BSD.
2024-11-14 13:44:49 -06:00
Mahmoud Al-Qudsi
fea1e3aee5 Use iterators to clean up disown logic 2024-11-14 13:25:25 -06:00
Mahmoud Al-Qudsi
c1acbf2845 Deduplicate jobs passed to disown builtin
I'm guessing this was missed in the port because there were comments referencing
using a hash set to perform the deduplication but there was no hashset. (The
TODO was added later.)
2024-11-14 13:24:55 -06:00
Fabian Boehm
366c1b7210 Refuse to search history pager if no new results exist
This prevents searching further and collapsing results into one.

Now I need to figure out how to get it to flash.
2024-11-14 20:02:49 +01:00
Mahmoud Al-Qudsi
4061ef7137 Remove unnecessary Pid::get() calls 2024-11-14 13:02:03 -06:00
Mahmoud Al-Qudsi
fc47d9fa1d Use strongly typed Pid for job control 2024-11-14 13:02:03 -06:00
Mahmoud Al-Qudsi
2cf4b12d41 Use strongly typed Option<Pid> for event handler
This caught an incorrect description for process/job exit handlers for ANY_PID
(now removed) which has been replaced with a message stating the handler is for
any process exit event.
2024-11-14 13:02:03 -06:00
Mahmoud Al-Qudsi
95ac51101e Use Option<Pid> instead of Option<pid_t>
Statically assert that the interior value is both positive and non-zero.
2024-11-14 13:02:03 -06:00
Mahmoud Al-Qudsi
3307672998 Use type safety for pid values
The previous approach of "treat this field as an `Option<NonZeroU32>` and
remember to check `p.has_pid()` before accessing it" was a mix of C++ and rust
conventions and led to some bugs or incorrect behaviors.

* `jobs -p` would previously print both the (correct) external pid and the
  (incorrect) internal value of `0` if a backgrounded command contained a
  fish function (e.g. `function foo; end; cat | foo &; jobs`)
* Updating/calculating job cpu time and usage was incorrectly including all of
  fish's cpu usage/time for each function/builtin member of the job pipeline.

Closes #10832
2024-11-14 13:02:03 -06:00
Fabian Boehm
080e40aac0 Fix crash in history pager
ctrl-r ctrl-s ctrl-s

Attemps to go before the beginning and asserts out. Instead refuse to
do that.

(there's some weirdness where it can reduce the pager to the first
entry if you keep pressing, which I haven't found yet, but that's better than *crashing*)
2024-11-14 16:36:40 +01:00
Fabian Boehm
7846a232a9 cmake: Add some new version gunk
CMake Warning (dev) at cmake/Tests.cmake:56 (add_custom_command):
  Exactly one of PRE_BUILD, PRE_LINK, or POST_BUILD must be given.  Assuming
  POST_BUILD to preserve backward compatibility.

  Policy CMP0175 is not set: add_custom_command() rejects invalid arguments.
  Run "cmake --help-policy CMP0175" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

So we just keep it the same.
2024-11-13 17:48:15 +01:00
Fabian Boehm
6d76b938c7 bind: Remove "c-" and "a-" shortcut notation
These are another way to spell the same thing that doesn't match what
`bind` would print.

They're also not documented and tested thoroughly.

Since they are just small shortcuts and unreleased we can just remove
them.

Fixes #10845
2024-11-13 17:48:15 +01:00
Mahmoud Al-Qudsi
14a5c0ca44 Disable tmux-multiline-prompt under macOS CI 2024-11-12 17:13:18 -06:00
Mahmoud Al-Qudsi
bb57f2391f Fix a bad comment and clarify delta behavior
s/fish/delta/ and provide a better explanation.
2024-11-12 09:59:10 -06:00
Mahmoud Al-Qudsi
d33cbfd1a3 Prevent delta completions from complain with old version 2024-11-11 16:51:27 -06:00
Mahmoud Al-Qudsi
4e3dc51bc4 Prevent test suite from hanging on panic 2024-11-11 16:45:13 -06:00
Fabian Boehm
960415db3f function: Error out for read-only variables
This will refuse to define the function instead of defining it with an
unusable argument.

Fixes #10842
2024-11-11 17:56:57 +01:00
Fabian Boehm
0ef811c86e dir_iter: Remove duplicate NUL-removal
This goes over the d_name twice.

Filenames already cannot contain NUL (the C-api cannot express it!), so we don't need to scan them.
2024-11-11 17:56:57 +01:00
Mahmoud Al-Qudsi
f0a3a5708f git: complete git diff src/ to show modified files before unmodified ones
This has the side effect of changing the order of completions for a bare `git
diff` to show modified files before revisions; previously they came at the very
end after all revisions, stashes, local branches, remote branches, and tags.
That seems sensible to me?

As I understand the completions file, it seems to me that the intention was for
`git diff src/` to only show modified files to begin with ­ it
previously/currently shows them all, so we might want to add a `-n 'not ...'`
condition for `git diff` to prevent that.
2024-11-10 12:55:32 -06:00
Peter Ammon
dff454b1c7 Rework git detection for macOS
fish by default shows a git-aware prompt. Recall that on macOS, there are
two hazards we must avoid:

1. The command `/usr/bin/git` is installed by default. This command is not
actually git; instead it's a stub which pops open a dialog proposing to
install Xcode command line tools. Not a good experience.
2. Even after installing these tools, the first run of any `git` or other
command may be quite slow, because it's now a stub which invokes `xcrun`
which needs to populate a cache on a fresh boot. Another bad experience.

We previously attempted to fix this by having `xcrun` print out its cache
path and check if there's a file there. This worked because `xcrun` only
lazily created that file. However, this no longer works: `xcrun` now
eagerly creates the file, and only lazily populates it. Thus we think git
is ready, when it is not.

(This can be reproduced by running `xcrun --kill-cache` and then running
the default fish shell prompt - it will be slow).

Change the fix in the following way: using sh, run `/usr/bin/git --version;
touch /tmp/__fish_git_ready` in the background. Then detect the presence of
/tmp/__fish_git_ready as a mark that git is ready.

Fixes #10535
2024-11-09 12:46:06 -08:00
Johannes Altmanninger
2543b8198d Fix crash when sprintf width argument overflows u64
Given "printf %18446744073709551616s", we parse the number only in
the printf crate, which tells us that we overflowed somwhere (but
not where exactly).
2024-11-09 08:16:08 +01:00
Mahmoud Al-Qudsi
9fddc3e887 Emit only sane pgid value for jobs output (#10833)
We were previously printing the internal `INVALID_PID` value (since removed),
which was a meaningless `-2` constant, when there was no pgid associated with a
job.

This PR changes that to `-` to indicate no pgid available, which I prefer over
something like `0` or `-1`, but will cause problems for code that is hardcoded
to convert this field to an integral value.
2024-11-08 10:33:30 -06:00
David Adam
2279b47178 CHANGELOG: work on 4.0.0 2024-11-07 23:52:29 +08:00
Dezhi Wu
5405833822 feat(completion): Add kops.fish completion
[kOps] is a set of tools for installing, operating, and deleting Kubernetes
clusters.

[kOps]: https://github.com/kubernetes/kops/
2024-11-07 23:13:09 +08:00
Johannes Altmanninger
5e3fdf3320 Fix regression causing crash when we should clamp negative wcwidth
Fixes c41dbe455 (Also use control pictures for pager prefix,
2024-10-19).

Fixes #10836
2024-11-07 07:36:36 +01:00
Fabian Boehm
373c5b1e14 fixup! Cursor visible sequence
Whoops, picked the wrong part of cnorm
2024-11-06 19:03:50 +01:00
Fabian Boehm
56718c31b1 reader: Comment the OSC 133 marker sequences 2024-11-06 19:01:17 +01:00
Fabian Boehm
c1fbe237c9 Make cursor visible after commands
Just like we already fix terminal modes if a command left them broken,
having an invisible cursor makes the terminal hard to use and so we
fix it.

We can't really use cnorm/cursor_normal because that often includes
other gunk like making the cursor blink, but it turns out every
terminfo entry agrees on the sequence to make the cursor visible, so
we hardcode it.

Fixes #10834
2024-11-06 19:01:17 +01:00
Fabian Boehm
bfc68345c9 Disable CSI u in Jetbrains terminals
Note: This may not be sent in WSL.

Fixes #10829
2024-11-06 19:01:04 +01:00
Fabian Boehm
4b24fe7daf docs/export: Add a bit on PATH=$PATH:... 2024-11-06 18:50:41 +01:00
Fabian Boehm
0979b9a98b help: Print external URL if no browser was found
This is nicer when you use fish over ssh, and that system does not
have a browser. But the system where your terminal is has one, and so
now you can just click the link.
2024-11-06 18:48:57 +01:00
David Adam
018659bf66 CHANGELOG: work on 4.0.0 2024-11-07 01:09:11 +08:00
David Adam
0d9ad0f23b docs: add short documentation for export
Work on #10541.
2024-11-06 23:47:31 +08:00
David Adam
767ae87191 CONTRIBUTING.rst: update for Rust 2024-11-06 23:27:04 +08:00
David Adam
7f29f09d25 README: updates for Rust / 4.0 2024-11-06 23:22:26 +08:00
Johannes Altmanninger
7debdb75af Fix regression causing fish_cursor_external to be ignored
Regressed in 0e97b876e (Simplify fish_vi_cursor, 2024-10-25).
2024-11-06 07:24:00 +01:00
Mahmoud Al-Qudsi
24a077f804 Silence GPG warnings about directory permissions 2024-11-04 16:35:24 -06:00
Mahmoud Al-Qudsi
d7f4ad7ab8 Silence gh warnings re unable to read plugins dir
Unlike the errors, these *do* get printed to stderr.
2024-11-04 16:33:30 -06:00
Mahmoud Al-Qudsi
33a170d614 Replace INVALID_PID constant with Option<NonZeroU32>
If we end up using this in more places, we can create a `Pid` newtype.
Note that while the constant is no longer used in code, its previous value of -2
is still printed by `jobs` when no pgid is associated with a job. I will open a
PR to change this to something else, likely either `0` or `-`.
2024-11-04 16:19:22 -06:00
Mahmoud Al-Qudsi
d1a2923d72 Fix doc comments for CancelBehavior 2024-11-04 15:49:33 -06:00
Mahmoud Al-Qudsi
8aed929f5e Fix broken changelog formatting 2024-11-03 13:53:42 -06:00
David Adam
e5040cbbaf CHANGELOG: work on 4.0.0 2024-11-03 22:43:25 +08:00
Peter Ammon
23941ea9ca Don't try locking the history file if mmap returns ENODEV
If we try to memory map the history file, and we get back ENODEV meaning that
the underlying device does not support memory mapping, then treat that as a hint
that the filesystem is remote and disable history locking.
2024-11-02 12:09:51 -07:00
Peter Ammon
344b072e82 Further expand the list of filesystems considered remote
Incorporate additional file systems from
https://github.com/coreutils/gnulib/blob/master/lib/mountlist.c#L237-L253
by hunting down their magic numbers.

In the future we could consider switching to f_fstypename.
2024-11-02 11:59:34 -07:00
Johannes Altmanninger
cfcf415db7 Render overflown commandline in entirety just before executing
As of 04c913427 (Limit command line rendering to $LINES lines,
2024-10-25), we only render a part of the command line.  This removes
valuable information from scrollback.
The reasons for the limit were
1. to enable redrawing the commandline (can't do that if part of it
   is off-screen).
2. if the cursor is at the beginning of the command-line, we can't
   really render the off-screen suffix (unless we can tell the terminal
   to scroll back after doing that).

Fortunately these don't matter for the very last rendering of a
command line.  Let's render the entire command just before executing,
fixing the scrollback for executed commands.

In future, we should fix it also for pre-execution renderings. This
needs a terminal command to clear part of the scrollback.  Can't find
anything on https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
There is "Erase Saved Lines" but that deletes the entire scrollback.

See the discussion in #10827
2024-11-02 10:25:58 +01:00
Johannes Altmanninger
04d97e936a Remove redundant cursor position invariant check
Since f89909ae3 (Also handle overflown screens if editing pager search
field, 2024-10-27), cursor_arr is never None after the loop.
Assert that by unwrapping.

qa.sh
2024-11-02 10:16:45 +01:00
Johannes Altmanninger
f42beec42e Fix typo in comment 2024-11-02 10:13:37 +01:00
Johannes Altmanninger
85404bf7a9 edit_command_buffer: speed up setting cursor position by line/column
alt-e restores the cursor position received from the editor, moving by
one character at a time.  This can be super slow on large commandlines,
even on release builds.  Let's fix that by setting the coordinates
directly.
2024-11-01 20:09:55 +01:00
Johannes Altmanninger
6525e3d11a edit_command_buffer: silence error when editor reports out-of-bounds line number
This happens when using alt-e to edit the command buffer,
adding some lines, leaving the cursor at the end
and quitting the editor without saving.

Let's avoid the noisy error that has sort of bad rendering (would
need __fish_echo).
2024-11-01 20:09:55 +01:00
Johannes Altmanninger
3710e98d65 Suppress spurious error when config dir creation fails due to TOCTOU
Our recursive create_dir() first calls stat() to check if the directory
already exists and then mkdir() trying to create it. If another (fish)
process creates the same directory after our stat() but before our
mkdir(), then our mkdir() fails with EEXIST. This error is spurious
if there is already a directory at this path (and permissions are
correct).

Let's switch to the stdlib version, which promises to solve this issue.
They currently do it by running mkdir() first and ask stat() later.

This implies that they will only return success even if we don't have
any of rwx permissions on the directory, but that was already a problem
before this change. We silently don't write history in that case..

Fixes #10813
2024-10-31 08:01:31 +01:00
Josef Litoš
9e01981bb9 completions/adb: local files first when pushing 2024-10-31 01:05:44 +01:00
Johannes Altmanninger
cd3b6f9124 commandline --showing-suggestion to ignore single-space autosuggestion
All-whitespace autocompletions are invisible, no matter the cursor
shape.  We do offer such autosuggestions after typing a command name
such as "fish". Since the autosuggestion is invisible it's probably
not useful. It also does no harm except when using a binding like

	bind ctrl-g '
	    if commandline --showing-suggestion
	        commandline -f accept-autosuggestion
	    else
	        up-or-search
	    end'

where typing "fish<ctrl-g>" surprisingly does not perform a history
search.  Fix this by detecting this specific case. In future we
could probably stop showing autosuggestions whenever they only
contain whitespace.
2024-10-30 06:25:27 +01:00
Johannes Altmanninger
ec939fb22f Work around BSD man calling pager when stdout is not a TTY
With BSD man, "PAGER=vim man man | cat" hangs because
[man](https://cgit.freebsd.org/src/tree/usr.bin/man/man.sh) wrongly
calls the pager even though stdout is not a terminal.

This hang manifests in places where we call apropos in a subshell,
such as in "complete -Ccar".

Let's work around this I guess. This should really be fixed upstream
because it's a problem in every app that wants to display man pages
but doesn't emulate a complete terminal.

Weirdly, the Apple derivative of man.sh uses WHATISPAGER instead
of MANPAGER.

Closes #10820
2024-10-30 04:58:50 +01:00
Johannes Altmanninger
31d7f197b1 Switch default build type back to RelWithDebInfo for now
A release build is recommended to most users (to avoid occasional slowness)
whereas developers may prefer debug builds for shorter build times and more
accurate debug information.

There are more users of "make install" than developers, so I think the
default should be optimized for users, i.e. an optimized build. I think
that's in line with what most of our peer projects do.

Even if developers don't know about the -DCMAKE_BUILD_TYPE=Debug
trick, they will likely be able to iterate quickly by using "cargo
{build,check,clippy,test}" and rust-analyzer, all of which use a debug
configuration by default, irrespective of cmake. Granted, users will need
to use cmake to run system tests. If a task needs a lot of iterations,
one can always convert the system test to a script that can be run with
target/build/fish. For building & running all system tests, the release
build takes 30% longer, so not that much.

Here are my build/test times and binary sizes; with debug:

    $ time ninja -C build-Debug/
    ________________________________________________________
    Executed in   25.30 secs    fish           external
       usr time   68.33 secs  676.00 micros   68.32 secs
       sys time   11.34 secs   41.00 micros   11.34 secs
    $ du -h build-Debug/fish
    43M	    build-Debug/fish
    $ time ninja -C build-Debug/ test
    ________________________________________________________
    Executed in  193.96 secs    fish           external
       usr time  182.84 secs    1.53 millis  182.83 secs
       sys time   30.97 secs    0.00 millis   30.97 secs

with release

    $ time ninja -C build-RelWithDebInfo/
    ________________________________________________________
    Executed in  106.80 secs    fish           external
       usr time  164.98 secs  631.00 micros  164.98 secs
       sys time   11.62 secs   41.00 micros   11.62 secs
    $ du -h build-RelWithDebInfo/fish
    4.6M	build-RelWithDebInfo/fish
    $ time ninja -C build-RelWithDebInfo/ test
    ________________________________________________________
    Executed in  249.87 secs    fish           external
       usr time  260.25 secs    1.43 millis  260.25 secs
       sys time   29.86 secs    0.00 millis   29.86 secs

Tangentially related, the numbers with "lto = true" deleted.  This seems
like a nice compromise for a default but I don't know much about the other
benefits of lto.

    $ time ninja -C build-RelWithDebInfo-thin-lto/
    ________________________________________________________
    Executed in   35.50 secs    fish           external
       usr time  196.93 secs    0.00 micros  196.93 secs
       sys time   13.00 secs  969.00 micros   13.00 secs
    $ du -h build-RelWithDebInfo-thin-lto/fish
    5.5M	build-RelWithDebInfo-thin-lto/fish
    $ time ninja -C build-RelWithDebInfo-thin-lto/ test
    ________________________________________________________
    Executed in  178.62 secs    fish           external
       usr time  287.48 secs  976.00 micros  287.48 secs
       sys time   28.75 secs  115.00 micros   28.75 secs

Alternative solution: have no default at all, and error out until the user
chooses a build type.
2024-10-28 14:26:57 +01:00
Johannes Altmanninger
dccc3349f0 Update build type recommendation to match our previous default
Currently the only difference between RelWithDebInfo and Release is that
the former adds -g (aka debuginfo=2) though it doesn't seem to make a lot
of difference in my testing.

Since build_tools/make_pkg.sh and debian/rules use RelWithDebInfo, let's be
consistent with those.
2024-10-28 14:26:57 +01:00
Peter Ammon
fa72d1faa1 Changelog fix for filesystem remote detection
Add note about #10818
2024-10-27 21:30:29 -07:00
Peter Ammon
e322d3addc Expand the set of filesystems considered remote on Linux
Some background: fish has some files which should be updated atomically:
specifically the history file and the universal variables file. If two fish
processes modified these in-place at the same time, then that could result
in interleaved writes and corrupted files.

To prevent this, fish uses the write-to-adjacent-file-then-rename to
atomically swap in a new file (history is slightly more complicated than
this, for performance, but this remains true). This avoids corruption.

However if two fish processes attempt this at the same time, then one
process will win the race and the data from the other process will be lost.
To prevent this, fish attempts to take an (advisory) lock on the target
file before beginning this process. This prevents data loss because only
one fish instance can replace the target file at once. (fish checks to
ensure it's locked the right file).

However some filesystems, particularly remote file systems, may have locks
which hang for a long time, preventing the user from using their shell.
This is far more serious than data loss, which is not catastrophic: losing
a history item or variable is not a major deal. So fish just attempts to
skip locks on remote filesystems.

Unfortunately Linux does not have a good API for checking if a filesystem
is remote: the best you can do is check the file system's magic number
against a hard-coded list. Today, the list is NFS_SUPER_MAGIC,
SMB_SUPER_MAGIC, SMB2_MAGIC_NUMBER, and CIFS_MAGIC_NUMBER.

Expand it to AFS_SUPER_MAGIC, CODA_SUPER_MAGIC, NCP_SUPER_MAGIC,
NFS_SUPER_MAGIC, OCFS2_SUPER_MAGIC, SMB_SUPER_MAGIC, SMB2_MAGIC_NUMBER,
CIFS_MAGIC_NUMBER, V9FS_MAGIC which is believed to be exhaustive.

ALSO include FUSE_SUPER_MAGIC: if the user's home directory is some FUSE
filesystem, that's kind of sus and the fewer tricks we try to pull, the
better.
2024-10-27 21:10:45 -07:00
Peter Ammon
3e3aa08c28 Fix some dumb clippies 2024-10-27 18:20:49 -07:00
Nihaal Sangha
5ee51492be Add tailscale completion 2024-10-27 16:49:00 -07:00
Giorgio Gallo
677e53f06a fix documentation for path normalize 2024-10-27 08:32:05 +00:00
Johannes Altmanninger
f89909ae31 Also handle overflown screens if editing pager search field
As mentioned in 04c913427 (Limit command line rendering to $LINES
lines, 2024-10-25) our rendering breaks when the command line overflows
the screen and we have a pager search field.

Let's also apply the overflow logic in this case.

Note that the search field still works, it's just not visible.

In future we should maybe show a small search field (~4 lines) in
this case (removing 4 screen lines worth of command line).  But again,
this is not really important.
2024-10-27 08:17:56 +01:00
Johannes Altmanninger
adfa87d141 Fix glitch rendering commandline that overflows screen size
If the first physical line in the command line overflows the screen,
the cursor will be wrong and we'll fail to clear the prompt without
a manual ctrl-l.  Let's fix that, and also don't print the OSC 133
marker in this case.

Currently, when we are scrolled, the first line on the screen still
gets an indentation that would normally be filled by the prompt.
This happens even for soft-wrapped lines, so they might be
torn apart in weird ways here.

In future, we might paint the prompt here.  If not, the current
behavior for soft-wrapped lines is debatable but its' not super
important to fix. The main goal is to first get rid of glitches in
these edge cases.
2024-10-27 07:16:30 +01:00
Johannes Altmanninger
c155acd004 Fix tmux-multiline-prompt test with EDITOR=vim
This test does "isolated-tmux send-keys Escape" to exit copy mode. When
EDITOR contains "vi", tmux will use Vi keybindings where Escape does
something else ("q" would exit copy mode).

Tests want to have predictable behavior so let's declare the default
emacs key bindings unconditionally.

Fixes #10812
2024-10-27 05:03:30 +01:00
Peter Ammon
2e2765eec0 Remove .cargo/config.toml
This added link args to target macOS 10.9, but these arguments are not necessary
when building via the make_pkg.sh script, and this file is causing other
problems.
2024-10-26 18:05:22 -07:00
Fabian Boehm
ca27e028df Silence unused imports for backports
Would be cool if there was a way to do this on future:: in general.
2024-10-26 22:28:37 +02:00
Fabian Boehm
0e62178320 Only apply kitty protocol MC hack in MC
This deactivated it everywhere
2024-10-26 22:24:22 +02:00
Johannes Altmanninger
bd9fee417b Use kitty keyboard protocol again for recent Midnight Commander
See https://midnight-commander.org/ticket/4597
2024-10-26 19:55:48 +02:00
Johannes Altmanninger
9ef76860e6 Default Vi cursor shapes for insert/replace mode
Let's provide a sensible default here. Use a line for "insert" and an
underline for "replace_one" mode.  Neovim does the same, it feels pretty
slick.

As mentioned in #10806
2024-10-26 08:25:12 +02:00
Johannes Altmanninger
5760a1afcf Don't reset the fish_cursor_selection_mode in fish_default_key_bindings
As of the parent commit, __fish_vi_key_bindings_remove_handlers
should be working properly now, so this is no longer necessary That
function also cleans up other stuff like fish_cursor_end_mode, that
fish_default_key_bindings doesn't know anything about.

Also this fixes a spurious exit status of 4 in some scenarios.
2024-10-26 08:25:12 +02:00
Johannes Altmanninger
b05e071238 Properly remove Vi mode when switching to different bindings
fish_key_bindings may be set directly
or via fish_{default,vi}_key_bindings.

The latter use "set --no-event" to simplify their control
flow.  This (24836f965 (Use set --no-event in the key binding
functions, 2023-01-10)) broke Vi mode cleanup, since Vi mode
uses a variable hook.  Let's update this variable also when using
fish_{default,vi}_key_bindings.  Another reason to keep this variable
in sync is to make the fish_key_bindings handlers working as expected.
2024-10-26 08:22:19 +02:00
Johannes Altmanninger
8eaa16542a Extract function for changing key bindings 2024-10-26 08:21:12 +02:00
Johannes Altmanninger
832cda26f6 Fix external cursor not being restored on exiting Vi mode 2024-10-26 08:21:12 +02:00
Johannes Altmanninger
0e97b876ea Simplify fish_vi_cursor
This command has redundant source statements which need a lot
of escaping. Also, let's extract a function, to be modified in a
following commit.
2024-10-26 08:21:12 +02:00
Johannes Altmanninger
aca8058717 Remove obsolete optimization in default binding initialization
This special case was added in fb2ed355e (Improve fork reporting Save a
couple of forks during init, 2012-04-24) but the reason for it is gone.
2024-10-26 08:21:12 +02:00
Johannes Altmanninger
dea7841611 Fix Vi replace mode regression not being able to append to command line
Regressed in d51f66964 (Vi mode: avoid placing cursor beyond last
character, 2024-02-14).
2024-10-26 08:21:12 +02:00
Johannes Altmanninger
c2cde317f2 Remove stale FISH_UNIT_TESTS_RUNNING workaround
This exists to make sure our assertions pass independent of the
terminal but now we unconditionally print __fish_cursor_xterm.
2024-10-26 08:21:12 +02:00
Johannes Altmanninger
04c9134275 Limit command line rendering to $LINES lines
Render the command line buffer only until the last line we can fit
on the screen.

If the cursor pushes the viewport such that neither the prompt nor
the first line of the command line buffer are visible, then we are
"scrolled". In this case we need to make sure to erase any leftover
prompt, so add a hack to disable the "shared_prefix" optimization
that tries to minimize redraws.

Down-arrow scrolls down only when on the last line, and up-arrow always
scrolls up as much as possible.  This is somewhat unconventional;
probably we should change the up-arrow behavior but I guess it's a
good idea to show the prompt whenever possible.  In future we could
solve that in a different way: we could keep the prompt visible even
if we're scrolled. This would work well because at least the left
prompt lives in a different column from the command line buffer.
However this assumption breaks when the first line in the command
line buffer is soft-wrapped, so keep this approach for now.

Note that we're still broken when complete-and-search or history-pager
try to draw a pager on top of an overfull screen.  Will try to fix
this later.

Closes #7296
2024-10-25 17:35:42 +02:00
Johannes Altmanninger
50333d8d00 Fix code duplication in commandline rendering
Will use this in the next commit.
2024-10-25 17:11:54 +02:00
Peter Ammon
0d5e6f356e Correct spelling of "courtesy" 2024-10-24 20:25:22 -07:00
Mahmoud Al-Qudsi
9c960d6af8 Fix number of characters consumed for VT200 mouse tracking
It's a 9-char CSI and we've read 3 (`<ESC>[T`), so we need to read six more.
Verified against the previous C++ codebase and couldn't find a reason for the
change to consuming 10 chars in a `git blame` run.
2024-10-24 11:22:52 -05:00
Mahmoud Al-Qudsi
daa2f2d023 Document max CSI parameter count 2024-10-24 10:36:00 -05:00
Mahmoud Al-Qudsi
21860cbd39 Fix panic parsing CSIs
The array lengths were transposed, so attempting to parse a CSI with more than 4
parameters would go out of bounds and panic.
2024-10-24 10:28:04 -05:00
Johannes Altmanninger
1b644226ec CHANGELOG: minor update 2024-10-22 08:55:08 +02:00
Johannes Altmanninger
d9633f2b38 Remove stale docs about fish_vi_force_cursor
Remove in 983746a69 (fish_vi_cursor: Remove terminal checks, 2024-08-30).
2024-10-21 21:53:32 +02:00
Johannes Altmanninger
5b249dbb41 test_env: remove stale env sanitization
These are unused since 983746a69 (fish_vi_cursor: Remove terminal checks,
2024-08-30).
2024-10-21 12:56:55 +02:00
Ilya Grigoriev
9c96ae0d40 ISSUE_TEMPLATE.md: Reset XDG_DATA_DIRS in suggested commands
This turned out to be relevant in https://github.com/fish-shell/fish-shell/issues/10800#issuecomment-2425170531 .
2024-10-21 12:54:43 +02:00
Johannes Altmanninger
2dbaf10c36 Also refresh TTY timestamps after external commands from bindings
Commit ba67d20b7 (Refresh TTY timestamps after nextd/prevd, 2024-10-13)
wasn't quite right because it also needs to fix it for arbitrary commands.

While at it, do this only when needed:
1. It seems to be only relevant for multiline prompts.
   Note that we can wait until after evaluation to check if the prompt is
   multiline, because repaint events go through the queue, see 5ba21cd29
   (Send repaint requests through the input queue again, 2024-04-19).
2. When the binding doesn't execute any external command, we probably don't
   need to fix up whatever the user printed. If they actually wanted to show
   output and print another prompt, they should currently use  "__fish_echo",
   to properly support multiline prompts. Bindings should produce no other
   output. What distinguishes external programs is that they can trigger this
   issue even if they don't  produce any output that remains visible in fish,
   namely by using the terminal's alternate screen.
   Would be nice if we could get rid of __fish_echo; I'm not yet sure how.

Fixes #10800
2024-10-21 12:13:00 +02:00
Johannes Altmanninger
30cba03bf9 Make SIGTERM handler async-signal-safe again 2024-10-21 09:30:47 +02:00
Johannes Altmanninger
ae7b401029 completions/set: show innermost scope in variable description
A side effect of cd9e50c2c (completions/set: Complete variables of all scopes
when setting, 2024-10-03) is that

    HOME=$(mktemp -d) fish
    fish_config choose ayu\ Light
    set -S fish_color_

gives only completions that have the "Universal variable" description even
though most colors are also defined in the global scope which usually takes
precedence.

Fix this by reordering the completions. (The last-added completion is shown
first which is very surprising, we should change that).

This is not perfect; if the user has already specified `-U`, then we should
probably not show description of the global version.  But that's still
worth the trade that this commit makes.  Finally, the description could show
something like "Defined in universal and global scope" etc.
2024-10-20 07:55:04 +02:00
Johannes Altmanninger
2e4f98b51c Do not add a space after completing inside brace expansion
Another everyday annoyance, has been for many years.
2024-10-19 22:06:05 +02:00
Johannes Altmanninger
c41dbe4551 Also use control pictures for pager prefix
The test case shows that the pager rendering is not quite right.  It renders
'{\', leaving out the newline.  This rendering is ambiguous.

Let's fix it by rendering \n as control picture, like we do for other control
characters in the pager.
2024-10-19 22:05:49 +02:00
Johannes Altmanninger
f5c6829670 Fix pager being blank when token prefix contains newline
Given

    $ echo {\
    C

where C is the cursor.
Completions have prefix "{\\\n".
Since \n has a wcwidth of -1, this line always fails

    let prefix_len = usize::try_from(fish_wcswidth(&self.prefix));

This triggers uncovers a regression in 43e2d7b48 (Port pager.cpp, 2023-12-02),
where we end up computing comp_width=0 for all completions.

Fix this. Test in the next commit.

The C++ version added the prefix width only if the completion had a valid
width. That seems wrong, let's do it always (if the prefix width is valid).
2024-10-19 22:05:49 +02:00
Johannes Altmanninger
cd541575b4 Fix completion failing on unclosed brace with wildcard
Completion on ": {*," used to work but nowadays our attempt to wildcard-expand
it fails with a syntax error and we do nothing.  This behavior probably only
makes sense for the overflow case, so do that.
2024-10-19 22:04:54 +02:00
Johannes Altmanninger
f4ff312265 Fix typo in docs 2024-10-19 22:04:54 +02:00
Johannes Altmanninger
3d5ef2bcf5 Fix inverted condition in panic handler
Fixes 139d204c (Restore terminal state again in panic handler, 2024-10-12).
2024-10-19 22:04:54 +02:00
Rikuki IX
85801b443a feat(completion): add lsb_release completion (#10795) 2024-10-19 13:06:06 -05:00
Jason Nader
6082c3f77a completions/diff: allow file completion for --unified (#10796)
* completions/diff: allow file completion for --unified

* Update diff.fish

* Update diff.fish
2024-10-19 16:58:29 +02:00
Johannes Altmanninger
b625c566b1 Remove workaround for WezTerm configured with enable_kitty_keyboard=true
On a German keyboard, with a German keymap, and this ~/.wezterm.lua

    local wezterm = require 'wezterm'
    local config = wezterm.config_builder()
    config.enable_kitty_keyboard = true
    return config

when I press shift+# (which is single quote)
WezTerm sends the CSI u encoding shift-'.

Because of this, we completely disable kitty progressive enhancements and
modifyOtherKeys on WezTerm.

It makes no sense for every single app to work around WezTerm violating the
protocol. All these workarounds just create unnecessary version dependencies.
Also our workaround is brittle; it breaks as soon as you're inside something
like SSH.
Least importantly, the workarond prevents users of English keyboard layouts
to easily use the new features.

Since it seems so easy to work around by settting "enable_kitty_keyboard = false",
and most importantly, since that's the default, it seems better to remove
the workaround to simplify the world.

See #10663
2024-10-17 11:30:30 +02:00
Johannes Altmanninger
3869b59000 Add some context to changelog on new alt arrow bindings 2024-10-17 11:30:30 +02:00
Fabian Boehm
a1e74007d2 CHANGELOG colorscheme 2024-10-17 11:14:01 +02:00
Fabian Boehm
81ff6db62d default color scheme: Make commands "normal" color
This makes the default colorscheme less colorful for two reasons:

1. It makes it a little less "angry fruit salad"
2. Some terminals (like Microsoft's Windows Terminal) have a terrible
blue default that contrasts badly against a black background

The alternative is to make *parameters* "normal" and give commands the
current parameter color (cyan). But I've seen cyan be quite blue and
quite green depending on the terminal, so I don't want to rely on it.
2024-10-15 21:21:30 +02:00
Fabian Boehm
0dfc490721 build.rs: Use Cargo_PKG_VERSION if no version could be found
`cargo build --git` clones a git repo without any tags, so you get a
version like

```
fish, version f3fc743fc
```

which is *just* the commit hash and missing the "3.7.1-NUM-g" part.

So, if we hit that case (detected because it has no ".", under the
assumption that we'll never make a version that's just "4" instead of
"4.0"), we prepend the version from Cargo.toml.
2024-10-15 13:10:07 +02:00
Fabian Boehm
de13e6f9af complete: Only describe commands if the function exists
This shells out to __fish_describe_command, but if the install is
incomplete that will trigger the command-not-found handler.
2024-10-15 13:09:02 +02:00
Fabian Boehm
ebf19c22fd fish_config: Find fish via fish-path 2024-10-15 13:09:02 +02:00
Mahmoud Al-Qudsi
8447c32d65 __fish_indent: Cache fish_indent location 2024-10-14 19:01:41 -05:00
exploide
7bb6ce5156 completions: added arping 2024-10-14 15:34:11 -07:00
EmilyGraceSeville7cf
1148b790bb feat(completion): support winetricks command 2024-10-14 15:11:45 -07:00
exploide
2f2b4c8e99 completions: updated hashcat completions 2024-10-14 12:12:07 -07:00
Fabian Boehm
9f92d1f204 CI: Remove test deps from the clippy check 2024-10-14 21:02:26 +02:00
Johannes Altmanninger
b4f86bf0f5 Fix installation of pexpect on latest GitHub Actions images
We already use --break-system-packages for macOS but it's not necessary here.
2024-10-14 11:26:08 +02:00
Johannes Altmanninger
a2dc0ef377 Revert "Lock history file before reading it"
Commit 5db0bd5 (Lock history file before reading it, 2024-10-09)
rewrites the history file in place instead of using rename().
By writing to the same file (with the same inode), it corrupts
our memory-mapped snapshot; mmap(3) says:

> It is unspecified whether modifications to the underlying object done
> after the MAP_PRIVATE mapping is established are visible through the
> MAP_PRIVATE mapping.

Revert it (it was misguided anyway).

Closes #10777
Closes #10782
2024-10-14 11:13:46 +02:00
Peter Ammon
fbf0ad98af Build macOS x86-64 with Rust 1.73.0 in make_pkg.sh
This retains compatibility with macOS 10.9.
Note that Apple Silicon Macs shipped with 10.15, so compatibility for Apple
Silicon is not a concern.
2024-10-13 14:36:02 -07:00
Peter Ammon
9337c20c2e Stop using the getrandom feature of the rand crate
This feature uses the "getentropy" function which is not supported on
macOS < 10.12.
2024-10-13 12:39:54 -07:00
Johannes Altmanninger
6af96a81a8 Default bindings for token movement commands
There is no natural default binding for token movements. Add the
alt-{left,right,backspace,delete}, breaking some existing behavior.

For example, backward-delete-word is no longer bound to alt-backspace but
only to ctrl-backspace.  Unfortunately some terminals (particularly tmux)
don't support distinguishing ctrl-backspace from ctrl-h yet, so the loss
of alt-backspace may be tragic.

---

I guess we could also add:

    bind alt-B backward-token
    bind alt-F forward-token
    bind ctrl-W backward-kill-token
    bind alt-D kill-token

Those might be intercepted by the terminal on Linux, but I don't know where
that happens.

Tested on foot, kitty, alacritty, xterm, tmux, konsole and gnome-terminal.

Closes #10766
2024-10-13 14:53:45 +02:00
Johannes Altmanninger
2dafe81f97 Builtin source to print error if missing both file argument and piped stdin
Closes #10774
2024-10-13 10:44:38 +02:00
Johannes Altmanninger
00875d0f83 Allow builtin source to read from non-regular files
Commit a91bf6d88 (builtin.c: builtin_source now checks that its argument is
a file., 2005-12-16) fixed an infinite loop for commands like "source /"
where the argument is a directory.

It did so by erroring out early unless the filename argument is a regular file.
This is too restrictive; it disallows reading from special files like /dev/null
and fifos.
Today we get a sensible error without this check, so remove it.
2024-10-13 10:44:38 +02:00
Johannes Altmanninger
ba67d20b7c Refresh TTY timestamps after nextd/prevd
This fixes a macOS-specific bug.  See 390b40e02 (Fix regression not refreshing
TTY timestamps after external command from binding, 2024-05-29) and 8a7c3ceec
(Don't abandon line after writing control sequences, 2024-04-06).

Fixes #10779
2024-10-13 08:17:22 +02:00
Johannes Altmanninger
3a02a3bd6c Fix tmux-multiline-prompt test on some systems
The fast input would race with tmux redrawing the screen,
so sometimes the ": 5" is rendered twice.
2024-10-13 08:17:22 +02:00
Johannes Altmanninger
24e7a2ca60 Disable tmux OSC 133 prompt marking test also on cirrus' old alpine
tmux -V prints "tmux next-3.4" there.
2024-10-12 21:05:27 +02:00
Johannes Altmanninger
f77153e6c8 Disable tmux OSC 133 prompt marking test for some tmux versions < 3.4
OSC 133 was added to tmux 3.4.

Also fix the test on macOS where we do have 3.5a in CI; for some reason we
get copy_cursor_y=6 there.  I didn't investigate yet but at least that's
not the same bug this test was made to fix.
2024-10-12 19:48:26 +02:00
Johannes Altmanninger
5496247344 Avoid erasing OSC 133 prompt start marker with clr_eol
For multi-line prompts, we start each leading line with a clr_eol.  Immediately
before printing these prompt lines we emit the OSC 133 prompt start marker.
Some terminals such as tmux interpret make clr_eol delete such markers,
hence prompt navigation is broken.

Fix this by printing the marker only after clr_eol.

The scenario where this triggers is quite odd.  I haven't looked into why
the problem doesn't exist if I remove the recursive repaint request.

See https://github.com/tmux/tmux/issues/4183
Closes #10776
2024-10-12 19:00:16 +02:00
Johannes Altmanninger
69380c6c92 Remove redundant test setup
One function calls setup twice, and the other one is not a test so should
not be prefixed with "test_".
2024-10-12 13:32:19 +02:00
Johannes Altmanninger
a139d204c0 Restore terminal state again in panic handler
Our panic handler attempts a blocking read from stdin and only exits
after the user presses Enter.

This is unconventional behavior and might cause surprise but there is a
significant upside: crashes become more visible for terminals that don't
already detect crashes (see ecdc9ce1d (Install a panic handler to avoid
dropping crash stacktraces, 2024-03-24)).

As reported in 4d0aa2b5d (Fix panic handler, 2024-08-28), the panic handler
failed to exit fish if the panic happens on background threads.  It would
only exit the background thread (like autosuggestion/highlight/history-pager
performer) itself. The fix was to abort the whole process.
Aborting has the additional upside of generating a coredump.

However since abort() skips stack unwinding, 4d0aa2b5d makes us no longer
restore the terminal on panic. In particular, if the terminal supports kitty
progressive enhancements, keys like ctrl-p will no longer work in say,
a Bash parent shell.  So it broke 121680147 (Use RAII for restoring term
modes, 2024-03-24).

Fix this while still aborting to create coredumps.  This means we can't use
RAII (for better or worse).  The bad part is that we have to deal with added
complexity; we need to make sure that we set the AT_EXIT handler only after
all its inputs (like TERMINAL_MODE_ON_STARTUP) are initialized to a safe
value, but also before any damage has been done to the terminal. I guess we
can add a bunch of assertions.

Unfortunately, if a background thread panics, I haven't yet figured out how
to tell the main thread to do the blocking read.  So the trick of "Press
Enter to exit", which allows users to attach a debugger doesn't yet work for
panics in background threads.  We can probably figure that out later. Maybe
use pthread_kill(3)?  Of course we still create coredumps, so that's fine.
As a temporary workaround, let's sleep for a bit so the user can at least
see that there is a crash & stacktrace.

One ugly bit here is that unit tests run AT_EXIT twice but it should be
idempotent.
2024-10-12 13:28:55 +02:00
Johannes Altmanninger
468849dd54 Minor refactoring in panic handler
I don't think I really get why this newline is here. It moves the cursor
from the end of the newline to the beginning of the next line.  Maybe it
was added only for panics in background threads?  Either way it's fine.
2024-10-12 12:18:50 +02:00
Johannes Altmanninger
97581ed20f Do send bracketed paste inside midnight commander
It can handle it fine (well, it simply strips the control sequences..).
2024-10-12 12:18:50 +02:00
Johannes Altmanninger
0d9dfb307b Apply terminal protocol workarounds also in fish_key_reader
We don't care to check the latest value of these variables;
these should only be read on startup and are not meant to
be overridden by the user ever. Hence we don't need a parser.
2024-10-12 12:18:50 +02:00
Johannes Altmanninger
fe3e3b3b50 Fix potential assertion failure on SIGTERM
If SIGTERM is delivered to a background thread, a function call to sanitize
the reader state would crash in assert_is_main_thread(). In this case we
are about to exit so there's no need to fix the reader state. Skip it on
background threads.
2024-10-12 10:50:56 +02:00
Johannes Altmanninger
49b88868df Fix stripping of " (deleted)" from non-UTF8 paths to fish 2024-10-12 06:53:25 +02:00
Johannes Altmanninger
edaf011ab1 Try to use the fish_indent that corresponds to the fish binary
Users may install two versions of fish and configure their terminal to run
the one that is second in $PATH.  This is not really what I'd do but it
seems reasonable.  We should not need $PATH for this.

Fixes #10770
2024-10-10 05:18:35 +02:00
Johannes Altmanninger
88e749e4ce fixup! Back out assertion that doesn't hold yet 2024-10-09 21:35:56 +02:00
Johannes Altmanninger
c5db7565cc Back out assertion that doesn't hold yet 2024-10-09 21:34:19 +02:00
Johannes Altmanninger
5db0bd5874 Lock history file before reading it
We use optimistic concurrency when rewriting the history file to
minimize the lock scope. Unfortunately, old.mtime == new.mtime
does not imply that file is unchanged; we don't have guarantees
on the granularity of the modification time timestamp, see
https://stackoverflow.com/questions/14392975/timestamp-accuracy-on-ext4-sub-millsecond

So let's lock before reading any old contents and use the other
"write-to-tempfile-and-rename" code path only when locking fails.

Potentially fixes #10300
(untested) which probably happens because read_zero_padded() attempts to
read bytes that have not been flushed yet.
2024-10-09 14:51:54 +02:00
Johannes Altmanninger
35ee5e661f history: rename target_fd_after to target_file_after
This was forgotten in decf99f71 (Use `File` instead of `OwnedFd` in a few
places (#10355), 2024-03-17).
2024-10-09 14:51:54 +02:00
Johannes Altmanninger
f906a949cf Temporarily enable history_file debug category by default
All of these should never happen so let's enable them to hopefully get useful
bug reports.  Should disable it again before a release.

See #10300
2024-10-09 14:51:54 +02:00
Johannes Altmanninger
13e5d8097c Log more history_file errors, and add more context
See #10300
2024-10-09 14:51:54 +02:00
Johannes Altmanninger
29a01eb3cf Fix EINTR handling when importing history from bash 2024-10-09 14:48:58 +02:00
Johannes Altmanninger
ffedcdaac3 Do not interpret unknown file systems as local on Linux
No functional change, since with the parent commit, we no longer treat
"DirRemoteness::local" different from "DirRemoteness::remote", but we might
do so in future, so make sure we don't give a false positive here.

Non-Linux systems have ST_LOCAL or MNT_LOCAL, so no unknowns there.

See #10434
2024-10-09 14:48:58 +02:00
Johannes Altmanninger
dc5823d150 Fix history merge on all network file systems
mmap() fails with ENODEV on remote file systems. This means we always fail
to read any old history on network file systems on Linux (except on the file
systems we recognize which are NFS, SMB and CIFS).

Untested, so I'm not sure if this works.

Fixes #10434
2024-10-09 14:48:58 +02:00
Johannes Altmanninger
37c04745e6 Avoid potential contention on SIGTERM while enabling terminal protocols
We no longer use RAII for enabling/disabling these, so a full object is
overkill.  Additionally this object doesn't allow us to recover from the case
where we receive SIGTERM while inside terminal_protocols_{enable,disable}.
We can simply run disable another time since they're idempotent. Untested.
2024-10-09 13:05:25 +02:00
Lucas Garron
a7abd83c57 Typo fix: documentaiton → documentation
Closes #10767
2024-10-09 12:36:58 +02:00
Johannes Altmanninger
2b873570a8 Fix typo 2024-10-09 12:36:58 +02:00
Fabian Boehm
e3ecfa729d CHANGELOG
The flow control thing isn't down to us, it's apparently a common
terminal issue where they no longer trigger suspend when CSI u is
used.
2024-10-08 19:34:24 +02:00
Peter Ammon
c33b35efd4 Set macOS version minimums harder
Fix the macOS app.
2024-10-06 16:38:21 -07:00
Peter Ammon
0e474768f4 Set macOS version minimums when building
Allows running on older versions of macOS.
2024-10-06 14:39:04 -07:00
Johannes Altmanninger
efa109b62e Add default-enabled error log when there is a corrupted history entry
We'll drop the corrupted item on the next vacuum, so this shouldn't be
too annoying, and hopefully helps to narrow down #10300 further.
2024-10-06 11:48:51 +02:00
Johannes Altmanninger
9c4d31f89a Make errors in the history_file log category human-readable 2024-10-06 11:42:30 +02:00
Johannes Altmanninger
f36f757fa6 Never rewrite history file when adding ephemeral items
When I run a command with leading space, it is not added to the on-disk
history.  However we still call History::save().  After 25 of such calls,
we rewrite the history file (even though nothing was written by us).

This is annoying when diagnosing #10300 where the history of the current
shell (but not other shells) is broken; because the history rewrite will
make the problem go away. Let's not save in this case, to make it easier to
run commands to inspect the state of the history file.
2024-10-06 08:30:53 +02:00
Johannes Altmanninger
33bcf4d0ce Remove redundant drop 2024-10-06 08:30:53 +02:00
Peter Ammon
521498143a Fix the static PCRE2 build harder
Commit 4e79ec5f tried to restore the static PCRE2 build after the update to the
pcre2 crate, but it set an environment variable at configure time, not build
time.

Properly set the environment variable at build time.
2024-10-05 20:22:55 -07:00
Johannes Altmanninger
1b9b893169 After reading corrupted history entry, keep reading older entries
Given a history like

    - cmd: echo OLD
      when: 1726157160
    \x00\x00\x00- cmd: echo leading NUL bytes
      when: 1726157160
    - cmd: echo NEW
      when: 1726157223

offset_of_next_item() happily records 3 items even though the second item
is corrupted.
decode_item() fails which makes the caller stop loading any older items --
we got knee capped.

Avoid this horrible failure mode by skipping over these items already in
offset computation. For now we still lose the corrupted item itself.

In future we should probably try to delete the NUL bytes or avoid the
corruption in the first place.

See #10300 and others.
2024-10-06 00:28:26 +02:00
diniamo
052e764f29 accept-autosuggestion to return false if there was no autosuggestion to accept
Example usage:

    bind ctrl-space accept-autosuggestion and execute

Closes #10608
2024-10-05 23:43:16 +02:00
EmilyGraceSeville7cf
cd3da62d24 fix(completion): unescape strings for __fish_complete_list 2024-10-05 23:32:59 +02:00
Jacob Chapman
a9cee9e755 Commands to move by entire tokens
ja: I'll try to add default bindings in a follow-up PR.

Closes #10738
Closes #2014
2024-10-05 22:43:39 +02:00
Fabian Boehm
e4c7a522ff webconfig: Add missing highlighting vars
This would otherwise not set these variables.

Tbh I would like if this wasn't hardcoded like that.
2024-10-05 16:30:58 +02:00
Fabian Boehm
5e8adb18f4 complete: Sort --keep-order completions smaller
This should make the sort have a strict weak ordering, which rust
requires since 1.81 (or it will panic).

Note: This changes the order, but that's *fine* since the current
order is random weirdness anyway.

Fixes #10763
2024-10-05 13:53:02 +02:00
Fabian Boehm
2238c07b91 path: Remove weird order hack
Part of #10763
2024-10-04 16:48:40 +02:00
Wolfgang Müller
38300a818e completions/portage: Follow symbolic links in repos.conf
Repository configuration files in the repos.conf/ directory may also be symbolic
links, so make sure to follow those.
2024-10-04 10:23:58 +02:00
Fabian Boehm
cd9e50c2cc completions/set: Complete variables of all scopes when setting
This was overly smart and tried to not show you e.g. global variables
unless you were setting without scope or explicitly global.

That is annoying when you do

`set -g fish_col<TAB>`

and don't get colors because they're universal, but you could
overwrite them.

We *could* elide e.g. local variables if we're setting a global, but I
can see someone wanting to set a universal variable on basis of a
global ("save this"), so I would rather not try to find the very
specific cases where this works.
2024-10-03 11:46:17 +02:00
Fabian Boehm
0fea1dae8c __fish_print_help: Make formatting more man-like
1. Leave the indentation
2. Leave the "NAME" header - without the first line would be
unindented
3. Leave the "SYNOPSIS" header

We use $MANPAGER here, so it should be formatted like a manpage.

The alternative is to write special docs for this use-case, which
would be shorter and point towards the full man page.

Fixes #10625
2024-10-03 11:29:24 +02:00
EmilyGraceSeville7cf
07bc54f406 feat(template): note about not documenting completions in PRs 2024-10-03 09:44:42 +02:00
Nikita Bobko
c253aa7a8c fish_vi_key_bindings: add bindings for semicolon and comma in visual mode
They are already presented in normal mode, and I presume were forgotten to be
added in visual mode

I don't add it to ./CHANGELOG.rst because it's a minor change that can be
considered as a bug fix
2024-10-03 09:42:59 +02:00
Johannes Altmanninger
f6d5355d7a Bump iTerm workaround version
This unnecessarily enables the workaround for some nightly versions.

See #10653
2024-09-30 11:00:03 +02:00
Peter Ammon
4e79ec5f0e CMake: Restore static PCRE2 builds
The recent update to the rust-pcre2 crate lost the property where a static
PCRE2 build could be enabled with a Cargo feature. This means that static
PCRE2 builds can no longer be forced.

Switch to setting the "PCRE2_SYS_STATIC" variable again, which is how the
official rust-pcre2 crate expects to work.
2024-09-29 19:42:48 -07:00
Peter Ammon
c227233571 fish_apropos: use realpath instead of readlink
readlink -f is not supported on macOS Big Sur (from 2020).
2024-09-29 18:13:36 -07:00
Johannes Altmanninger
243a8345ce Minor changelog updates 2024-09-28 18:00:02 +02:00
Johannes Altmanninger
d829a99977 Fix kbd tag HTML rendering
Commit c921c124e (docs: use canonical key names in :kbd: tags, 2024-04-13)
removed the box highlighting from elements like :kbd:`ctrl-c`.
This is because Sphinx for some reason converts this into

    <kbd>
        <kbd>ctrl</kbd>
        -
        <kbd>c</kbd>
    </kbd>

which results in duplicate boxes.
(See https://github.com/sphinx-doc/sphinx/issues/7530)

Our current style looks a bit ugly (it's
definitely worse than github's rendering at
https://github.com/fish-shell/fish-shell/blob/master/CHANGELOG.rst).
Let's restore the old style but make sure to only apply it only to the
outermost kbd element.

While at it, use the same monospace font as for inline code.
2024-09-28 18:00:02 +02:00
Johannes Altmanninger
4c43819d32 Fix crash indenting quoted suffix after command substitution
Commit b00899179 (Don't indent multi-line quoted strings; do indent inside
(), 2024-04-28) made parse_util_compute_indents() crash on `echo "$()"'x`.
After recursively indenting the command substitution, we indent the "'x
suffix.  We skip the quoted part by setting "done=2".  Later we wrongly
index "self.indents[done..range.start+offset+1]" (= "self.indents[2..1]").

Fix this by making sure that "start >= done", thus not setting any indents
for the quoted suffix.  There is no need to do so; only the first character
in each line needs an indent.
2024-09-28 13:36:17 +02:00
Johannes Altmanninger
50314e309b Follow naming convention 2024-09-28 13:35:07 +02:00
Johannes Altmanninger
d00e900e5a Don't reattempt failing history pager search
In particular, this fixes the case

    ctrl-r foo ctrl-r

where foo substring-matches no more than one page's worth of results.
The second attempt will fall back to subsequence matching which is wrong.
2024-09-28 11:28:49 +02:00
Johannes Altmanninger
ae7fd770ee Extract history pager state 2024-09-28 11:26:50 +02:00
Johannes Altmanninger
263f1b35de Reapply "Clear to eol before outputting line in multi-line prompt"
In case a terminal resize[1] causes us
to repaint a multi-line prompt that changes width like

    function fish_prompt
        for i in 1 2 3
            random choice 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'bbbbbbbbbbb'
        end
    end

we add a clr_eol after each line[2] , to make sure
that a "b" line does not have leftover "a" letters
(80aaae5b7 (Clear to end of each line in left prompt, 2020-10-25)).

Unfortunately, if a prompt line takes up all the columns, clr_eol will
wrongly clear the last column. Reproduce with

    function fish_prompt
        string repeat $COLUMNS -
        echo "$PWD> "
    end

and observe that the last "-" is missing.

Previous (reverted) attempt d3ceba107 (Clear to eol before outputting line
in multi-line prompt, 2021-05-17) found the right fix but had an off-by-one
error which reintroduced the leftover "a" letters in the "random choice"
prompt above.

Given prompt string "aa\nbb\ncc", it wrongly printed

    clr_eol "aa" clr_eol "\nbb" "\ncc"

Observe that the first line is cleared twice, while the second line is
never cleared. Fix that.

[1]: or an async "commandline -f repaint" triggered by a uvar change /
     async prompt update
[2]: except after the last line where we probably already emit clr_eol
     elsewhere..

Alternative fix: emit both clr_eol and clr_bol *before* drawing the current
line. However, if fish and the terminal disagree on character width, that
approach might erase too much.

Closes #8164
2024-09-28 10:39:54 +02:00
Fabian Boehm
48a6550688 Remove obsolete workaround for strftime on BSD
This was added in libc 0.2.152, see aff5e66e54
2024-09-24 21:38:15 +02:00
Fabian Boehm
798150ac39 Update widecharwidth for Unicode 16
Commit 533e50efb0b9b122a08f2273337dbf6b44b03cc7 upstream.
2024-09-24 17:00:13 +02:00
Peter Ammon
4e8d6b1760 Improve the README of the printf crate 2024-09-23 11:16:42 -07:00
Johannes Altmanninger
308ed62d83 fish_key_reader: stop emitting \n for ctrl-j
I guess it's nice to know that these two are the same but that info is not
needed here, it just adds confusion. The user must have pressed ctrl-j if
we get here, so echo that back.

See the parent commit.
2024-09-23 20:08:46 +02:00
Johannes Altmanninger
4336f9df7f fish_key_reader: stop emitting \b for ctrl-h
This is just too confusing; \b sounds like it would map backspace but it's
actually just ctrl-h.  Backspace is a different key ("bind backspace"),
so let's move away from \b.

Reproduce by typing ctrl-h in fish_key_reader, or, for even more confusion,
use a terminal like tmux and type ctrl-backspace which also sends ctrl-h.

I've thought about changing \b (and its aliases like \ch and \x08) to mean
backspace but that seems like unnecessary breakage, since they all already
mean ctrl-h, and can usually be mapped independent of backspace.

See the discussion in #10738
2024-09-23 20:00:35 +02:00
Johannes Altmanninger
2e9de57fd7 Document ctrl-backspace and bind ctrl-delete as well
This has a slightly different behavior than what the CUA user expects:
it fails to eat up trailing spaces.  We should probably fix this.
2024-09-23 14:52:50 +02:00
Johannes Altmanninger
904649c5c5 Bind ctrl-backspace to backward-kill-word
Closes #10741
2024-09-23 14:32:43 +02:00
Peter Ammon
e3993a3d96 Update code and Cargo.toml for recent pcre2-utf32 changes 2024-09-22 17:05:14 -07:00
Peter Ammon
617b61cd3a Clean up fd_monitor getter
No need for UnsafeCell
2024-09-22 14:02:55 -07:00
Peter Ammon
fb700ca50d Clean up a few more comments 2024-09-22 13:11:40 -07:00
Peter Ammon
f733553ac8 Clean up some stale comments 2024-09-22 13:09:11 -07:00
Peter Ammon
520a3b5a12 Add a repository field to fish_printf's manifest 2024-09-21 18:43:46 -07:00
Peter Ammon
974ad882fa Clean up fish-printf in preparation for publishing
Make fish-printf no longer depend on the widestring crate, as other clients
won't use it; instead this is an optional feature.

Make format strings a generic type, so that both narrow and wide strings can
serve. This removes a lot of the complexity around converting from narrow to
wide.

Add a README.md to this crate.
2024-09-21 17:52:11 -07:00
Fabian Boehm
cdcf460edf math: Nicer error for non-ascii-lowercase identifiers
This gave a weird error when you did e.g. `math Foo / 6`:

"Missing Operator" and only the "F" marked.

Adding an operator here anywhere won't help, so calling this an
"Unknown function" is closer to the truth. We also get nicer markings
because we know the extent of the identifier.
2024-09-18 22:27:00 +02:00
Fabian Boehm
fc7be1c2a3 Minor doc fixes 2024-09-18 22:11:14 +02:00
EmilyGraceSeville7cf
0277fe3ca9 feat(completion): add test-spice support 2024-09-17 19:44:09 +02:00
EmilyGraceSeville7cf
98de7ea14a feat(completion): add validate-spice support 2024-09-17 19:44:09 +02:00
EmilyGraceSeville7cf
63e7608be4 feat(completion): add cascadia completion 2024-09-17 19:43:31 +02:00
mattmc3
9eee1b4499 fish_indent: Cleanup all *.fish files not in tests 2024-09-17 19:11:42 +02:00
Johannes Altmanninger
add0a9dfcd fish_indent: clean up file writing logic
Fix 7308dbc7a (fish_indent: Prevent overwriting file with identical content,
2024-07-21) in a different way by passing O_TRUNC again.
If we don't want regressions we could use code review.
2024-09-16 21:27:11 +02:00
Fabian Boehm
e27f4a3744 fish_indent: Truncate file to the size of the text
This can happen in case the formatted script is shorter, e.g. because
we ditched superfluous quotes.

Fixes #10724
2024-09-16 21:08:53 +02:00
Fabian Boehm
9fafae7a8a docs/complete: Explain -r a bit better 2024-09-15 09:44:09 +02:00
Fabian Boehm
8092af9c45 docs/prompt: Add funcsave/funced 2024-09-15 09:39:13 +02:00
Fabian Boehm
f9635b1a04 docs/argparse: Explain dashes in flag names 2024-09-15 09:39:09 +02:00
Johannes Altmanninger
1e2368f609 Fix off-by-one-error parsing \e\e prefixed sequences
Closes #10721
2024-09-14 22:56:37 +02:00
Rebecca Turner
a6c8cd6e85 Fix man completions on macOS with symlinked manpath
When `manpath` prints a symlink to a directory, `/usr/libexec/makewhatis`
ignores the entire directory:

```
$ /usr/libexec/makewhatis -o /tmp/whatis \
    (/usr/bin/manpath | string split :)
makewhatis: /Users/wiggles/.nix-profile/share/man: Not a directory
```

This means that the built-in `man` completions will not index any commands in
these directories.

If we pass the directories to `readlink -f` first, `makewhatis` correctly
indexes the `man` pages.

```
$ /usr/libexec/makewhatis -o /tmp/whatis \
    (/usr/bin/manpath | string split : | xargs readlink -f)
```
2024-09-14 13:38:33 -07:00
Kerim
bc55945072 improved vi keybind 2024-09-14 13:33:21 -07:00
Peter Ammon
8f3a034264 History to store old item offsets in Vec and not VecDeque
We used deque in C++ because this vector may be large, and so it avoids
repeated re-allocations. But VecDeque is different in Rust - it's contiguous -
so there's no benefit. Just use Vec.
2024-09-14 13:26:34 -07:00
Peter Ammon
7ac62bbca4 Remove a redundant "unsafe" specifier 2024-09-14 13:15:21 -07:00
mattmc3
0a1bf01574 docs: Update synopsis for 'set' 2024-09-14 10:29:44 +02:00
Johannes Altmanninger
5432ee1aa9 Relax history autosuggestion and highlighting if cd is wrapped
For implementation reasons, we special-case cd in several ways
1. it gets different completions (handle_as_special_cd)
2. when highlighting, we honor CDPATH
3. we discard autosuggestions from history that don't have valid path arguments

There are some third-party tools like zoxide that redefine cd ("function cd
--wraps ...; ...; end"). We can't support this in general but let's try to
make an effort.

zoxide tries to be a superset of cd, so special case 1 is still
valid but 2 and 3 are not, because zoxide accepts some paths
that cd doesn't accept.

Let's add a hack to detect when "cd" actually means something else by checking
if there is any --wraps argument.

A cleaner solution is definitely possible but more effort.

Closes #10719
2024-09-14 08:51:42 +02:00
Johannes Altmanninger
5b04f221a3 __fish_anypager: remove bat from default choice
As pointed out in
b83f3b0e98 (commitcomment-146189480)
bat is not actually useful. Also its (monochrome) output is unreadable on
my system.
2024-09-14 07:21:56 +02:00
Johannes Altmanninger
9eeed5ca12 Install fish-* man pages in default MANPATH
fish adds ~/.local/share/fish/man to its MANPATH for builtins etc.  But pages
like fish-doc are unambiguous so it seems like they should be accessible
from outside fish by default.

Closes #10711
2024-09-14 07:21:18 +02:00
Johannes Altmanninger
5ad7ab7b01 Clear some env variables in test env setup 2024-09-14 07:21:18 +02:00
Harmen
fc4dd8f4de docs: fix "theme choose None" command
The command needs an upper-case "None", not a lower case.
2024-09-13 12:21:34 +02:00
Theodor Tonum
5344576dc6 fix: pacman quiet typo 2024-09-13 09:59:56 +02:00
Kaley Main
a979b6341d Create a test that reproduces fish-shell/fish-shell#10703 2024-09-06 16:41:10 +02:00
Johannes Altmanninger
f8a720da8c Fix wildcard expansion doubling up "*/"
In some cases we add the wildcard twice.

    $ fish -c '../jj; complete -C"ls cli/*/conf/tem"'
    cli/*/*/config/templates.toml

Fix that. Test in the next commit.

There seems to be another bug in 3.7.1 where we fail to apply this completion
to the command line. This appears fixed. (FWIW we might want to revert
the quoting change in completion_apply_to_command_line(), maybe that one
accidentally fix this).

Fixes #10703
2024-09-06 16:41:10 +02:00
Fabian Boehm
325b51aca0 docs/set: Fix markup
Fixes #10697
2024-09-05 19:30:38 +02:00
Abel Chalier
65ab9e7bfc clearer wording on test.fish completions 2024-09-05 17:33:24 +02:00
may
79a9c0e0f2 add completions for git diff --color-moved and --color-moved-ws (#10698) 2024-09-03 18:00:17 -05:00
Johannes Altmanninger
77b2dcb462 Fix ctrl-c being ignored during builtin wait
Same as d21ed0fb2 (Disable terminal protocols before expanding wildcards,
2024-07-31).

Also mention a related issue in the changelog.
2024-09-01 14:08:01 +02:00
Johannes Altmanninger
15b08cbcab Make import style less noisy 2024-09-01 14:05:48 +02:00
Mahmoud Al-Qudsi
50a6dfd10d Replace a HashMap w/ a BTreeMap
The HashMap is used to generate the __fish_describe_command integration
completions. Given the nature of the allocations and the numbers that we use, a
BTreeMap would theoretically perform better. Benchmarks show a 2-9%
improvement in completion times consistently in favor of BTreeMap.
2024-08-31 14:13:41 -05:00
Mahmoud Al-Qudsi
73908f1218 fish_test_helper: Fix warnings about intentionally unused results
Warnings were appearing under GCC 13.2

(void) alone is insufficient under modern compilers, workaround with logical
negation taken from GCC bug tracker.
2024-08-31 13:16:51 -05:00
Mahmoud Al-Qudsi
ef6577db25 Update threads::thread_id() documentation 2024-08-31 12:57:13 -05:00
Mahmoud Al-Qudsi
c6bbacc703 Catch tls issues caused by linker bug
Worth including because mold is rather popular in the rust world and because the
bug affects mold versions coincident with the development of the fish rust port.

The bug affects all currently released versions of mold from 2.30.0 (Mar 2024)
onwards under at least FreeBSD (though quite likely other platforms as well).

See https://github.com/rui314/mold/issues/1338 for reference.
2024-08-31 12:48:15 -05:00
Fabian Boehm
c1d9f57107 CHANGELOG 2024-08-30 21:30:05 +02:00
Fabian Boehm
8ac06f5455 Comment why we need terminfo 0.9.0
This was attempted to relax in #10622, so before some poor packager
tries warn them against it.
2024-08-30 21:27:41 +02:00
Fabian Boehm
983746a697 fish_vi_cursor: Remove terminal checks
We keep having to extend these with new terminals, and I can no longer
find a terminal that fails this.

Even emacs' ansi-term can now at least reliably ignore the sequence.
2024-08-30 21:28:15 +02:00
Klaus Hipp
1020d830e5 Add delta completions 2024-08-30 21:02:03 +02:00
exploide
cf6391b8d3 completions: improved xxd completions
- the __fish_seen_any_argument function did not work
- the xxd_exclusive_args specification was not correct
- longer old-style options were missing
- technically short options are also old-style options in xxd
- some options were missing
2024-08-30 20:34:04 +02:00
Nihaal Sangha
5f4bc28008 Add xcodes completions 2024-08-30 20:33:01 +02:00
Nihaal Sangha
02da9fa845 Add warp-cli completions 2024-08-30 20:32:40 +02:00
Nihaal Sangha
695c7a0071 Add OpenTofu completions
This is based on the existing Terraform completions with minimal changes.
2024-08-30 20:32:18 +02:00
EmilyGraceSeville7cf
74a91afa38 feat: add jv completion 2024-08-30 20:28:23 +02:00
Fabian Boehm
848921a391 build: Forbid linking glibc statically again
Static linking against glibc has crashes depending on the name
resolution setup (I think when it needs to dlopen). It is a fundamental glibc
limitation that we cannot fix on our end.

It will crash when doing `echo ~<TAB>`.

This carves out a specific exception for "gnu", i.e. glibc, targets.

Other targets, including musl and other operating systems, continue to
allow static linking.
2024-08-30 18:35:31 +02:00
Mahmoud Al-Qudsi
5278259312 Don't break out of panic handler
The previous control flow logic wasn't sound and would leave the shell in a hung
state when `break` would be encountered.

The behavior is now straightforward, the shell reads until <Enter> or <q> is
pressed, at which point it aborts.
2024-08-28 17:38:05 -05:00
Mahmoud Al-Qudsi
4d0aa2b5dd Fix panic handler
It wasn't actually exiting and would basically block indefinitely after reading
from stdin.
2024-08-28 17:29:56 -05:00
Fabian Boehm
7b7d16da48 Revert libc time_t changes
This was based on a misunderstanding.

On musl, 64-bit time_t on 32-bit architectures was introduced in version 1.2.0,
by introducing new symbols. The old symbols still exist, to allow programs compiled against older versions
to keep running on 1.2.0+, preserving ABI-compatibility. (see musl commit 38143339646a4ccce8afe298c34467767c899f51)

Programs compiled against 1.2.0+ will get the new symbols, and will therefore think time_t is 64-bit.

Unfortunately, rust's libc crate uses its own definition of these types, and does not check for musl version.
Currently, it includes the pre-1.2.0 32-bit type.

That means:

- If you run on a 32-bit system like i686
- ... and compile against a C-library other than libc
- ... and pass it a time_t-containing struct like timespec or stat

... you need to arrange for that library to be built against musl <1.2.0.

Or, as https://github.com/ericonr/rust-time64 says:

> Therefore, for "old" 32-bit targets (riscv32 is supposed to default to time64),
> any Rust code that interacts with C code built on musl after 1.2.0,
> using types based on time_t (arguably, the main ones are struct timespec and struct stat) in their interface,
> will be completely miscompiled.

However, while fish runs on i686 and compiles against pcre2, we do not pass pcre2 a time_t.
Our only uses of time_t are confined to interactions with libc, in which case with musl we would simply use the legacy ABI.

I have compiled an i686 fish against musl to confirm and can find no issue.

This reverts commit 55196ee2a0.
This reverts commit 4992f88966.
This reverts commit 46c8ba2c9f.
This reverts commit 3a9b4149da.
This reverts commit 5f9e9cbe74.
This reverts commit 338579b78c.
This reverts commit d19e5508d7.
This reverts commit b64045dc18.

Closes #10634
2024-08-27 14:28:00 +02:00
Mahmoud Al-Qudsi
46c1f0e338 Add kqueue-based uvar notifier for BSD (#10674)
Add kqueue-based uvar notifier for BSD

Tested under FreeBSD 13.3.

This also works under all versions of macOS, and has some
benefits over the current notifyd choice.

Mutex is used because of the non-mut `notification_fd_became_readable()` `&self`
reference, but contention is not expected.
2024-08-26 17:10:26 -05:00
Nadir Fejzic
28a5bac560 fix: add ghostty to terminals that support vi cursors 2024-08-26 20:18:59 +02:00
Peter Ammon
91ffa8ab48 Revert "Resume repainting command line when colors change"
This reverts commit 313bd558da.

Per discussion in 313bd558da
2024-08-25 18:41:31 -07:00
EmilyGraceSeville7cf
0954ec2596 feat: add yajsv completion 2024-08-24 16:30:52 -07:00
Dezhi Wu
04a4e5c4e7 Add completions for jj
Jujutsu (jj) is a powerful version control system for software projects.

More information can be found at https://github.com/martinvonz/jj
2024-08-24 15:26:18 -07:00
Peter Ammon
313bd558da Resume repainting command line when colors change
This restores a hack to trigger a command line repaint when "$fish_color_*" or
"$fish_pager_color_*" changes. These allow the command line to react immediately
to changes in other sessions or web_config.

This was removed in ff62d172e5 but there does not
appear to be a handler which actually redraws these.

Revert of ff62d172e5
2024-08-24 15:02:14 -07:00
Johannes Altmanninger
5918bca1eb Make "complete -e" prevent completion autoloading
We do the same for functions.

Closes #6716
2024-08-24 08:30:52 +02:00
Mahmoud Al-Qudsi
f3d59abc46 Remove unnecessary reference 2024-08-20 14:48:59 -05:00
Mahmoud Al-Qudsi
6c37103b7c unescape_yaml_fish_2_0: Remove MaybeUninit::assume_init()
The generated assembly is more or less the same and the previously generated
version had been manually verified, but this PR removes the usage of
`MaybeUninit::assume_init()` and replaces it with direct pointer writes.

This should result in no observable change: it continues to pass the functional
tests and benchmarks identically. The safety of the new code has been verified
with Miri.

[0]: https://github.com/mqudsi/fish-yaml-unescape-benchmark
2024-08-20 14:27:59 -05:00
Fabian Boehm
569d3cdfff completions/git: Add rev-list
The basics, by eye-balling the options that are the same as log.

Also fixes a typo: ingnore-missing
2024-08-20 20:55:16 +02:00
Fabian Boehm
c9bc04f274 fish_config: Write an empty prompt if necessary
This clears the right prompt if the new preset doesn't have any.

This was supposed to be fixed but was broken again in
f3b950157d.

Fixes #10675.
2024-08-19 17:03:52 +02:00
triallax
ad674c61dc Improve apk completions for apk 3.x
- -q silenced warnings in apk 2.x but not in in 3.x, so redirect stderr
  to /dev/null to avoid seeing warnings while completing (-q is still
  passed to `apk search` as it strips package versions and releases)
- Drop `-q` from `apk info`, as on apk 3.x it prevents apk info from
  outputting anything at all

I've tested these changes on both Chimera Linux (which uses apk 3.x)
and Alpine Linux (which is still using 2.x).
2024-08-18 12:28:36 +02:00
EmilyGraceSeville7cf
7883de6562 feat: add web-ext completion 2024-08-18 12:28:03 +02:00
Fabian Boehm
a23cfd0aa8 Simplify freedesktop icon completions
Use `path` more and skip the `sort` - this is for completions and
they're sorted internally.
2024-08-18 12:22:39 +02:00
kpbaks
f07e6c6667 Add completions for notify-send 2024-08-18 12:18:26 +02:00
Johannes Altmanninger
31896534a0 Correct iTerm2 version in CSI u workaround
The 3.5.4 release does not include the fix, presumably the next one then.

See #10653
2024-08-17 07:43:18 +02:00
Fabian Boehm
8612d34996 Remove useless osttr->cstr->osstr roundtrip 2024-08-16 15:30:57 +02:00
Fabian Boehm
980ef6f2f1 Extend small stack workaround to netbsd 2024-08-15 18:32:25 +02:00
Fabian Boehm
835f907cd4 docs: Remove broken indents in license
Lots of "WARNING: Block quote ends without a blank line; unexpected
unindent." from sphinx.
2024-08-15 17:48:48 +02:00
Fabian Boehm
a4cc9c6975 Skip cd-without-read tests on NetBSD 2024-08-15 17:38:04 +02:00
Fabian Boehm
2965603e7f Work around eventfd on NetBSD
Revisit if libc gains support
2024-08-15 17:38:02 +02:00
Johannes Altmanninger
e4bcee2727 Revert "Decode arrow keys as sent by urxvt"
This does not work as-is ("CSI a" is shift-up, not up).
I'm not sure if we want to implement these.
It's not a regression so there is no pressure.

This reverts commit 350598cb99.
2024-08-14 15:43:54 +02:00
Johannes Altmanninger
fcf7cd81cf Parse no more than one \e prefix as alt modifier 2024-08-14 15:16:14 +02:00
Johannes Altmanninger
53ea6db72d Show un-decodable inputs as bytes instead of the internal encoding
When the input is invalid UTF8, we re-encode the raw bytes using the private
use area. Let's make sure we convert back before printing.
2024-08-14 15:16:14 +02:00
Johannes Altmanninger
182f8948b8 Remove unused function 2024-08-14 15:16:14 +02:00
Johannes Altmanninger
b8e280add6 Clean up fish_key_reader rendering code 2024-08-14 15:16:14 +02:00
Fabian Boehm
da8fe7e845 docs: Point to functions/type from funced/funcsave
Fixes #10609
2024-08-13 17:44:23 +02:00
Fabian Boehm
357eb3cd32 fish_key_reader: use char_to_symbol for verbose output
byte_to_symbol was broken because it didn't iterate by byte, it
iterated by rust-char, which is a codepoint.

So it failed for everything outside of ascii and, because of a
mistaken bound, ascii chars from 0x21 to 0x2F ("!" to "/" - all the punctuation).

char_to_symbol will print printable codepoints as-is and
others escaped. This is okay - something like `decoded from: +` or
`decoded from: ö` is entirely understandable, there is no need to tell
you that "ö" is \xc3\xb6.

This reverts commit 423e5f6c03.
2024-08-13 16:03:47 +02:00
Fabian Boehm
7fc58ee7f5 help: Show online URL in case showing it locally doesn't work.
See #10668.
2024-08-13 15:46:22 +02:00
Fabian Boehm
0520b56ea9 webconfig: Don't allow exceptions from chromeos workaround
This except clause was too narrow, so it would fail here even on other
systems just because webbrowser.get() returned nothing usable

Now it will fail *later* with "could not locate runnable browser", but
at least it won't say anything about chromeos on non-chromeos systems.
2024-08-13 15:41:44 +02:00
Johannes Altmanninger
423e5f6c03 Fix fish_key_reader --verbose output 2024-08-11 15:16:03 +02:00
Fabian Boehm
e3196446fa Fix crash in ctrl_to_symbol
Array starts at 0, goes up to 27, that's 28 entries... *BUT* we also
need the catch-all entry after, so it's 29.

To be honest there's got to be a better way to write this.
2024-08-11 14:57:04 +02:00
Fabian Boehm
9903eb4c76 Convert ASCII DEL to \x7f
Annoying when you press backspace in fish_key_reader
2024-08-11 14:57:04 +02:00
Fabian Boehm
1f7fdd5d88 Add back docs for fish_key_reader --verbose 2024-08-11 14:57:04 +02:00
hdhoang
7682abb703 Import portable_atomic::AtomicU64 when std does not provide it
Restores support for 32-bit powerpc and mips. Fixes #10415.

Signed-off-by: Hoang Duc Hieu <code@hdhoang.space>
2024-08-11 14:50:39 +02:00
Johannes Altmanninger
ebd23c9f86 Add back fish_key_reader --verbose
See #10663
2024-08-11 14:41:17 +02:00
Johannes Altmanninger
ba3683cfa5 Disable keyboard protocols on WezTerm
WezTerm supports CSI u but unfortunately, typing single quote on a German
keyboard makes WezTerm send what gets decoded as `shift-'`.

This is bad, so disable it until this is fixed.  In future we should maybe
add a runtime option to allow the user to override this decision.

See #10663
2024-08-11 14:12:28 +02:00
Munzir Taha
58cf600747 Create run0.fish
Initial run0 completion which could later be improved.
2024-08-11 11:45:21 +02:00
Colin Woodbury
7f7a9a3e09 Update aura completions 2024-08-11 11:44:57 +02:00
Klaus Hipp
c958ee08a3 Update zed completions 2024-08-11 11:44:07 +02:00
Zapeth
9dd0b60509 Update xbps-install.fish
`-R` or `--repository` require an argument which is in most cases a url, but can also refer to a directory path on the file system
2024-08-11 11:43:29 +02:00
metamuffin
5648c86a08 wg completion 2024-08-11 11:42:45 +02:00
Lzu Tao
a1a293032a Complete commands after timeout 2024-08-11 11:41:17 +02:00
Lzu Tao
ca485768cb Complete gem install --user-install 2024-08-11 11:41:17 +02:00
Johannes Altmanninger
ff476eff2d Read \e prefix for escape sequences as alt modifier
The \e\e\[A style is bad but iTerm and putty (alt-left) use it.

The main motivation for this change is to improve fish_key_reader output.

Part of #10663
2024-08-11 11:31:13 +02:00
Johannes Altmanninger
d32825ba57 Decode formatOtherKeys=0 format (XTerm default) too
Part of #10663
2024-08-11 11:31:13 +02:00
Peter Ammon
2b40c6364e Mark some functions as potentially unused
Fixes warnings on macOS
2024-08-10 17:36:56 -07:00
Johannes Altmanninger
4664a0b52f Limit iTerm2 CSI u workaround to iTerm<=3.5.3
Looks like 3.5.4 will include
9cd0241afd
so the need for the workaround is gone.

See #10653
2024-08-10 08:17:35 +02:00
Dezhi Wu
09b8b94025 Remove unnecessary unsafe block
The `unsafe` is not needed here, as the `select64` is already a safe wrapper
around the `C_select64` function.

Closes #10659
2024-08-10 07:16:04 +02:00
Johannes Altmanninger
09797acf92 make_vendor_tarball: fix deprecated name for vendor Cargo manifest
> /builddir/build/BUILD/fish-3.7.1+2217.gbd5f9babd-build/fish-3.7.1-2217-gbd5f9babd/.cargo/config
> is deprecated in favor of config.toml
2024-08-09 15:07:42 +02:00
Fabian Boehm
bd5f9babd7 __fish_seen_subcommand_from: Fix error when there's no second token
Regression from 2bfa7db7bc

Can be triggered e.g. with `complete -C"history "`.
2024-08-08 21:20:07 +02:00
Johannes Altmanninger
5f9e9cbe74 Replace clock_gettime/futimens with 64-bit wrappers
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
c1fba4663b Replace nanosleep with stdlib wrapper (which is still broken)
As of rust 1.78, the Unix stdlib implementation is affected by the same issue:

    pub fn sleep(dur: Duration) {
        let mut secs = dur.as_secs();
        let mut nsecs = dur.subsec_nanos() as _;

        // If we're awoken with a signal then the return value will be -1 and
        // nanosleep will fill in `ts` with the remaining time.
        unsafe {
            while secs > 0 || nsecs > 0 {
                let mut ts = libc::timespec {
                    tv_sec: cmp::min(libc::time_t::MAX as u64, secs) as libc::time_t,
                    tv_nsec: nsecs,
                };
                secs -= ts.tv_sec as u64;
                let ts_ptr = core::ptr::addr_of_mut!(ts);
                if libc::nanosleep(ts_ptr, ts_ptr) == -1 {
                    assert_eq!(os::errno(), libc::EINTR);
                    secs += ts.tv_sec as u64;
                    nsecs = ts.tv_nsec;
                } else {
                    nsecs = 0;
                }
            }
        }
    }

Note that there is a small behavior change here -- sleep() will continue
after signals; I'm not sure if we want that but it seems harmless?

Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
55196ee2a0 Replace pselect with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
4992f88966 Replace getrusage with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
46c8ba2c9f Replace select with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
3a9b4149da Replace localtime_r with a 64-bit-time_t wrapper
Part of #10634
2024-08-07 13:11:22 +02:00
Johannes Altmanninger
70357c4f6e Add back .clang-format 2024-08-07 13:11:22 +02:00
Johannes Altmanninger
338579b78c Rename fstatat/readdir wrapper to match Linux equivalents 2024-08-07 13:11:22 +02:00
Johannes Altmanninger
d19e5508d7 Remove non-portable use of fstatat
Part of #10634
2024-08-06 14:16:01 +02:00
Johannes Altmanninger
0705446e6e Remove non-portable use of stat
Part of #10634
2024-08-06 14:16:01 +02:00
Johannes Altmanninger
ff47c2c628 Remove non-portable use of fstat
Part of #10634
2024-08-06 14:15:57 +02:00
Johannes Altmanninger
b64045dc18 Remove non-portable use of ino_t
Part of #10634
2024-08-06 14:15:03 +02:00
Johannes Altmanninger
fa4daeee0f Address clippy lint 2024-08-06 14:15:03 +02:00
Johannes Altmanninger
8fbe29ed7b Remove dead code 2024-08-06 14:15:03 +02:00
Johannes Altmanninger
7cfc6297bc Hack to make alt-{left,right} work again in iTerm2
iTerm2 deviates from protocol, so back out c3c832761 (Stop using stack for
kitty progressive enhancement, 2024-08-03) in that case.

Note that we use several ways of detecting iTerm2 (ITERM_PROFILE,
TERM_PROGRAM=iTerm.app, ITERM_SESSION_ID).
LC_TERMINAL seems superior because it works over ssh.

This new one should hopefully go away eventually.
2024-08-06 10:36:36 +02:00
Johannes Altmanninger
5acac84df9 Enable Cirrus CI again for some Linux targets
There are two failures remaining (focal-32bit and jammy-asan):
https://github.com/krobelus/fish-shell/runs/28339746247
2024-08-05 10:41:17 +02:00
Johannes Altmanninger
25724342e1 Cirrus: remove misplaced/redundant only_if 2024-08-05 10:41:17 +02:00
Johannes Altmanninger
4df0adefc8 Update docker files and cirrus config
- Ubuntu focal is the lowest LTS release that we can support with only
  distro packages (e.g. no rustup).
- Remove tsan from Cirrus (it's not working currently, and also not really
  important).
- Remove Centos (it passes tests but I'm not sure it's worth adding; there
  isn't even an official docker image for CentOS Stream).
2024-08-05 10:41:17 +02:00
Johannes Altmanninger
3984725b80 Fix tmux-complete test for old tmux versions
The CentOS Stream image I used provided tmux 2.7 which doesn't know about the
"Delete" alias.
2024-08-05 10:41:17 +02:00
Johannes Altmanninger
f033bccd3c Move fish build dir canonicalization into build.rs, to lower CMake version 2024-08-05 10:41:17 +02:00
Johannes Altmanninger
f71233ae02 Remove a CMake 3.19 construct
CONFIG supports multiple arguments only as of CMake 3.19, see
https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#configuration-expressions

Ubuntu focal ships with 3.16 by default, so enable building with that.
Note that there is also the workaround of installing "cmake-mozilla".
2024-08-05 10:41:17 +02:00
Johannes Altmanninger
615b413335 Mention in changelog that universal notifiers are not yet supported on BSD 2024-08-05 10:41:17 +02:00
Johannes Altmanninger
7c5f0fea1c Add test dependency (tmux) to builds.sr.ht specs 2024-08-05 10:41:17 +02:00
David Adam
8d8a036e20 add some reminders about the many places copyright information is kept 2024-08-04 21:11:21 +08:00
Kaley Main
70d0736b92 Tidy up Cargo.toml to better support packaging
Closes #10622.
2024-08-04 21:03:54 +08:00
Peter Ammon
1c38677db0 Minor cleanup of path_normalize_for_cd 2024-08-03 12:27:05 -07:00
Shaik Azhar Madar
b31b77cf83 Update p4.fish
add `--` for the string match command, so that if the `$line` has any `-`'s in it will be ignored
2024-08-03 10:52:48 -05:00
Johannes Altmanninger
c3c8327610 Stop using stack for kitty progressive enhancement
Today fish pushes/pops kitty progressive enhancements everytime control is
transfered to/from fish. This constitutes a regression relative to 3.7.1:

    $ fish
    $ ssh somehost fish
    (network disconnect, now we missed our chance to pop from the stack)
    $ bash # or some ncurses application etc
    (keyboard shortcuts like ctrl-p are broken)

When invoking bash, we pop one entry off the stack but there is another one.
There seems to be a simple solution: don't use the stack but always reset
the current set of flags.  Do that since I did not find a strong use case
for using the stack[1] (Note that it was recommended by terminal developers
to use the stack, so I might be wrong).

Note that there is still a regression if the outer shell is bash.

[1]: https://github.com/kovidgoyal/kitty/issues/7603#issuecomment-2256949384

Closes #10603
2024-08-03 17:51:48 +02:00
Amos Bird
041a26f647 Update TTY modes for external commands only after successful command
According to the discussion in #2315, we adopt TTY modes for external commands
mainly for "stty".  If our child process crashes (or SSH disconnect), we
might get weird modes. Let's ignore the modes in the failure case.

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Part of #10603
2024-08-03 17:51:48 +02:00
Fabian Boehm
56a4ae17c9 docs: Make output not selectable
We already do this for the prompt
2024-08-03 16:26:34 +02:00
Johannes Altmanninger
e25a1358e6 Work around broken rendering of pasted multibyte chars in non-UTF-8-ish locale
Run

    printf \Xf6 | wl-copy # ö in ISO-8859-1
    LANG=de_DE LC_ALL=$LANG gnome-terminal -- build/fish

and press ctrl-v. The pasted data looks like this:

    $ set data (wl-paste -n 2>/dev/null | string collect -N)
    $ set -S data
    $data: set in local scope, unexported, with 1 elements
    $data[1]: |\Xf6|

we pass $data directly to "commandline -i", which is supposed to insert it
into the commandline verbatim. What's actually inserted is "�".

This is because of all of:
1. We never decode "\Xf6 -> ö" in this scenario. Decoding it -- like we do
   for non-pasted keyboard input -- would fix the issue.
2. We've switched to using Rust's char, which, for better or worse, disallows
   code points that are not valid in Unicode (see b77d1d0e2 (Stop crashing
   on invalid Unicode input, 2024-02-27)). This means that we don't simply
   store \Xf6 as '\u{00f6}'. Instead we use our PUA encoding trick, making it
   \u{f6f6} internally.
3. Finally, b77d1d0e2 renders reserved codepoints (which includes PUA chars)
   using the replacement character � (sic).  This was deemed more
   user-friendly than printing an invalid character (which is probably not
   mapped to a glyph).  Yet it causes problems here: since we think that
   \u{f6f6} is garbage, we try to render the replacement character. Apparently
   that one is not defined(?) in ISO-8859-1; we get "�".

Fix this regression by removing the replacement character feature.

In future we should maybe decode pasted input instead. We could do that
lazily in "commandline -i", or eagerly in "set data (wl-paste ...)".
2024-08-03 11:32:59 +02:00
David Adam
8b028c37e5 Bring licensing information up to date and synchronise across files 2024-08-03 00:14:48 +08:00
Johannes Altmanninger
d21ed0fb22 Disable terminal protocols before expanding wildcards
Commit 29f2da8d1 (Toggle terminal protocols lazily, 2024-05-16) made it so
the wildcard expansion in "echo **" (in a large directory tree) can't be
canceled with ctrl-c.  Fix this by disabling terminal protocols already at
expansion time (not waiting until execution).
2024-07-31 23:37:11 +02:00
Johannes Altmanninger
3be588569d Disable CSI u inside Midnight Commander for now
Using

    SHELL=$(command -v fish) mc

Midnight Commander will spawn a fish child with

    "function fish_prompt;"
    "echo \"$PWD\">&%d; fish_prompt_mc; kill -STOP %%self; end\n",

So fish_prompt will SIGSTOP itself using an uncatchable signal.

On ctrl-o, mc will send SIGCONT to give back control to the shell.
Another ctrl-o will be intercepted by mc to put the shell back to sleep.

Since mc wants to intercept at least ctrl-o -- also while fish is in control
-- we can't use the CSI u encoding until mc either understands that, or uses
a different way of passing control between mc and fish.

Let's disable it for now.

Note that mc still uses %self but we've added a feature flag
to disable that.  So if you use "set fish_features all"
you'll want to add a " no-remove-percent-self". A patch
to make mc use $fish_pid has been submitted upstream at
https://lists.midnight-commander.org/pipermail/mc-devel/2024-July/011226.html.

Closes #10640
2024-07-29 22:38:18 +02:00
Xiretza
fd006e02da Fix cd .. to the root directory
The leading slash always needs to be present, even if there aren't any other
components. This was introduced by the Rust port.
2024-07-29 10:23:29 -07:00
Peter Ammon
3d816174fd Wildcard tree walking to only rely on dev, inode to detect changes
When applying a wildcard, it's important to keep track of the files that have
been visited, to avoid symlink loops. Previously fish used a FileId for the
purpose. However FileId also includes richer information like modification time;
thus if a file is modified during wildcard expansion then fish may believe that
the file is different and visit it twice.

The richer information like modification time is important for atomic file
writes but should be ignored for wildcard expansion; just use the (dev, inode)
pair instead.

This also somewhat reduces our reliance on struct stat, but we still need it for
fstatat which Rust does not expose.
2024-07-28 09:48:24 -07:00
Peter Ammon
89794ccfdb Adopt fstat in screen.rs 2024-07-27 18:58:35 -07:00
Peter Ammon
3dc3aed991 Adopt fstat in file_id_for_fd 2024-07-27 18:58:34 -07:00
Peter Ammon
1332d33025 Introduce fstat() and adopt it in reader
Begin to migrate to Rust "native" Metadata, as part of addressing #10634

This will be structured as a series of small commits to aid bisecting.
2024-07-27 18:49:46 -07:00
Peter Ammon
0651ca0d9b Unify FileId structs
We had two of these! Just use one.
2024-07-27 18:48:51 -07:00
EmilyGraceSeville7cf
4108306e45 feat: Yeoman support 2024-07-25 19:16:12 -07:00
Fabian Boehm
b3ed2f215b __fish_anyeditor: Add missing -- separator
My $EDITOR is set to "emacs" and "-nw", which breaks this
2024-07-23 17:04:23 +02:00
Johannes Altmanninger
c3cf3792f3 Expand tilde after brace expansion
Fixes #10610
2024-07-23 11:47:58 +02:00
Johannes Altmanninger
4e0cb5d3e9 __fish_seen_subcommand_from: don't clobber global variable 2024-07-23 11:47:58 +02:00
Johannes Altmanninger
6feec60a8e completions: don't treat token at cursor as flag 2024-07-23 11:47:58 +02:00
Johannes Altmanninger
a35c3d4d10 competions/clasp: add namespace to helper function 2024-07-23 11:47:58 +02:00
Johannes Altmanninger
82639d274e string-replace.rst: fix trailing whitespace 2024-07-23 11:47:58 +02:00
Peter Ammon
ff72080aac Changelog fix for #10624 2024-07-21 19:20:46 -07:00
Dezhi Wu
7308dbc7ad fish_indent: Prevent overwriting file with identical content
Fixes #10616
2024-07-21 18:57:48 +08:00
Lzu Tao
d9e5c6527f Add description for git log -L 2024-07-20 13:54:21 -07:00
Mahmoud Al-Qudsi
fe63775ec5 string: Also escape new lines with --style=regex
This isn't *required* in the PCRE2 spec but it greatly increases the utility of
escaped regex strings at the commandline.
2024-07-16 17:05:11 -05:00
Mahmoud Al-Qudsi
6020fc497a Patch __fish_seen_argument to support --foo=arg
...when searching for long arguments by name/key.

Closes #10615.
2024-07-14 21:05:52 -05:00
Mahmoud Al-Qudsi
936f7d9b8d Add pexpect test for commandline --showing-suggestion 2024-07-07 22:34:36 -05:00
Mahmoud Al-Qudsi
b93e52079b Document commandine --showing-suggestion 2024-07-07 22:34:36 -05:00
Mahmoud Al-Qudsi
faf3b356f2 Add commandline --showing-suggestion
Returns 0 (true) in case an autosuggestion is currently being displayed.

This was first requested in #5000 then again in #10580 after the existing
workaround for this missing functionality was broken as part of a change to the
overall behavior of `commandline` (for the better).
2024-07-07 22:34:36 -05:00
Mahmoud Al-Qudsi
4730a04f25 Use NonZero types for 1-based line numbers
Since we have a mix of both 0-based and 1-based line numbers in the code base,
we can now distinguish between them by type alone. Also stop using 0 as a
placeholder value for "no line number available" except in explicit helper
functions such as `get_lineno_for_display()`.
2024-07-07 20:58:09 -05:00
Mahmoud Al-Qudsi
92cae9b576 Reduce size of Block to 32 bytes
Using a 32-bit integer to store the line number, as previously discussed.
2024-07-07 20:37:04 -05:00
Peter Ammon
9edd0cf8ee Remove some now unused CMake bits 2024-07-07 16:06:45 -07:00
Peter Ammon
925382dc3e Make make_pkg.sh create fat binaries again on macOS 2024-07-07 14:53:17 -07:00
Peter Ammon
c90862cd3d Remove legacy Mac.cmake 2024-07-07 12:25:47 -07:00
Mahmoud Al-Qudsi
2bfa7db7bc Restructure __fish_seen_subcommand_from
Both are plenty fast enough, but this way the output of fish_trace isn't
completely taken over by the loops (seems fair since fish_trace probably gets
used rather heavily for completions).
2024-07-07 14:07:05 -05:00
Mahmoud Al-Qudsi
11be48fc38 Dramatically speed up npm/yarn completions
These go from a minimum of 5s in release mode to instantaneous. Worst case was
more than 30s when we didn't find enough matches to end early.
2024-07-07 14:05:12 -05:00
Mahmoud Al-Qudsi
a33d12fe53 Silence string match expression 2024-07-07 13:08:42 -05:00
Mahmoud Al-Qudsi
725bcef117 Update clasp completions (#10377)
Commit would not rebase cleanly.
Closes #10377.

Co-Authored-By: EmilyGraceSeville7cf <EmilyGraceSeville7cfg@gmail.com>
2024-07-07 12:21:37 -05:00
Mahmoud Al-Qudsi
f4b01bb638 Fix typo in npm completions: isntall -> install 2024-07-07 11:47:48 -05:00
Henrik Hørlück Berg
75da00df94 Fix short/long delimiter in string {match,replace}
- We use `()` not `[]`, as can be seen in e.g. `string split`
2024-07-06 16:18:14 +02:00
Peter Ammon
96c5139254 Build, codesign, and notarize macOS packages in CI
This adds a new workflow and script to build macOS packages in GitHub CI.
It also adds some documentation for the process.
2024-07-05 17:29:28 -07:00
Peter Ammon
e67ffc1a3b Revert accidentally pushed commits
This reverts commit 81de0ee97b.
This reverts commit b4450f0ee5.
This reverts commit d5a128d342.
This reverts commit 580028816c.
2024-07-04 19:01:11 -07:00
Peter Ammon
81de0ee97b try 1.79 2024-07-04 18:52:21 -07:00
Peter Ammon
b4450f0ee5 more 2024-07-04 18:08:22 -07:00
Peter Ammon
d5a128d342 more 2024-07-04 17:21:54 -07:00
Peter Ammon
580028816c Add a script to automate macOS codesign 2024-07-04 15:35:29 -07:00
Fabian Boehm
70242ce38c reader: Fix external modes again
Missed in the port
2024-07-03 20:39:25 +02:00
Mahmoud Al-Qudsi
8b7597913e Add tests for string match/replace --max-matches 2024-06-30 17:51:50 -05:00
Mahmoud Al-Qudsi
f975e1c9e5 Document string match/replace --max-matches 2024-06-30 17:51:50 -05:00
Mahmoud Al-Qudsi
93f8385448 Add option to speed up string match/replace with --max-matches
I've often needed a way to get the last bit of performance out of unwieldy
completions that involve a lot of string processing (apt completions come to
mind, and I ran into it just now with parsing man pages for kldload
completions).

Since many times we are looking for just one exact string in the haystack, an
easy optimization here is to introduce a way for `string match` or `string
replace` to early exit after a specific number of matches (typically one) have
been found.

Depending on the size of the input, this can be a huge boon. For example,
parsing the description from FreeBSD kernel module man pages with

    zcat /usr/share/man/man4/zfs.4.gz | string match -m1 '.Nd *'

runs 35% faster with -m1 than without, while processing all files under
/usr/share/man/man4/*.4.gz in a loop (so a mix of files ranging from very short
to moderately long) runs about 10% faster overall with -m1.
2024-06-30 17:51:50 -05:00
Peter Ammon
204663f1b8 Minor cleanup of apply_var_assignments
Simplify the function signature and calls sites.
2024-06-30 15:27:49 -07:00
Peter Ammon
b5fd8d697b Minor refactor of completer perform_for_commandline 2024-06-30 13:59:22 -07:00
Peter Ammon
8db7f6d8ba Fix an errant tilde 2024-06-30 13:05:19 -07:00
visrosa
7260774fc3 Update less.fish
Preliminary work.  Might be important to check version if options I added aren't widely available.

Changed some short options to old-style options since they can't be grouped and don't even need spaces before their arguments, such as `less -ooutputfile` which creates `outputfile`.

The -Dxcolor argument is commented out because its arguments follow complex rules I didn't look into in depth
2024-06-30 13:00:19 -07:00
Joe Adams
2ad4454e52 give the two pages of the functions tab individual scrollbars 2024-06-30 12:50:00 -07:00
Nikita Bobko
e03e5e116d fish_vi_key_bindings: add 'ab' and 'ib' vi text object
Part of #1842

The implementation is obviously isn't 100% vi compatible, but works good enough
for major cases

This commit depends on previous commits where jump-{to, till}-matching-bracket
motions were introduces
2024-06-30 11:58:10 -07:00
Nikita Bobko
67e190876a Implement jump-till-matching-bracket input function
Part of #1842

It's like jump-to-matching-bracket, but jumps right before the bracket

I will use it to mimic vi 'ab' and 'ib' text objects in the next commit

Given complicated semantics of jump-till-matching-bracket, an alternative name
could be 'jump-inside-matching-brackets'. But that would make names non-symmetrical.
I'm not sure what is worse.
2024-06-30 11:58:10 -07:00
Nikita Bobko
f8ebe346a9 Implement jump-to-matching-bracket motion and bind % (percent) in vi mode
Part of #1842
2024-06-30 11:58:10 -07:00
Nikita Bobko
c966c19c56 Refactoring. Decompose ReaderData.jump function to two functions
Part of #1842

Split to:
- jump_and_remember_last_jump. What previously was called jump, now called
  jump_and_remember_last_jump
- jump. Only jump, don't remember last jump. Now it's also possible to pass
  vector of targets

The commit is pure refactoring, no functional changes are introduced.
The refactoring is needed for the next commits
2024-06-30 11:58:10 -07:00
Peter Ammon
1cbd18cc30 Tweak the allowed clippy set and fix some 2024-06-30 11:38:15 -07:00
Peter Ammon
90535d5b51 Allow clippy::ptr_arg and fix cases 2024-06-29 18:48:49 -07:00
Peter Ammon
cce2aab371 Rename binary_semaphore_t to BinarySemaphore 2024-06-29 18:07:11 -07:00
Peter Ammon
266852327f Rename fd_readable_set_t to FdReadableSet 2024-06-29 18:06:21 -07:00
Peter Ammon
2d35d3f3c7 Remove yet more dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
6b4dbf3b05 Remove additional dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
1ed256d328 Remove RefCells from ExecutionContext and just make it mut
No more storing these in Parser; big simplification.
2024-06-29 18:03:52 -07:00
Peter Ammon
aa50e4f8c4 Remove some more dead code 2024-06-29 18:03:52 -07:00
Peter Ammon
606b668fff Remove the pointer module
This is now unused.
2024-06-29 18:03:52 -07:00
Peter Ammon
c212ac95e9 Thread a reference to a line counter into parse execution
Simplify Parser by removing the reference to the execution context
2024-06-29 18:03:52 -07:00
Peter Ammon
b00ab4673b Adopt the new line counting machinery in parse_execution 2024-06-29 18:03:52 -07:00
Peter Ammon
300fcfdba7 Factor out line counting
This moves the line counting logic from parse_execution into a new type, in
preparation for further refactoring.
2024-06-29 18:03:52 -07:00
Peter Ammon
ad1ea94405 Remove an Option from the parsed source ref in parse_execution
This was never None.
2024-06-29 18:03:52 -07:00
Peter Ammon
3aa12c1be9 Rename ParseExecutionContext to ExecutionContext 2024-06-29 18:03:52 -07:00
Kendell R
2a0f7e411f don't error if only dependencies or devDependencies are present (#10594) 2024-06-29 18:01:41 -05:00
Mahmoud Al-Qudsi
8f563846e8 Compile in release mode for at least one CI runner (#10591)
When we changed our default from RelWithDebInfo to Debug, we inadvertently ended
up with all CI building and running in Debug mode. Change at least one of them
back to Release to make sure we don't have any optimizations that cause funky
stuff.

I'm changing the Ubuntu CI image because it's hopefully the fastest (since rust
is relatively dog-slow to compile in release mode).
2024-06-27 21:46:18 -05:00
Mahmoud Al-Qudsi
b5f5fa98bf Fix __fish_describe_command integration test under macOS
__fish_apropos is a huge hack under macOS and it seems that it's either broken
or man pages are missing/not indexed under CI. In all cases, hard-code the
results of __fish_describe_command to test the integration machinery
specifically and get the test to pass under macOS CI.
2024-06-27 21:35:06 -05:00
Mahmoud Al-Qudsi
dd7d537d90 Add regression test for command completion descriptions 2024-06-27 20:45:38 -05:00
Mahmoud Al-Qudsi
0adebdfbc4 Fix completely broken __fish_describe_command integration
Command completion descriptions were not being generated from `apropos`. Well,
they were being generated but that was not being correctly used by fish core.

Not sure when this was broken, but there's a possibility it was during the rust
port.

In addition to simply not working, it seems the old code tried to avoid
allocations but String::split_at_mut() allocates a new string (since one
allocation from the global allocator can't be split into two allocations to be
freed separately). Use `String::as_mut_utfstr()` before splitting the &wstr
instead of splitting the &str to actually do this alloc-free.
2024-06-27 20:43:14 -05:00
Mahmoud Al-Qudsi
ee4d578171 completions/env: Fix errant loud string match
This was vexing me for a while because the extraneous output presented as a
valid (but unwanted) completion, i.e. with RUSTC_WRAPPER exported, `env RUSTC_W`
would offer `RUSTC_W=` and `RUSTC_WRAPPER=` as completions (when only the latter
should have been offered up).
2024-06-26 19:10:51 -05:00
Mahmoud Al-Qudsi
f711c874ce Fix broken __fish_bin_dir when running out of build directory
`exec_path` is the path to the `fish` binary itself. This would cause the shell
to try to execute /foo/bar/fish/fish, which would, of course, fail.
2024-06-26 19:01:57 -05:00
Johannes Altmanninger
90150e1729 fish_key_reader: enable terminal protocols again
Fixes 29f2da8d1 (Toggle terminal protocols lazily, 2024-05-16).
2024-06-25 19:55:24 +02:00
Ryan Patterson
2d9f8547e2 Fix completion for port
This blames to a40b019, when @floam made some changes to various completions,
but this one seems to not quite fit the pattern and had a copy/paste error
resulting in using an undeclared variable.

Also disable filename completion on port.
2024-06-25 22:18:53 +08:00
Mahmoud Al-Qudsi
4d7ef1fad8 Speed up kldload descriptions with alternative to __fish_whatis
__kld_whatis is an order of magnitude faster than calling `whatis` by means of
`__fish_whatis`. (It could be even faster if we could somehow tell `string
replace` to return after the first result, since the .Nd line comes at the start
of the file.)

It still takes some ~3.5 to print descriptions for all available klds (864 under
FreeBSD 13), so we still need to decide when it's prudent to do so and when it's
not.
2024-06-24 15:21:06 -05:00
Mahmoud Al-Qudsi
d914f4e991 Fix broken __fish_whatis
This has been broken for a *long* time.
2024-06-24 14:30:37 -05:00
David Adam
2d3bb36b8c GitHub Actions: drop CXXFLAGS as no C++ remains 2024-06-24 18:57:23 +08:00
Peter Ammon
73c46db609 Remove some (hopefully) unnecessary clippy and compiler directives 2024-06-23 17:13:14 -07:00
Peter Ammon
d059bdb877 Bring topic monitor naming in line with Rust conventions 2024-06-23 17:06:20 -07:00
Peter Ammon
6163999ec7 Remove the ParserRef type
No need to pass around Rc any more.
2024-06-23 16:49:11 -07:00
Peter Ammon
4557d9fc09 Remove the notion of principal parser
The "principal" parser is the one and only today; in the future we hope to
have multiple parsers to execute fish script in parallel.

Having a globally accessible "principle" parser is suspicious; now we can
get rid of it.
2024-06-23 16:49:11 -07:00
Peter Ammon
631516398e Remove the notion of the "principal" environment stack
The "principal" environment stack was the one that was associated with the
"principal" parser and would dispatch changes like to TZ, etc.

This was always very suspicious, as a global; now we can remove it.
2024-06-23 16:49:11 -07:00
Peter Ammon
dbf54f49ff Remove principal_parser() from the last of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
fd84dc4cdd Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
2bd3bcf7fc Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
0d7e8c22a6 Remove principal_parser() from yet more of the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
077f439283 Remove uses of EnvStack::principal() in the tests 2024-06-23 16:49:11 -07:00
Peter Ammon
0e96a420d6 Remove a use of EnvStack::principal()
Try to get off of globals.
2024-06-23 16:49:11 -07:00
Peter Ammon
01d45ad755 Clarify a comment about safety in the environment impl
We use an unusual pattern of protecting data via a global lock, but it's safe.
2024-06-23 16:49:11 -07:00
Peter Ammon
0378cb750b Be more explicit about when to dispatch variable changes
This controls e.g. when we react to TZ changes. Rather than having a special
blessed environment stack, simply store it as a property.
2024-06-23 16:49:11 -07:00
Peter Ammon
9ad875cdb7 Enforce that nobody can push/pop from the global environment stack
This is just a precaution.
2024-06-23 16:39:39 -07:00
Peter Ammon
7fcbe5b8ab Thread variables into autoload_names
Stop fetching a global set of variables.
2024-06-23 16:39:39 -07:00
Peter Ammon
d2d2d8cb45 Remove the shared_from_this for Parser
We no longer need this.
2024-06-23 16:39:39 -07:00
ridiculousfish
924d6aac71 Remove another call to current_data()
Continue to get off of globals.
2024-06-23 16:39:39 -07:00
ridiculousfish
dee692759a Split Reader off from ReaderData
Prior to this commit, there was a stack of ReaderDatas, each one has a
reference to a Parser (same Parser in each, for now). However, the current
ReaderData is globally accessible. Because it holds a Parser, effectively
anything can run fish script; this also prevents us from making the Parser
&mut.

Split these up. Create ReaderData, which holds the data portion of the
reader machinery, and then create Reader which holds a ReaderData and a
Parser. Now `reader_current_data()` can only return the data itself; it
cannot execute fish script.

This results in some other nice simplifications.
2024-06-23 16:39:39 -07:00
ridiculousfish
dfd948fcb5 Eliminate a call to reader_current_data
Try to get off of these globals.
2024-06-23 16:39:39 -07:00
ridiculousfish
c297df38c7 Migrate the Inputter type to a trait
This is a start on untangling input. Prior to this, a ReaderData and an
Inputter would communicate with each other; this is natural in C++ but
difficult in Rust because the Reader would own an Inputter and therefore
the Inputter could not easily reference the Reader. This was previously
"resolved" via unsafe code.

Fix this by collapsing Inputter into Reader. Now they're the same object!
Migrate Inputter's logic into a trait, so we get some modularity, and then
directly implement the remaining input methods on ReaderData.
2024-06-23 16:39:39 -07:00
ridiculousfish
c9a76bd634 Make OperationContext not hold a Parser via Rc
Exploit Rust's lifetimes. This will lead to simplifications.
2024-06-23 16:39:39 -07:00
ridiculousfish
d36f94d96c Remove additional call to Parser::shared() 2024-06-23 16:39:39 -07:00
ridiculousfish
832ed31687 Start removing calls to Parser::shared()
Parser::shared() gets an Rc to a Parser, but we can do without it.
Let's aim to get rid of the cyclic ref.
2024-06-23 16:39:39 -07:00
Mahmoud Al-Qudsi
245ee466cb completions/magento: remove sed dependency
This runs in about half the time, too.
2024-06-23 18:08:34 -05:00
Jean-Bernard Valentaten
3c74f14569 completions/magento: Fixes module aggregation for module related commands (#10446)
* completions/magento: Fixes module aggregation for module related commmands

Previousely when attempting completion for commands `module:enable`,
`mmodule:disable` and `module:uninstall` and error would be disaplyed,
stating that "magento" was not found.
Upon inspection of the issue in the related completion script it became
clear that:
1. The shell command `magento` does not exist as the CLI script of
   Magentoresides under `bin/magento`.
2. The module aggregation would not work after referncing the
   appropriate CLI command as an undeclared variable was being
   introspected.
3. Using Magento's CLI command took too long to respond as it has to
   bootstrap the whole Magento stack in order to deliver modules.

Thus the whole aggregation was rewritten to a form that actually works
and reduces the aggregation to reading the appropriate information
directly from the configuration file, provided that the file exists and
PHP is installed.

* completions/magento: Refactors module aggregation for module related commmands to not use PHP script

Executing random scripts from fish completion poses a threat to the
system. While this would indicate that the Magento installation has been
corrupted, it still is better to not run `app/etc/config.php` to get
hold of the modules.
Thus the module aggregation was rewritten to make use of `sed` instead,
which has the additional benefit of being faster than using PHP.
2024-06-23 18:05:52 -05:00
Mahmoud Al-Qudsi
2f46186f2b Fix formatting 2024-06-23 18:01:31 -05:00
Mahmoud Al-Qudsi
1a18d06a57 math: Fix copy-and-paste error in error message 2024-06-23 17:53:49 -05:00
Mahmoud Al-Qudsi
1a7a7a5dcb math: Support abbreviated scale modes 2024-06-23 17:52:14 -05:00
Mahmoud Al-Qudsi
80c02400eb Fix hard-coded decimal separator in builtin math 2024-06-23 17:50:02 -05:00
Mahmoud Al-Qudsi
c0028a0ec9 math: Rename ZeroScaleMode
It's no longer only for the zero scale.
2024-06-23 17:47:21 -05:00
Looouiiis
480d48351c feat(math): add round options (#9117)
Add round options, but I think can also add floor, ceiling, etc. And
the default mode is trunc.

Closes #9117

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-06-23 17:45:52 -05:00
Mahmoud Al-Qudsi
f1ae170155 printf: Ignore some floating point tests under i586
A few specific tests fail under i586 due to its inherent floating point
inaccuracy issues (rust-lang/rust#114479), so ignore these tests if certain
are met.

We have specific integration tests elsewhere in fish to check that even under
i586 we get mostly sane results, so this is OK. I tried to modify the assert
macros to check for a loose string match (up to one character difference) or an
f64 abs diff of less than epsilon, but it was a lot of code with little value
and increased the friction to contributing to the tests. Also, let's just
acknowledge the fact that all of i686, let alone i586 specifically, is a dead
end and not worth investing such time and effort into so long as it more or less
"works".

Closes #10474.
2024-06-23 16:14:02 -05:00
Mahmoud Al-Qudsi
7d1942a023 Add reduced-accuracy variants of some math tests under x86
Due to the inherent floating point accuracy issues under i586 described
in #10474 and at https://github.com/rust-lang/rust/issues/114479, we need to add
a workaround to our littlecheck math tests to perform less stringent comparisons
when fish was built for x86 without SSE2 support.

This commit addresses the littlecheck issues that caused #10474 to be re-opened,
but I still have to reproduce the cargo test failures for
`negative_precision_width`, `test_float`, `test_float_g`, and `test_locale`.
2024-06-23 16:14:02 -05:00
Lzu Tao
e0266067c4 git: completion for git commit --edit 2024-06-22 20:00:31 +00:00
Fabian Boehm
d917b89009 docs: Fix two links 2024-06-22 14:58:07 +02:00
Mahmoud Al-Qudsi
59daa5abce Run 32-bit CI tests as i586 (#10578) 2024-06-21 12:45:54 -05:00
Mahmoud Al-Qudsi
298cdb0c5b Always pass --target to cargo test when CMake Rust_CARGO_TARGET is set
The CMake `cargo test` integration was broken if Rust_CARGO_TARGET were used
with `CARGO_FLAGS` set to `-Zbuild-std` (e.g. to target i586 under i686 without
the i586 toolchain installed).
2024-06-21 12:00:10 -05:00
Florian Meißner
14fd7bd9af Explain function --argument-names in more detail. (#10524) 2024-06-19 22:51:47 -05:00
Mahmoud Al-Qudsi
32a5be52e1 Add note about non-ASCII decimal_sep length 2024-06-19 18:50:24 -05:00
Mahmoud Al-Qudsi
28a3ae7a8b Remove Clone bound on parse_dec_float()
It's not necessary to clone the character iterator at all.
Also move rarely used inf/nan parsing to own cold function.
2024-06-19 18:43:53 -05:00
Peter Ammon
373cef08cc Fix a clippy in ulimit 2024-06-19 10:47:46 -07:00
Schlomo Schapiro
b3a16e0993 Show only writeable volumes
to exclude system volume
2024-06-19 09:17:14 -07:00
Schlomo Schapiro
f0c8f7406c Extend diskutil eject to suggest volumes
Extend `diskutil eject` completion to also suggest mounted volumes.

Fixes #10573
2024-06-19 09:17:14 -07:00
Manuel Krebs
27c7578760 Add completions for dust 2024-06-19 02:10:52 +02:00
David Adam
e95fc104ec CHANGELOG #830 2024-06-17 06:36:38 +08:00
Peter Ammon
5cc9e0187e Suppress an annoying warning about non-camel-case types 2024-06-16 11:49:09 -07:00
Peter Ammon
376bdb16c7 Fix a misspeeled comment 2024-06-15 16:20:15 -07:00
Peter Ammon
5a45b189da Make EnvStackSetResult use Rust naming conventions 2024-06-15 15:57:28 -07:00
Peter Ammon
0c20ccc72d Fix an annoying warning about camel case types 2024-06-15 13:46:45 -07:00
Peter Ammon
4d300b7f32 Correct fish_default_key_bindings docs
These referred to vi key bindings, not emacs.

Credit to chapeupreto for spotting this in #10569.
2024-06-15 12:18:37 -07:00
Peter Ammon
aa83e155f5 Correct changelog for #10394 2024-06-15 12:16:55 -07:00
Lzu Tao
d370adf5fe git: allow path completion after git reset -- 2024-06-15 11:59:24 -07:00
Peter Ammon
61a90deb8f Changelog fix to #10394 2024-06-15 11:50:35 -07:00
iselda aiello
bac222e001 Move cursor back one space when deleting in vi visual mode
Fixes #10394
2024-06-15 11:44:32 -07:00
Trishank Karthik Kuppusamy
261274ea26 docs/tutorial: Add a note about universal variables (#10548)
Link to some best practices for universal variables.
2024-06-13 18:28:22 +02:00
Fabian Boehm
616ca83799 Cirrus: Increase clone depth
This would fail the FreeBSD tests whenever we merge or push multiple
times in quick succession.

Basically:

- Commits up to ABCDEF are pushed, which triggers a CI run
- Cirrus starts up, but takes a while - it knows to use commit ABCDEF
- More commits are pushed up to 123456
- Cirrus does a shallow clone, only has 123456
- Cirrus tries to check out ABCDEF, but doesn't know it - instant failure

Instead, let's use 100 commits, which should be enough
2024-06-12 17:28:23 +02:00
David Adam
3a9dc12a31 fish.spec: drop C++ requirement 2024-06-12 14:14:52 +08:00
Fabian Boehm
61bf839991 Update README 2024-06-12 08:11:16 +02:00
Fabian Boehm
84b5701b92 Port fish_test_helper to C
This is the last piece of C++, so now we can remove the need for a C++
compiler.

We need one for C anyway (libc.c).

Fixes #10549
2024-06-12 08:11:16 +02:00
Shun Sakai
525a39b42c Add completions for actionlint 2024-06-12 08:10:57 +02:00
Mark Huang
1d8b10399a apt list completions 2024-06-12 08:10:38 +02:00
Fabian Boehm
04da7043a6 tests: Remove skipped tests hack for Cmake < 3.9.0
We require 3.19

This also makes skipped tests visible, which showed that the
print-help test was never run because the REQUIRES line was off.

In sh-mode, bash's `command -v` returns true if *all* commands exist.
2024-06-11 16:55:11 +02:00
Fabian Boehm
32d23a37cb format 2024-06-10 17:16:19 +02:00
Fabian Boehm
652996124d reader: Remove a panic
The special input functions self-insert, self-insert-not-first, and
and or used to be handled by inputter_t::readch, but they aren't
anymore with `commandline -f`.

I am unsure if these *would* have worked, I can't come up with a use.

So, for now, do nothing instead of panicking.
2024-06-10 17:14:13 +02:00
Fabian Boehm
c7d878a8d2 input: Let function_pop_arg return an Option
This would crash if you ran `commandline -f backward-jump`.

The C++ version would read a char (but badly), this doesn't anymore.

So, at least instead of crashing, just do nothing.
2024-06-10 17:02:11 +02:00
David Adam
19d92a9476 make_vendor_tarball: stop trying to excise winapi
errno no longer depends on winapi, and nothing else does either. Stop
trying to remove it.
2024-06-10 22:13:27 +08:00
ridiculousfish
20e9c9493c Rewrite float parsing to use Rust native parsing
Eliminates the fast-float dependency.
2024-06-09 15:52:13 -07:00
ridiculousfish
838ff86ae7 Rename printf crate to fish-printf
Preparing to publish to crates.io
2024-06-09 12:29:09 -07:00
ridiculousfish
56ea456ca3 Add description and license to printf Cargo.toml 2024-06-09 12:20:05 -07:00
ridiculousfish
02532f8bb8 Mark that our printf is licensed under MIT 2024-06-09 12:15:04 -07:00
Fabian Boehm
251ddd1bcc Revert "builtins/path: Use fancy bitflags feature"
This builds on my machine, but doesn't on CI.

Rust 1.67 possibly needs to derive Eq as well as PartialEq?

This reverts commit 2fa0f13db2.
2024-06-08 09:12:56 +02:00
Fabian Boehm
2fa0f13db2 builtins/path: Use fancy bitflags feature
Just a cleanup TODO, no functional changes intended
2024-06-07 21:49:49 +02:00
Fabian Boehm
ab0fdd1918 Remove unescape_string_in_place
Only used in two places and did not do anything sensible
2024-06-06 17:11:25 +02:00
Fabian Boehm
364c53c5e5 CHANGELOG 2024-06-06 16:50:13 +02:00
Fabian Boehm
d317e3638c Update the other dependencies 2024-06-06 16:47:52 +02:00
Fabian Boehm
ad73dcc308 Update nix to 0.29 2024-06-06 16:47:52 +02:00
Fabian Boehm
f59cdfaa8d fish_add_path: Be more informative in verbose mode
One issue with fish_add_path at the moment is that it is sometimes a bit too intransparent.

You'll try to add a path, but it won't appear - was that because it wasn't a directory,
or because it doesn't exist, or because it was already included?

If it isn't usable after, did fish_add_path not add it because of something or did something *else* remove it?

So we give more explanations - "skipping this because it's a file", "not setting anything because no paths are left to add", ...
2024-06-06 16:47:39 +02:00
Fabian Boehm
6706b15fbc fish_add_path: Automatically enable verbose mode for interactive use
fish_add_path can be used either interactively, in the commandline,
or in config.fish. That's its greatest strength, it's a very
DWIM-style command.

One of the compromises that entails, however, is that it can't really
be very loud about what it does. If it skips a path, it can't write a
warning because it might be used in config.fish.

But it *can* if it's used interactively. So we try to detect that case
and enable verbose mode automatically.

That means if you do

```fish
fish_add_path /opt/mytool/bin/mytool
```

it may tell you "Skipping path because it is a file instead of a
directory:".

The check isn't perfect, it goes through status current-command and
isatty, but it should be good for most cases (and be false in config.fish).
2024-06-06 16:47:39 +02:00
Fabian Boehm
3411b72a6d Curses: Update the comments 2024-06-04 22:23:46 +02:00
Fabian Boehm
90bd8cc02b Remove errant .rs2 file 2024-06-04 21:55:43 +02:00
tesuji
01e958d2fb git: add completion for sparse-checkout subcommand (#10542) 2024-06-02 22:02:06 -05:00
Mahmoud Al-Qudsi
9f0e034fad Fix curl data string from path completions
Closes #10539.
2024-06-02 21:58:54 -05:00
Mahmoud Al-Qudsi
d90d924c8c Remove parser library_data_pod_t ffi workaround
We don't need to separate POD fields from the main parser libdata any more.
2024-06-02 20:27:44 -05:00
ridiculousfish
abf92fcbd1 Fix the bind.py tests
Errant newlines were causing extra prompts.
2024-06-02 15:47:15 -07:00
ridiculousfish
c0766c1844 Fix the histfile.py test
Add missing expect_prompt()
2024-06-02 15:31:19 -07:00
ridiculousfish
cb62ed3e3d Bravely reenable fg.py in CI for Mac 2024-06-02 15:11:51 -07:00
ridiculousfish
96faad247f Fix the fg.py pexpect test 2024-06-02 15:07:23 -07:00
ridiculousfish
25ac5bdb49 Fix the undo pexpect
Add the missing expect_prompts to reflect where we send newlines.
2024-06-02 14:17:36 -07:00
ridiculousfish
15c0313c33 Fix pexpect_helper.py prompt regex
The prompt regex for pexpect was:

```
    return re.compile(
        r"""(?:\r\n?|^)   # beginning of line
            (?:\x1b[\d[KB(m]*)* # optional colors
            (?:\x1b[\?2004h) # Bracketed paste
            (?:\x1b[>4;1m) # XTerm's modifyOtherKeys
            (?:\x1b[>5u) # CSI u with kitty progressive enhancement
            (?:\x1b=) # set application keypad mode, so the keypad keys send unique codes
            (?:\[.\]\ )?  # optional vi mode prompt
         """
        + (r"prompt\ %d>" % counter)  # prompt with counter
        + r"""
            (?:\x1b[\d\[KB(m]*)* # optional colors
        """,
        re.VERBOSE,
    )
```

This has a terrible bug: an accidentally unescaped bracket here:

    (?:\x1b[>4;1m) # XTerm's modifyOtherKeys
           ^

This bracket then extends throughout the entire regex, and is
accidentally terminated here:

    (?:\x1b[\d\[KB(m]*)* # optional colors
                    ^

Thus the whole regex is busted; in particular the prompt counters are
not being tested correctly.

A second issue is that these escape sequences are not emitted before the
first prompt, so correcting the regex will cause every test to fail.

Fix this by ignoring all of the escape sequences and merely look for
the "prompt %d>" portion.

THIS DELIBERATELY CAUSES TEST FAILURES.

The tests were already broken and falsely reported as passing.
These will be fixed in followup commits.

Good news is that the tests should become way more reliable after
this is fixed - hopefully no more introducing random sleep() calls.
2024-06-02 14:07:35 -07:00
Fabian Boehm
28484e2498 CHANGELOG: Fix issue mention 2024-06-02 10:52:11 +02:00
Fabian Boehm
94644e88fb Revert "Reduce size of Block to 32 bytes"
This doesn't pull its weight. Block size is not a particularly big
problem,
and this both complicates the code a bit and would arbitrarily cause issues
if a fish script exceeded 65k lines.

This reverts commit edd6533a14.
2024-06-02 10:44:15 +02:00
Mahmoud Al-Qudsi
ac40807309 Reduce explicit Block state
This doesn't have any effect on the size of the struct (due to alignment
requirements and padding) but reduces the complexity by turning
Block::wants_pop_env into an emergent property dependent on the type rather than
something we have to manually manage.
2024-06-01 13:16:24 -05:00
Mahmoud Al-Qudsi
2e52d51af2 Convert Block::event_blocks to a bool
We only increment it and check if it's non-zero, we never decrement or check the
actual count. As such, change it to a bool and bring the size of `Block` down
from 32 to 24 bytes.
2024-06-01 13:01:40 -05:00
Mahmoud Al-Qudsi
edd6533a14 Reduce size of Block to 32 bytes
We don't need 16 bytes (plus the `Option` overhead) to store the line number!
2024-06-01 12:49:15 -05:00
Mahmoud Al-Qudsi
5ca76564a4 Store BlockData in a Box
We almost never access any of this and having it stored directly in the `Block`
struct increases its size (reducing how many we can fit in L1 and L2, and
increasing memory copy traffic).

Gets rid of BlockData::None so we can avoid allocating a Box at all when we have
no data (at the cost of yet-another-wrapper-type), which is the usual case.
2024-06-01 11:41:32 -05:00
Mahmoud Al-Qudsi
1d159277c6 Move Block fields specific to certain block types to separate enum
This has a few advantages,
* We now statically assert that all fields used by a particular block type are
  correctly initialized (i.e. you can't assign the function name but forget to
  assign its arguments),
* Conversely, we can match directly on `BlockData` and be guaranteed that the
  fields we want to access are initialized and present,
* We reduce the number of assertions, effectively "unwrapping" only once based
  off the block type instead of each time we try to access a conditional field,
* We reduce the size of the `Block` struct by coalescing fields that cannot
  co-exist, bringing it down from 104 bytes to 88 bytes.

It would be nice to make all of `Block` itself an enum, but it currently
requires `Copy` and we take advantage of that to copy it around everywhere.
Putting these fields directly in `Block` directly would mean a lot more memory
traffic just checking block types.
2024-06-01 11:15:19 -05:00
Mahmoud Al-Qudsi
0246c938ca Coalesce BlockType::function_call and BlockType::function_call_no_shadow
There's no need for two separate block types when one is merely a variant of the
other. This may have been required under C++ but thanks to sum types (rust's
enums) we don't need to do that any more.
2024-05-31 20:53:52 -05:00
Mahmoud Al-Qudsi
fc9a743622 completions/env: overhaul completions
The value completions were rendered almost entirely useless due to the forced
inclusion of file completions at all tokens, including in the head/command
position thanks to the use of `__fish_complete_subcommand` which doesn't
understand the semantics of `env` and expects something like `ssh`. But we don't
need it at all.
2024-05-31 20:49:48 -05:00
Mahmoud Al-Qudsi
6ec09260dd Changelog: document #5263 and provide workaround
[ci skip]
2024-05-31 16:21:24 -05:00
Mahmoud Al-Qudsi
417e89a4b3 Work around WSLv1 not properly cleaning up stopped orphaned jobs
See #5263.
2024-05-30 21:31:04 -05:00
Mahmoud Al-Qudsi
6c944debec Send signals in the correct order in hup_jobs()
If the backgrounded/stopped job was using the tty, sending it SIGCONT first
might cause it to immediately wake and try to use the tty (which fish still has
control over), causing it to immediately stop again after receiving a SIGTTOU.

We are supposed to send SIGHUP first so that when the process resumes it sees
the queued SIGHUP and executes its registered handler!
2024-05-30 18:26:13 -05:00
Mahmoud Al-Qudsi
e1ee193822 Speed up __fish_make_cache_dir
Don't fork/exec an external process, especially one performing IO, if we don't
have to.

This, in turn, speeds up __fish_source_cached_completions which is rather slow
under WSL (and slower than it needs to be on other platforms).
2024-05-30 17:03:03 -05:00
Mahmoud Al-Qudsi
98642d307a Don't use a graphical browser under SSH
...unless X is also being forwarded.

Someone else will have to figure out the Wayland equivalent (if that even
exists). Not my monkey, not my circus.
2024-05-30 16:15:07 -05:00
Mahmoud Al-Qudsi
7d77d7aa84 Convert more block iteration methods to use iterators 2024-05-30 15:54:54 -05:00
Fabian Boehm
0a8fd05bb0 docs/fish_add_path: Reword description
Use "directories" explicitly instead of "components" to make it more
clear that the arguments need to be directories, not files.

Also a bit on intent and variable scope.
2024-05-30 22:52:03 +02:00
Mahmoud Al-Qudsi
f6200224fc Use Iterator::count() to check function stack depth 2024-05-30 12:49:28 -05:00
Mahmoud Al-Qudsi
b495cffa50 fixup! Add workaround for targets with too small a main stack size 2024-05-30 12:25:06 -05:00
Mahmoud Al-Qudsi
a3e0d64e88 Remove usage of env -u
`env -u` is not supported on all platforms we support (e.g. macOS/OS X 10.10).
We don't need these variables erased, blanked works just fine.
2024-05-30 12:14:43 -05:00
Mahmoud Al-Qudsi
4b840075f4 Patch cd.fish test to support older macOS versions
The sysctl kern.osproductversion is not available on the oldest versions
we support.
2024-05-30 12:14:43 -05:00
Mahmoud Al-Qudsi
57f558578b Add workaround for targets with too small a main stack size
pthread_get_stacksize_np() is buggy on legacy OS X; make sure you are building
fish with a rust toolchain that correctly patches these functions.

See https://github.com/macports/macports-legacy-support/pull/86
2024-05-30 12:14:37 -05:00
Mahmoud Al-Qudsi
46f6aa8024 Update ssh-keygen completions
Don't run `ssh` upon sourcing and don't rely on `ssh -Q` being available.
2024-05-29 14:08:21 -05:00
Mahmoud Al-Qudsi
828b88a212 Add issue reference to flatpak completion workaround
[ci skip]
2024-05-29 13:54:39 -05:00
Mahmoud Al-Qudsi
7bf3b57e47 Fix buggy test_pthread() condvar test
There's no guarantee that a condition variable is stateful. The docs for
`Condvar::notify_one()` actually say the opposite:

> If there is a blocked thread on this condition variable, then it will be woken
> up from its call to wait or wait_timeout. Calls to notify_one are not buffered
> in any way.

This test was relying on the main loop obtaining the lock and entering the
condition variable sleep before the thread was scheduled and got around to
notifying the condition variable. If this non-deterministic behavior was not
upheld, the test would time out since it would obtain the lock (either before or
after the variable were updated) then call `condvar.wait()` *after* the variable
had been updated and the condvar signalled, but without (atomically or even at
all) checking to see if the desired wake precondition was fulfilled. As the
child thread had already run and the wake notification was NOT buffered, there
was nothing to wake the running thread.

There really wasn't any way to salvage the test as originally written, since the
write to `ctx.val` was not in any way linked to the acquire/release of the mutex
so regardless of whether or not the main thread obtained the mutex and checked
the value precondition before calling `condvar.wait()`, the child thread's write
could have happened after the check but before the wait() call. As such, the
test has been rewritten to use `wait_while()` but then also updated to bail in
case of a timeout instead of hanging indefinitely (since neither the `ctest`
runner nor the `cargo test` harness was timing out; `cargo test` would only
report that the test had exceeded 60 seconds but as long as it was not executed
with `cargo test -- -Z --ensure-time` (which is only available under nightly),
the test would not halt.

If this test were *intentionally* written to test the scenario that was timing
out, it should be written deterministically in such a way that the main loop
did not run until after it was guaranteed that the variable had been updated
(i.e. by looping until val became 5 or waiting for an AtomicBool indicating the
update had completed to be set), but I'm not sure what the benefit in that would
be since the docs actually guarantee the opposite behavior (the notified state
is explicitly not cached/buffered).

If we have fish code written with the assumption that condvar notifications
prior to *any* call to `Condvar::wait()` *are* buffered, then that code should
of course be revisited in light of this.
2024-05-29 13:13:13 -05:00
Johannes Altmanninger
390b40e02b Fix regression not refreshing TTY timestamps after external command from binding
Commit 8a7c3ce (Don't abandon line after writing control sequences, 2024-04-06)
was broken by 29f2da8 (Toggle terminal protocols lazily, 2024-05-16), fix that.

Fixes #10529
2024-05-29 12:57:09 +02:00
Mahmoud Al-Qudsi
8c364dc949 CHANGELOG: Fix awkwardly formatted issue reference
The :issue:`xxxx` template generates text in the format (#xxxx), so this was
rendering as "... See (#xxxx)." which is just weird.

[ci skip]
2024-05-28 11:53:36 -05:00
Mahmoud Al-Qudsi
5b7fd61867 Fix single-backtick-quoted code expressions in CHANGELOG.rst
Reminder that reStructuredText is awkward and you can't make sphinx treat these
as inline code; they'll be formatted as italic text only.

Vim search expression:
    \([`:]\)\@<!`[^`:]\+`\(`\)\@!

Followed by
    ysi``

does the trick quite nicely.
2024-05-28 11:47:45 -05:00
Mahmoud Al-Qudsi
8b1c8ed791 CHANGELOG: Add #10506 and #10521 2024-05-28 11:09:09 -05:00
Yuntao Zhao
96416cc49e feat: improve completion for konsole (#10528)
* feat: improve konsole completion

* Improve konsole profile completion to be dynamic

Directly complete --profile as a long argument

* Dynamically complete konsole -p
2024-05-28 10:26:03 -05:00
Fabian Boehm
f06143c11a docs: Fix some formatting 2024-05-27 23:21:06 +02:00
ridiculousfish
29b620b56c Remove an unused type 2024-05-27 11:45:25 -07:00
ridiculousfish
9e406e4fbc Silence some clippies 2024-05-27 11:07:02 -07:00
Mahmoud Al-Qudsi
6117b5071c Don't ignore assert_sorted_by_name doctest 2024-05-27 10:20:24 -05:00
Fabian Boehm
7850142bef printf/tests: Use c_char instead of i8
Breaks on arm again
2024-05-27 12:47:51 +02:00
Nguyen Huu Kim
8880fa8dd7 feat: add completions for k8s tools (kustomize, flux) (#10473)
* feat: add completions for kustomize

* feat: add completions for FluxCD

* Update flux.fish

* Update kustomize.fish

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-05-26 22:12:49 -05:00
Mahmoud Al-Qudsi
f84b1993ec Add path basename -E tests 2024-05-26 22:06:11 -05:00
Mahmoud Al-Qudsi
6091d1149f Document path basename -E 2024-05-26 22:06:11 -05:00
Mahmoud Al-Qudsi
286fa4bf5b Add path basename --no-extension
This makes `path basename` a more useful replacement for the stock `basename`
command, which can be used with `-s .ext` to trim `.ext` from the base name.

Previously, this would have required the equivalent of

    path change-extension "" (path basename $path)

but now it can be just

    path basename -E $path
2024-05-26 22:06:11 -05:00
Mahmoud Al-Qudsi
dbf6dfd5d2 completions/flatpak: dynamically complete flatpak install 2024-05-26 22:03:27 -05:00
Mahmoud Al-Qudsi
4868166f86 completions/rustc: preserve trailing = in -Z values 2024-05-26 21:44:02 -05:00
Mahmoud Al-Qudsi
84d057e7b7 Finish refactoring rustc completions
* Properly handle a lot more -Z completion formats as suggested by `rustc -Z
  help`
* Don't run any `rustc` commands when sourcing `rustc.fish`; these invocations
  are instead deferred until the user attempts to complete the specific switch.
* Support CSV -A/F/D/W values
2024-05-26 21:33:48 -05:00
Mahmoud Al-Qudsi
9045b251b0 Fix missing -- filter in string replace call 2024-05-26 21:33:48 -05:00
tesuji
114856e1d9 git: add --reuse-message and --reedit-message completion (#10530) 2024-05-26 20:57:43 -05:00
ridiculousfish
94f13a50f5 Add musl libc to our license.rst
The new printf is derived from musl libc. Add it to license.rst to reflect our
usage.
2024-05-26 16:07:27 -04:00
ridiculousfish
f16a1361c5 Adopt the new printf crate
This drops our usage of printf-compat.
2024-05-26 16:07:27 -04:00
ridiculousfish
585dac6b08 Use cargo test --workspace
Allows running printf tests.
2024-05-26 16:07:27 -04:00
ridiculousfish
7002571cf8 Add printf crate to workspace
This adds a crate containing a new implementation of printf, ported from musl.

This has some advantages:

- locale support is direct instead of being "applied after".
- No dependencies on libc printf. No unsafe code at all.
- No more WideWrite - just uses std::fmt::Write.
- Rounding is handled directly in all cases, instead of relying on Rust and/or
  libc.
- No essential dependency on WString.
- Supports %n.
- Implementation is more likely to be correct since it's based on a widely used
  printf, instead of a low-traffic Rust crate.
- Significantly faster.
2024-05-26 16:07:27 -04:00
Fabian Boehm
b9b7dc5f6c fmt 2024-05-26 10:50:45 +02:00
Fabian Boehm
52d1806e1f Apply some manual clippy lints
Mostly replacing std::<type>::MAX with <type>::MAX.

Surprising here is replacing

.expect(format!(...))

with

.unwrap_or_else(|_| panic!(...))

It explains that this is because the "format!" would always be called.
2024-05-26 10:45:46 +02:00
Fabian Boehm
20830744a9 Apply some clippy lints
Nothing too surprising, mostly removing useless references and lambdas
2024-05-26 10:37:37 +02:00
Fabian Boehm
2c3894993f Remove errant profiling enabling
This enabled the profile in fish_setlocale, which caused startup
profile to always be on, so

```fish
fish --profile file -c 'foo'
```

would show the entire startup as well
2024-05-26 10:32:28 +02:00
ridiculousfish
08f8983085 Adopt the new hex float parsing
This eliminates hexponent.
2024-05-25 18:39:45 -07:00
ridiculousfish
bed2ff2ea6 Add homegrown hex float parsing
Hex float parsing may come about through wcstod, for example:

    printf "%f" '0x8p2'

should output 32.0.

Currently we use a not-great fork of hexponent. Hexponent has been dormant for
years, and has some issues: doesn't round properly, allocates unnecessarily,
doesn't handle denormals, is more complicated than necessary.

Just rewrite hex float parsing, fixing those problems and getting us off of this
weird fork.
2024-05-25 18:31:38 -07:00
Fabian Boehm
1d0f1d2697 fmt 2024-05-25 22:21:52 +02:00
Fabian Boehm
d5101e1923 set: Put back zero-index error instead of crashing
This was missed in the initial port in 77aeb6a2a8.
2024-05-25 21:32:40 +02:00
Fabian Boehm
89ed37d957 CHANGELOG 2024-05-25 13:21:02 +02:00
Fabian Boehm
bf9e5583ba Push and pop for-block every run through the loop
We do the same in while loops. This clears the local variables every time.

Fixes #10525
2024-05-25 13:20:05 +02:00
Mahmoud Al-Qudsi
6921394db2 Remove needless use of dynamic dispatch
We return a plain function, all with matching signatures. No need for dynamic
dispatch here.
2024-05-24 17:30:38 -05:00
Klaus Hipp
cd9f5bdbaa Add jnv completions (#10519) 2024-05-24 17:09:18 -05:00
tesuji
57963ced4b add completions for ssh-keygen (#10508)
* add bare completions for ssh-keygen

* chore: more completions for ssh-keygen
2024-05-24 17:07:32 -05:00
Fabian Boehm
06d842b0d8 completions/csvlens: Fix a typo 2024-05-24 22:40:18 +02:00
Klaus Hipp
843933ce95 Add csvlens completions (#10520) 2024-05-24 15:38:45 -05:00
Mahmoud Al-Qudsi
2c2f7cb4d1 Use our own thread id
ThreadId is way slower than it should be for the sense that we use it in; it
doesn't cache the id and allocates an Arc internally.

We don't care about the thread id used in crate::threads correlating with any
other thread id the code uses anywhere (not that it does) because it's only used
for our own bookkeeping. Change to something much simpler instead.
2024-05-24 13:34:18 -05:00
Mahmoud Al-Qudsi
cf4ab20055 Use OnceLock in crate::threads
Verified that std::sync::OnceLock<T> compiles to the same assembly at the
*access* site as the Option<T> we were using. The additional overhead upon init
is fine. No need for extra Box<T> indirection for IO_THREAD_POOL.
2024-05-24 12:46:47 -05:00
Mahmoud Al-Qudsi
b49e9b906f Wrap an unruly comment 2024-05-24 10:21:07 -05:00
Mahmoud Al-Qudsi
59317da19e Clarify threading semantics of DISOWNED_PIDS
While obtaining an uncontested mutex from the same thread (without reentrance)
is basically ~free, the use of `MainThread<RefCell<T>>` instead of `Mutex<T>`
makes it clear that there is no actual synchronization taking place, hopefully
making the code easier to understand.
2024-05-24 10:20:29 -05:00
Mahmoud Al-Qudsi
43d6289c26 Make assert_is_main_thread() simpler to optimize
The compiler cannot guarantee that a `static AtomicBool` is always the same
initial value, but it can do so for a `const bool`.
2024-05-24 09:57:42 -05:00
Johannes Altmanninger
6cd1323bfe Work on changelog 2024-05-24 15:16:17 +02:00
Johannes Altmanninger
8c073f56c2 Changelog issues from current milestone 2024-05-24 14:01:46 +02:00
Mahmoud Al-Qudsi
537cde0c72 Avoid auto-colorization of ls output if CLICOLOR_FORCE is set
We don't set this variable ourselves, but some might set it in their config out
of habit coming from shells that don't automatically colorize ls output.

This variable overrides stdout tty detection for `ls --color=auto` (but does not
modify the behavior of `ls --color=never` or `ls --color=always` regardless of
its value) under at least the BSD version of `ls`. (Under the GNU version, it
influences colorization only if stdout *is* a tty.)

If we detect CLICOLOR_FORCE *and* we are not writing directly to the tty, we
skip colorization (by clearing-but-not-erasing `$__fish_ls_color_opt`, so that
we don't end up accidentally using its value from another scope).
2024-05-23 20:50:23 -05:00
Shun Sakai
6d8b4214d5 Add completions for reuse-tool (#10511) 2024-05-23 16:53:53 -05:00
Mahmoud Al-Qudsi
d654880bcf Automatically label and milestone completions (#10517)
This automatically assigns the 'completions' label and the 'fish next-3.x'
milestone to completions-only PRs.

A completions-only PR is defined as being one that touches
share/completions/*.fish but does not touch any files outside of share/
2024-05-23 13:34:20 -05:00
Fabian Boehm
5bd1c5ecbf completions/git: Move unmerged to git restore --staged
I still don't get how exactly restore works.

Fixes #10518
2024-05-23 15:08:55 +02:00
Fabian Boehm
00e0d6ad9d Yet more shortening 2024-05-23 14:36:56 +02:00
Johannes Altmanninger
2f84f76cc2 completions/bind: complete ctrl/alt modifier abbreviations 2024-05-22 22:38:06 +02:00
Johannes Altmanninger
de7f39d627 builtin bind: make function keys lowercase (f1 instead of F1)
All other key names are lowercase so this inconsistency is weird.
2024-05-22 22:38:06 +02:00
Mahmoud Al-Qudsi
4869b98482 completions/flatpak.fish: Use terser/faster declarative style 2024-05-22 13:53:25 -05:00
Mahmoud Al-Qudsi
c2ecfe60ac completions/flatpak: Fix compatibility with older versions
Filter out ansi control characters and pretty formatting from older versions
that don't detect the absence of a tty.

Closes #10514.
2024-05-22 13:53:25 -05:00
Michal Koutný
fa0c585662 completions/git: Add git branch --edit-description (#10512)
* completions/git: Add `git branch --edit-description`
2024-05-21 18:56:52 -05:00
Johannes Altmanninger
2fa98ec20c Fix deadlock when importing universal LC_* variable
The C++ version of this code simply copied the entire uvar table.
Today we take a reference. It's not clear which one is better.

Removal of locale variables like LC_ALL triggers variable change handlers
which call EnvStackImpl::get. This deadlocks because we still hold the lock
to protect the reference to all uvars.  Work around this.

Closes #10513
2024-05-21 23:11:06 +02:00
Mahmoud Al-Qudsi
d07d0170ad build.rs: also declare cfgs when we run into a warning
e.g. gettext is found but can't be used
2024-05-21 13:34:24 -05:00
Mahmoud Al-Qudsi
0b5e41b268 Rework path_normalize_for_cd() to be less allocation trigger happy
Lots of resizing, splicing, and full-on allocating going on here.
2024-05-21 12:54:52 -05:00
Mahmoud Al-Qudsi
d14d8d5733 Remove wcstringutil::split_string()
It is short and simple enough to write yourself if you need it and it encourages
bad behavior by a) always returning owned strings, b) always allocating them in
a vector. If/where possible, it is better to a) use &wstr, b) use an iterator.

In rust, it's an anti-pattern to unnecessarily abstract over allocating
operations. Some of the call sites even called split_string(..).into_iter().
2024-05-21 12:54:52 -05:00
Mahmoud Al-Qudsi
96b979077c Add unit tests for path_normalize_for_cd() 2024-05-21 12:54:51 -05:00
Mahmoud Al-Qudsi
8c62f733b3 Extend certain WSL workarounds to WSLv2
This updates is_windows_subsystem_for_linux() to take a WSL version to test for
(any, v1, or v2) and returns the boolean result depending on the system. I've
benchmarked and when running on regular Linux, this is still just as fast as the
previous binary check; it's only when it's WSL that this takes about 20ns
longer to figure out which variant.

Note that older WSLv2 kernels had a `-microsoft-standard` suffix while newer
ones appear to have a `-microsoft-standard-WSL2` suffix, so we make sure to test
for the least common denominator. (It doesn't matter to us, but note that newer
WSLv2 kernels have four dots in the version string!)

WSL workarounds pertaining to the default Windows terminal or executable
behavior of win32 binaries under a WSL shell are extended to WSLv2 while those
specific to oddities in kernel behavior are confined to WSLv1 only. (It
technically wouldn't hurt to extend them to WSLv2 but there's no good reason to
do so, either.)
2024-05-20 14:14:25 -05:00
Mahmoud Al-Qudsi
3374692b91 Work around $PATH issues under WSL (#10506)
A common complaint has been the massive amount of directories Windows appends to
$PATH slowing down fish when it attempts to find a non-existent binary (which it
does a lot more often than someone not in the know might think). The typical
workaround suggested is to trim unneeded entries from $PATH, but this a) has
considerable friction, b) breaks resolution of Windows binaries (you can no
longer use `clip.exe`, `cmd.exe`, etc).

This patch introduces a two-PATH workaround. If the cmd we are executing does
not contain a period (i.e. has no extension) it by definition cannot be a
Windows executable. In this case, we skip searching for it in any of the
auto-mounted, auto-PATH-appended directories like `/mnt/c/Windows/` or
`/mnt/c/Program Files`, but we *do* include those directories if what we're
searching for could be a Windows executable. (For now, instead of hard-coding a
list of known Windows executable extensions like .bat, .cmd, .exe, etc, we just
depend on the presence of an extension at all).

e.g. this is what starting up fish prints with logging enabled (that has been
removed):

    bypassing 100 dirs for lookup of kill
    bypassing 100 dirs for lookup of zoxide
    bypassing 100 dirs for lookup of zoxide
    bypassing 100 dirs for lookup of fd
    not bypassing dirs for lookup of open.exe
    not bypassing dirs for lookup of git.exe

This has resulted in a massive speedup of common fish functions, especially
anywhere we internally use or perform the equivalent of `if command -q foo`.

Note that the `is_windows_subsystem_for_linux()` check will need to be patched to
extend this workaround to WSLv2, but I'll do that separately.

Under WSL:
* Benchmark `external_cmds` improves by 10%
* Benchmark `load_completions` improves by an incredible 77%
2024-05-20 10:29:32 -05:00
Jannik Vieten
bd4e5fe69a completions ip: silence stderr in case -d does not exist (busybox) (#10509) 2024-05-20 07:28:40 -05:00
Peter Yates
56a168d37f Prevent loading of psqlrc when listing databases
Users have the ability to override the way records are displayed in psql by
changing the format[1] and linestyle[2] settings. These settings also affect the
output of psql commands used for autocompletion, like listing databases and
users - so they inadvertantly break Fish's completion.

If we suppress the loading of psqlrc[3] the default settings are used instead.

[1] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-FORMAT
[2] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMAND-PSET-LINESTYLE
[3] https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-OPTION-NO-PSQLRC
2024-05-20 14:04:38 +02:00
ridiculousfish
efefeda392 Restore some iTerm2 default key bindings
c0bcd817ba removed some key bindings, including the bindings of
ESC ESC [ C for Alt-Right. the commit claimed that
"Sequences like \e\eOC are Escape followed by an SS3 arrow key which we
can already decode separately." but for whatever reason this doesn't work:
Alt-Right is broken in iTerm2 by default.

Restore the default ESC ESC [ X bindings for iTerm2 compatibility.
2024-05-19 11:01:14 -07:00
ridiculousfish
42f8672f34 Remove an errant {} from a FLOG 2024-05-19 10:27:45 -07:00
Klaus Hipp
4659fdf704 Add git-lfs completions (#10490) 2024-05-19 09:09:33 -05:00
tesuji
255c8da22d add completions for ibus (#10500) 2024-05-19 09:05:40 -05:00
Jannik Vieten
66d28f5fda completions: improved ip completions (#10505)
- complete routing table names/IDs
- rudimentary completions for ip rule subcommand
2024-05-19 09:00:29 -05:00
Johannes Altmanninger
d40d2b786f Work around wants_terminal not begin set inside eval
On this binding we fail to disable CSI u

    bind c-t '
        begin
            set -lx FZF_DEFAULT_OPTS --height 40% --bind=ctrl-z:ignore
            eval fzf | while read -l r; echo read $r; end
        end
    '

because for "fzf", ParseExecutionContext::setup_group() returns early with the
parent process group (which should be fish's own) , hence "wants_terminal"
is false. This seems questionable, I don't think the eval should make a
difference here.

For now, don't touch it; use the more accurate way of detecting whether
a process may read keyboard input. In many of such cases "wants_terminal"
is false, like

    echo (echo 1\n2\n3 | fzf)

Fixes #10504
2024-05-18 20:55:06 +02:00
Mahmoud Al-Qudsi
ef614ba2d9 Speed up rustc completions, filter out deprecated options
Don't unconditionally execute the plumbing to get `rustc -C` completions (use it
only when trying to complete `rustc -C`), filter out deprecated options, and use
fewer calls to the `string` builtin to optimize further.

Need to do the same thing for the `-Z` completions next, those hang the shell
for a good 1.5+ seconds.
2024-05-18 12:37:18 -05:00
Mahmoud Al-Qudsi
0a7725e469 Add comment re accuracy of cargo --target completions
[ci skip]
2024-05-18 12:00:45 -05:00
Mahmoud Al-Qudsi
cbb399f2ed completions/cargo.fish: Add python fallback for jq 2024-05-17 18:45:19 -05:00
Mahmoud Al-Qudsi
79f7b9f92a completions/cargo.fish: Dynamically generate --features completion 2024-05-17 18:17:53 -05:00
Mahmoud Al-Qudsi
f342ae6a1c Add a completion helper function to generate permutation completions
I've been needing this for some time to generate completions for functions that
we can dynamically generate completions for that take one or more
comma-separated values in any order.
2024-05-17 18:15:41 -05:00
Mahmoud Al-Qudsi
6dbae76b24 Update cargo-asm completions
Try not to let `cargo asm` build a large project and hang the terminal (and make
the fans go crazy) if we try to generate a list of functions/paths and the
project is in a dirty state. Also support dynamic completion of --target.
2024-05-17 17:10:10 -05:00
Mahmoud Al-Qudsi
1d36c6ad8c completions/cargo.fish: Generate dynamic --target options
If rustup is installed, use the existing `__rustup_installed_targets` to get a
list of installed targets to compile for. If it's not, print a list of all
targets known to rustc.

It sucks that the completions file is currently architected in a way where we
have to manually specify the arguments for each subcommand. 🤷
2024-05-17 16:57:40 -05:00
Mahmoud Al-Qudsi
d8e9a17c1f Inline extract_prefix_and_unescape_yaml()
We sometimes call it but discard half its results, so force it to be inlined to
make sure we don't perform work we then throw away.
2024-05-17 16:11:46 -05:00
Mahmoud Al-Qudsi
bcb1e2ed85 Further optimize unescape_yaml_fish_2_0()
This hot function dominates the flamegraphs for the completions thread, and any
optimizations are worthwhile.

A variety of different approaches were tested and benchmarked against real-world
fish-history file inputs and this is the one that won out across all rustc
target-cpu variations tried.

Benchmarks and code at https://github.com/mqudsi/fish-yaml-unescape-benchmark
2024-05-17 16:06:08 -05:00
Mahmoud Al-Qudsi
9ab1ec2a9e Tweak newly added rustc completion descriptions
Addendum to https://github.com/fish-shell/fish-shell/pull/10491
2024-05-17 12:33:59 -05:00
tesuji
d3758d3751 completion: add more arguments for rustc --print (#10491)
Based off of rustc 1.80.0-nightly
2024-05-17 12:32:41 -05:00
Ian Chamberlain
1462da3ae2 Complete cargo check bin targets like build (#10499)
Since `check` operates on basically the same things as `build`, it makes
sense to complete binary targets the same way (i.e. tests, bins, examples)
2024-05-17 12:31:30 -05:00
Mahmoud Al-Qudsi
0271d91d3a Add completions for cargo-asm 2024-05-17 12:31:02 -05:00
David Adam
f4a79cc138 debian packaging: disable LTO build profile
Fixes the build on Ubuntu distributions with aggressive enabling of LTO
for all builds.

This build profile sets CFLAGS and CXXFLAGS in a way that prevents cargo
tests from linking. This manifests as errors like:

= note: make[5]: *** read jobs pipe: Bad file descriptor.  Stop.
        make[5]: *** Waiting for unfinished jobs....
        lto-wrapper: fatal error: make returned 2 exit status
        compilation terminated.
        /usr/bin/ld: error: lto-wrapper failed
        collect2: error: ld returned 1 exit status
2024-05-17 23:41:54 +08:00
Mahmoud Al-Qudsi
3d648e6e04 Remove Arc from environment::globals() (take 2)
We don't forward this variable for storage in any structs, so there's no reason
to go through an Arc instead of returning the `&'static EnvStack` directly.

NB: This particular change was safe, and passes all tests on its own.
2024-05-16 21:17:15 -05:00
Mahmoud Al-Qudsi
45e249dd94 Revert removal of Arc from principal() and global()
This reverts commit c6d3bde0c6.
This reverts commit 4ce13f0adb.
2024-05-16 21:08:06 -05:00
Mahmoud Al-Qudsi
c6d3bde0c6 Remove Arc from environment::globals()
We don't forward this variable for storage in any structs, so there's no reason
to go through an Arc instead of returning the `&'static EnvStack` directly.
2024-05-16 20:50:23 -05:00
Mahmoud Al-Qudsi
4ce13f0adb Simplify lifetime of environment::principal()
It's clearer that using it with `Rc::from_raw()` is safe since we don't have to
go through an `Arc<T>`.
2024-05-16 20:46:28 -05:00
Mahmoud Al-Qudsi
ec1bf60941 Add note about possible safety issue with GLOBAL_NODE 2024-05-16 20:33:43 -05:00
Mahmoud Al-Qudsi
66618d64cb Convert some lazy_static to OnceCell/OnceLock
These have clearer sync/unsync semantics and now ship with rust itself.
They don't paper over any possible cross-thread issues, and we can specifically
choose which we want for the purpose.
2024-05-16 20:33:43 -05:00
Mahmoud Al-Qudsi
0f18480559 Simplify Parser and EnvStack singletons and clarify thread semantics
`Parser` is a single-threaded `!Send`, `!Sync` type and does not need to use
`Arc` for anything. We were using it because that's all we had for the parser's
`EnvStack`, but though that is *technically* protected internally by a mutex
(shared with global EnvStack), there's nothing to say that other parsers with a
narrower scope/lifetime on other threads will be necessarily using the same
backing mutex.

We can safely marshal the existing `Arc<EnvStack>` we get from
`environment::principal()` into an `Rc<EnvStack>` since the underlying reference
is always valid. To prove this point, we could have PRINCIPAL_STACK be a static
`EnvStack` and have `environment::principal()` use `Arc::from_raw()` to turn
that into an `Arc<EnvStack>`, but there's no need to factorize this process.
2024-05-16 20:33:39 -05:00
Mahmoud Al-Qudsi
e4282f3798 Remove all locking from principal_parser()
By inverting the order of storage, we can use an `OnceCell`/`unsync::Lazy`
inside the Send/Sync `MainThread<T>` and remove the need for a lock altogether.
2024-05-16 14:23:25 -05:00
Fabian Boehm
5dc07c9e7e completions: More shortening
Also removes a few deprecated options - there's really no need to
offer these.
2024-05-16 18:29:42 +02:00
Johannes Altmanninger
29f2da8d18 Toggle terminal protocols lazily
Closes #10494
2024-05-16 12:26:47 +02:00
Johannes Altmanninger
6f9d5cf44c Address clippy lint 2024-05-16 12:25:29 +02:00
Mahmoud Al-Qudsi
b82170aded Change extract_prefix_and_unescape_yaml() assert!() to debug_assert!()
It's reasonable since this is only checking to see that the history file
contains the expected format and if it's corrupted but we at least got what we
expect to be the correct key/value pairs, then that's all we can do.

Of course the real motivation is to speed up this very hot function in any way
possible!
2024-05-15 22:42:19 -05:00
Mahmoud Al-Qudsi
51275525c1 Speed up extract_prefix_and_unescape_yaml
On the completions and history thread, the parent function
HistoryFileContents::decode_item() is responsible for ~60% of the CPU time, and
extract_prefix_and_unescape_yaml() alone comprising 14% (of the total).

This change removes allocations in the event that the history item is either
fully or partially plain yaml with no escapes to begin with, and brings down the
execution time of this function to only 7% of the total execution time.

The bulk of the remaining time is spent in wcs2string(), which is called
unconditionally and is naturally alloc-heavy.
2024-05-15 22:42:19 -05:00
ridiculousfish
caef202551 Fix some more clippies and enable more warnings 2024-05-15 20:05:35 -07:00
Fabian Boehm
fc5eb0a98a fish_for_bash_users: Put explanation on subshells first
and *then* explain things that aren't subshells.
2024-05-15 22:44:07 +02:00
Fabian Boehm
b6bebec513 docs: Simplify Combining Lists section
This was a bit dense.
2024-05-15 20:18:17 +02:00
Fabian Boehm
8bac13360b completions/gcc: More cleanup
These options, I tell you
2024-05-15 20:07:28 +02:00
Fabian Boehm
173bcf29ab completions/gcc: Cleanup options
- Remove duplicated options - we had `-type` 9 times!
- Remove deprecated options and synonyms
- Make descriptions shorter, even removing some - when they're inscrutable they might as well not be there.

Really, 99.8% of these options are of interest to nobody except possibly (a subset of) gcc developers, so it pays to have *less* on your screen that you don't use anyway.
2024-05-15 17:05:02 +02:00
Fabian Boehm
4cadaa4041 completions/gcc: Fix some options
Especially the "-l" one was *always* offered.
2024-05-15 17:05:02 +02:00
Johannes Altmanninger
35b689335a Strip control characters from pasted text
We ignore typed control characters 33a7172ee (Revert to not inserting control
characters from keyboard input, 2024-03-02).

We used to do the same for bracketed paste but that changed in 8bf8b10f6
(Extended & human-friendly keys, 2024-03-30) which made bracketed paste
behave like fish_clipboard_paste; it inserts the exact input (minus leading
whitespace etc). At that time it wasn't clear to me which behavior was the
right one (because of the inconsistency between terminal and bracketed paste).

As reported in
https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$PEEOAoyJY-644amIio0CWmq1TkpEDdSy2QnfJdK-dco
trailing tabs in pasted text can be confusing.

There seems to be not real need to insert raw control characters into the
command line, so let's strip them when pasting.

Now the only way to insert a raw control character into the command line is
to recall it from command history.  Not sure what the behavior should be for
that case, we can revisit that later. If we get rid of raw control characters
entirely, then we can also delete the new "control pictures" rendering :)
2024-05-14 23:14:49 +02:00
Fabian Boehm
a72ba0408f CHANGELOG 2024-05-14 17:32:17 +02:00
Fabian Boehm
24836f9652 Use set --no-event in the key binding functions
This is how we can use it in a backwards-compatible way. Eventually we
would remove the compatibility guff.
2024-05-14 17:31:47 +02:00
Fabian Boehm
f1e19884fb Add set --no-event
This allows running `set` without triggering any event handlers.

That is useful, for example, if you want to set a variable in an event
handler for that variable - we could do it, for example, in the
fish_user_path or fish_key_bindings handlers.

This is something the `block` builtin was supposed to be for, but it
never really worked because it only allows suppressing the event for
the duration, they would fire later. See #9030.

Because it is possible to abuse this, we only have a long-option so
that people see what is up.
2024-05-14 17:31:47 +02:00
Fabian Boehm
403920e9d6 input: Remove all_mappings_cache
Replace it with a chained iterator.

This not only simplifies the code, but also removes a RefCell.
2024-05-14 16:14:02 +02:00
Mahmoud Al-Qudsi
e7f13ac329 Upgrade to rsconf 0.2.2
This version does not emit a warning for rustc-check-cfg for rustc <
1.80 and supports cfg names that include an underscore.
2024-05-13 16:36:27 -05:00
Fabian Boehm
e5d5e00969 Fix missing rename in build.rs 2024-05-13 20:04:08 +02:00
Mahmoud Al-Qudsi
ab68cf1eda Update build.rs formatting a bit 2024-05-13 11:34:07 -05:00
Johannes Altmanninger
a19ff4989a Prevent out-of-order execution following repaint
Commit a583fe723 ("commandline -f foo" to skip queue and execute immediately,
2024-04-08) fixed the execution order of some bindings but was partially
backed out in 5ba21cd29 (Send repaint requests through the input queue again,
2024-04-19) because repainting outside toplevel yields surprising results
(wrong $status etc).

Transient prompts wants to first repaint and then execute some more readline
commands, all within a single binding.  This was broken by the second commit
because that one defers the repaint until after the binding has finished.

Work around this problem by deferring input events again while a readline
event was queued. This is closest to the historical behavior.

The implementation feels hacky; we might find odd situations.
For example,

    commandline -f repaint end-of-line
    set token (commandline -t)

sets the wrong token.
Probably not a very important case. We could throw an error or make it work
by letting "commandline -t" drain the input queue.

That seems too complicated, better change repaints to not use the input queue
(and fake $status etc). Let's try to do that in future.

Closes #10492
2024-05-13 10:44:12 +02:00
ridiculousfish
d6e231af0d Fix some clippies 2024-05-12 14:55:35 -07:00
ridiculousfish
32ba8d93af Disable cd-without-permission test on macOS < 12
This allows the tests to pass on older macOS, before O_SEARCH was introduced.
2024-05-11 13:20:34 -07:00
ridiculousfish
172fb22692 Clean up and correct O_SEARCH definitions
Correct the FreeBSD constant and simplify some of the cfg() logic.
2024-05-11 13:20:34 -07:00
Jonathan Krebs
4606b02d44 rustfmt 2024-05-11 11:12:29 -07:00
Jonathan Krebs
07160e2f71 notice in CHANGELOG.rst 2024-05-11 11:12:29 -07:00
Jonathan Krebs
4eb0dd623d add testcase for cd without read permission 2024-05-11 11:12:29 -07:00
Jonathan Krebs
a148760963 cd: open directory with O_SEARCH or O_PATH, when the platform supports it 2024-05-11 11:12:29 -07:00
Jonathan Krebs
2ecbdb9ae7 cleanup: fds::open_dir - remove mode argument
[w]open_dir does not pass O_CREAT, so the mode argument to open is never used.
also, O_CREAT | O_DIRECTORY could not be used (portably) to create a directory.
(on POSIX does not specify what should happen, on Linux it is EINVAL.)
2024-05-11 11:12:29 -07:00
Fabian Boehm
e32efc0581 docs: Some rewording on completions 2024-05-10 17:40:18 +02:00
tesuji
f71623ec1b Partially update zig completions for zig 0.13 (#10479)
Try for completeness with `zig -h` and `zig build -h`
2024-05-09 15:31:07 -05:00
Klaus Hipp
ae486bafc8 Add completions for VS Code preview builds (#10485) 2024-05-09 15:28:14 -05:00
Klaus Hipp
1c0887eba2 Add duf completions (#10486) 2024-05-09 15:27:13 -05:00
Klaus Hipp
5524b46181 Add zed completions (#10487) 2024-05-09 15:25:41 -05:00
Mahmoud Al-Qudsi
a7bde3921b build.rs: Use rsconf::declare_dependency()
This new feature in rsconf 0.2.0 resolves the compile-time warnings we get under
rustc 1.80+ about unrecognized cfg names by informing cargo of all valid cfg
names/values even when the cfg in question isn't enabled.
2024-05-09 14:22:27 -05:00
Mahmoud Al-Qudsi
2faf1159fa Upgrade to rsconf 0.2.0 2024-05-09 14:20:57 -05:00
Mahmoud Al-Qudsi
35a16e3713 Rename FISH_TSAN_WORKAROUNDS and add feature to Cargo.toml
rustc 1.80 now complains about features not declared in Cargo.toml and cfg
keys/values not declared by build.rs to protect against typos or misuse (you
think you're using the right condition but you're not). See
rust-lang/cargo#10554 and rust-lang/rust#82450.

(We're not actually using TSAN under CI at this time, but I do want to re-enable
it at some point — especially if we get multithreaded execution going — using
the rust-native TSAN configuration.)

I'll be updating the `rsconf` crate and patching `build.rs` accordingly to also
handle the warnings about unknown cfg values, but tsan is a feature and not a
cfg and these can be dealt with in `Cargo.toml` directly.
2024-05-09 13:58:42 -05:00
Mahmoud Al-Qudsi
059b842d1b is_wsl(): Move .copied() earlier in the iter pipeline
This is a best practice that usually helps with auto vectorization, as llvm has
a hard time seeing through the references.
2024-05-09 13:33:50 -05:00
Mahmoud Al-Qudsi
5dcc5955fb Don't allocate a vector twice in wcs2zstring()
We were passing a slice (and not a vec) to `CString::new()`, meaning it would
allocate a new Vec internally to hold the bytes.

Also document that the resulting CString will be silently truncated at the first
interior NUL.
2024-05-09 13:19:06 -05:00
Mahmoud Al-Qudsi
883bcbad83 Remove possible panic from wperror() 2024-05-09 11:20:09 -05:00
Mahmoud Al-Qudsi
84be043f31 Clean up src/libc.rs some
Update the CVAR!() macro and use it more.
2024-05-08 22:34:10 -05:00
Mahmoud Al-Qudsi
2ca92cd52d completions/rustup: Filter out installed components from rustup component add 2024-05-08 18:47:15 -05:00
Mahmoud Al-Qudsi
671d128a3e completions/rustup: Fix incorrect component names
The components with the form abc-x86_64-unknown-linux-gnux32 were ending
up generating invalid components of the form abcx32, which is incorrect.
2024-05-08 18:43:28 -05:00
Fabian Boehm
9e6a661c00 One more sleep 2024-05-08 16:35:00 +02:00
Fabian Boehm
01bbdb02ae Upgrade terminfo to 0.9.0
Should also fix the macos CI failures
2024-05-08 15:46:41 +02:00
Mahmoud Al-Qudsi
92eee61fb5 Convert colors::Flags to a bitflags enum
We use accessors and setters for all operations, so there's no benefit to
storing the modifiers as separate boolean fields.
2024-05-07 14:03:38 -05:00
Fabian Boehm
41a0fe2b1d history: Check for cmd key earlier
This shows up hot in `perf record ./fish` style profiles.

This assumes that "- cmd" can't be escaped.
2024-05-07 20:23:32 +02:00
Mahmoud Al-Qudsi
f709795a3a Reserve vector capacity upfront in colors::named_color_names()
Only because why not.
2024-05-07 13:09:40 -05:00
Mahmoud Al-Qudsi
fd2ea3ff0f Add more tests for color::try_parse_rgb() 2024-05-07 13:00:11 -05:00
Mahmoud Al-Qudsi
5b79f267d6 Optimize color::try_parse_rgb()
The function was repeatedly calling `s.char_at(n)` which is O(1) only for UTF-32
strings (so not a problem at the moment). But it was also calling `hex_digit(n)`
twice for each `n` in the 3-digit case, causing unnecessary repeated parsing of
individual characters into their radix-16 numeric equivalents, which could be
avoided just by reusing the already calculated result.
2024-05-07 12:53:44 -05:00
Mahmoud Al-Qudsi
ebbba10608 Try a workaround for macOS CI failures
CARGO_NET_GIT_FETCH_WITH_CLI uses the `git` executable instead of the rust
git2 crate/lib, which speeds things up and is known to resolve some issues
fetching the registry or individual crates.

This is to work around a specific issue with git-resident Cargo.toml
dependencies (e.g. terminfo) that keep randomly failing to download under macOS
CI.
2024-05-07 11:25:02 -05:00
Fabian Boehm
37f0d7c522 Work around more spurious test failures 2024-05-07 17:55:29 +02:00
Fabian Boehm
1d7fde7bf0 tests: Fix apple key "invalid escape sequence" with python 3.12 2024-05-07 17:55:29 +02:00
Fabian Boehm
efb9d064d0 Update cargo.lock 2024-05-07 17:55:29 +02:00
Fabian Boehm
022a7c2e24 Cargo: Update libc to last MSRV-compatible version
After that it's rust 1.71
2024-05-07 17:55:29 +02:00
Fabian Boehm
29f9d3d843 tests/signals.py: Increase a timeout
10ms is *much* too short
2024-05-07 17:55:26 +02:00
Fabian Boehm
b9d44407b3 tokenizer: Stop copying the start string 2024-05-07 16:59:35 +02:00
Mahmoud Al-Qudsi
2d4e42ee93 Don't use a hardcoded ./build/ path for FISH_BUILD_DIR
We use this fallback value for FISH_BUILD_DIR when `cargo` is not
invoked from `cmake`, but we already have a cargo-defined build
directory and we shouldn't just decide to use $TARGET_MANIFEST_DIR/build
instead.

Tests pass locally!
2024-05-06 19:50:49 -05:00
Mahmoud Al-Qudsi
5f8f799cf7 Replace C++ doc \return with "Return"
quick_replace '\\\\return(s)? ' 'Return$1 ' src/

Filtered to only lines beginning with //
2024-05-06 14:59:36 -05:00
Mahmoud Al-Qudsi
589639a87d Replace C++-style \p with Markdown backticks
quick_replace '\\\\p ([a-zA-Z0-9_]+)' '`$1`' src/

Filtered to only lines beginning with //
2024-05-06 14:59:23 -05:00
Mahmoud Al-Qudsi
a35925b3ed Don't use $HOME under cargo test harness
We will continue to use the "normal" fish base directory detection when using
the CMake test harness which properly sets up a sandboxed $HOME for fish to use,
but when running source code tests with a bare `cargo test` we don't want to
write to the actual user's profile.

This also works around test failures when running `cargo test` under CI with a
locked-down $HOME directory (see #10474).
2024-05-06 14:31:51 -05:00
ridiculousfish
eba0d56411 Make bind_mode_events.py pass on Mac again 2024-05-06 10:26:32 -07:00
ridiculousfish
f6f1d93df5 Help fg.py test pass more on macOS 2024-05-06 10:26:32 -07:00
ridiculousfish
7b524f6995 Help the torn_escapes test pass on Mac 2024-05-06 10:26:32 -07:00
ridiculousfish
2bbeed157b Further improvements to signals.py test
Get it passing again on macOS.
2024-05-06 10:26:32 -07:00
ridiculousfish
269b18532d Fix Ctrl-C signals test
Prior to this change, signals.py attempted to generate Ctrl-C (SIGINT) by
sending \x03 to stdin. But with the change to use the CSI U sequence, Ctrl-C no
longer generates SIGINT.

Switch to sending SIGINT directly. Also switch up some of the sleep constants so
that a sleep command can't be confused with another one.
2024-05-06 10:26:32 -07:00
Fabian Boehm
9320fb52bb git prompt: Check for "U"nmerged files
Fixes #10481
2024-05-06 19:17:26 +02:00
Fabian Boehm
33c5cd5808 git prompt: Remove a useless use of math 2024-05-06 19:15:42 +02:00
Fabian Boehm
2a121ef1aa function: Check if --argument-names gets a valid variable name
These were accepted but then ineffective because the only way these
are used is to set a variable.
2024-05-06 17:00:45 +02:00
Fabian Boehm
39b996332e functions: Fix --argument-names display
Mentioned in #10465
2024-05-06 17:00:45 +02:00
Mahmoud Al-Qudsi
2d2b75003d Fix format string presumably broken under i686
%ld expects a 32-bit param under x86, change it to %lld instead.
2024-05-04 22:57:55 -05:00
Mahmoud Al-Qudsi
476b360eb8 Remove rust test dependency on cmake output
The test_history_formats test was reading from build/tests/ which is an artifact
of the cmake test runner. The source code tests should not depend on the cmake
test harness at all, so this is changed to read from the original test source in
the ./tests/ directory instead.
2024-05-04 20:49:49 -05:00
Mahmoud Al-Qudsi
6b43a96d09 fixup! Work around i586 wcstod test failure 2024-05-04 20:29:40 -05:00
Mahmoud Al-Qudsi
4d58a31670 Work around i586 wcstod test failure
As documented in #10474, there are issues with 64-bit floating point rounding
under x86 targets without SSE2 extensions, where x87 floating point math causes
imprecise results.

Document the shortcoming and provide some version of the test that passes
regardless of architecture.
2024-05-04 20:21:56 -05:00
Mahmoud Al-Qudsi
a99a7e65e7 Fix build failures when cmake never used
FISH_BUILD_DIR (nominally, ./build) is created by cmake. If you only check out
the project via git and then run `cargo build`, this directory won't exist and
many of the tests will fail.
2024-05-04 19:47:16 -05:00
Mahmoud Al-Qudsi
72259f658f Fix format string for failing test
%ld expects a 4-byte parameter on 32-bit architectures and an 8-byte parameter
on 64-bit architectures, but we supplied are trying to supply a 64-bit parameter
that would overflow 32-bit storage.

Use %lld instead which expects a `long long` parameter, which should be 8-bytes
under both architectures.

See #10474
2024-05-04 19:40:31 -05:00
Mahmoud Al-Qudsi
bcc1fc0167 rustup: add rustup target xxx completions 2024-05-04 18:42:11 -05:00
Johannes Altmanninger
4e816212a1 Check for unsupported "time &" in the proper place
This means we can detect this error also for simple blocks.

While at it do some cleanup in the area.
2024-05-03 09:37:56 +02:00
Johannes Altmanninger
a126d2aeba Revert "Remove redundant default escape delay"
I think given a local terminal running fish on a remote system, we can't
assume that an input sequence like \ea is sent all in one packet. (If we
could that would be perfect.)

Let's readd the default escape delay, to avoid a potential regression, but
make it only apply to raw escape bindings like "bind \e123". Treat sequences
like "bind escape,1,2,3" like regular sequences, so they can be bound on
all terminals.

This partially reverts commit b815319607.
2024-05-03 09:37:56 +02:00
Johannes Altmanninger
d855d1a2e6 Interpret escape as alt only if it's the escape byte
No need to take this code path when an unambiguous, prefix-free encoding is
used for the escape key.
2024-05-03 09:36:35 +02:00
Johannes Altmanninger
e1eeb3177e Silence clippy lint 2024-05-03 09:36:35 +02:00
Anurag Singh
4fa8d95b98 Move push_timer to measure command substitution timing too 2024-05-03 09:32:26 +02:00
Johannes Altmanninger
d4ecea56df Fix regression spuriously expanding abbr with cursor outside token
Given "abbr foo something", the input sequence

    foo<space><ctrl-z><space>

would re-expand the abbreviation on the second space which is surprising
because the cursor is not at or inside the command token.  This looks to be
a regression from 00432df42 (Trigger abbreviations after inserting process
separators, 2024-04-13)

Happily, 69583f303 (Allow restricting abbreviations to specific commands
(#10452), 2024-04-24) made some changes that mean the bad commit seems no
longer necessary. Not sure why it works but I'll take it.
2024-05-03 08:39:05 +02:00
Fabian Boehm
b5624f2e81 README: Update deps even more
I think we can now call what we have in git better than the last
C++-based release, and you'll still need a C compiler to build it
because we still have some C code (libc.c).
2024-05-02 19:44:43 +02:00
ClaXXX
0116dc5984 Fix the acidhub prompt for a commitless repository (#10462)
Deletes the error message generated by git when comparing indexes for a
commitless repository and print '-' as the branch name
2024-05-02 19:37:12 +02:00
Johannes Altmanninger
91b007cab7 Limit ctrl-r autofill/replace to a single command substitution
As reported on gitter, commands like "rm (...)" sometimes want a previous
command inside the parentheses. Let's try that.  If a user actually wants
to search for a command substitution they can move the cursor outside the
command substitution, or type the search string after pressing ctrl-r?
2024-05-01 20:21:18 +02:00
David Adam
a9078769c3 Update dependencies since RIIR is completed 2024-05-02 00:00:26 +08:00
fossdd
870c920a66 Upgrade to Alpine v3.19 and add cargo as dependency 2024-05-01 17:18:28 +02:00
Fabian Boehm
f551eeadfe Revert "Remove unused import"
It's not unused

This reverts commit 69fb620073.
2024-05-01 12:58:36 +02:00
Fabian Boehm
89b74a6983 Remove a few uses of unwrap 2024-05-01 12:58:29 +02:00
Johannes Altmanninger
69fb620073 Remove unused import 2024-05-01 12:53:00 +02:00
Johannes Altmanninger
0c413d0093 Use canonical key name in bind command 2024-05-01 12:53:00 +02:00
David Adam
5871deeee5 Debian packaging: drop Xenial support and bump debhelper compat
Discussed in https://github.com/fish-shell/fish-shell/issues/10453
2024-04-30 23:36:56 +08:00
David Adam
cc2fb5c07c fish.spec: drop RHEL/CentOS support
Discussed on https://github.com/fish-shell/fish-shell/issues/10453
2024-04-30 23:36:56 +08:00
David Adam
572aece169 RPM/Debian packaging: Rust build support 2024-04-30 23:36:56 +08:00
David Adam
e05bbe06ca build tools: add make_vendor_tarball script 2024-04-30 23:36:56 +08:00
Fabian Boehm
4be4592870 fish_add_path: Add separate message about files 2024-04-30 16:47:45 +02:00
Fabian Boehm
c43f7fbe9c tests: Add another sleep 2024-04-30 16:47:44 +02:00
Johannes Altmanninger
b00899179f Don't indent multi-line quoted strings; do indent inside ()
On a command with multiline quoted string like

    begin
        echo "line1
    line2"
    end

we actually indent line2 which seeems misleading because the indentation
changes the behavior when typed into a script.

This has become more prominent since commits
- a37629f86 (fish_clipboard_copy: indent multiline commands, 2024-04-13)
- 611a0572b (builtins type/functions: indent interactively-defined functions, 2024-04-12)
- 222673f33 (edit_command_buffer: send indented commandline to editor, 2024-04-12)

which add indentation to an exported commandline.

Never indent quoted strings, to make sure the rendering matches the semantics.
Note that we do need to indent the opening quote which is fine because
it's on the same line.

While at it, indent command substitutions recursively.  That feature should
also be added to fish_indent's formatting mode (which is the default).
Fortunately the formatting mode already works fine with quoted strings;
it does not indent them. Not sure how that's done and whether indentation
can use the same logic.
2024-04-30 14:12:48 +02:00
Johannes Altmanninger
2f6ed61833 parse_util_cmdsubst_extent to return an exclusive range
Given "1(23)4", this function returns an inclusive range, from the opening
to the closing parenthesis.  The subcommand is extracted by incrementing
the range start and interpreting the result as an exclusive range.

This is confusing, especially if we want to add multi-character quotes.
Change it to always return the full range (including parentheses) and provide
an easy way to access the command string.

While at it, switch to returning an enum.

This change is perhaps larger and more complex than necessary (sorry)
because it is mainly made with multi-character quotes in mind.  Let's see
if that works out.
2024-04-30 14:12:48 +02:00
Johannes Altmanninger
861feb7b46 Minor simplification in tokenizer 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
dfd08a1a2c Run fish_indent on checks/expansion.fish 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
29be454652 Move parse_util tests to separate file 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
e7347b9581 Bind ctrl-Z to redo (since ctrl-z is undo)
In addition to the native Emacs undo binding, we also support ctrl-z.
On Linux, ctrl-shift-z alias ctrl-Z is the redo binding according to
https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts Let's bind allow
that.

Unfortunately ctrl-shift and ctrl-alt modified shortcuts on Linux may be
intercepted by the windowing system or the terminal. Only alt-shift seems to be
available reliably (but the shift bit should mean "extend selection" in Emacs).
2024-04-30 14:00:06 +02:00
Johannes Altmanninger
5756fa369f Changelog consistency improvement 2024-04-30 14:00:06 +02:00
Johannes Altmanninger
1185e5279e Don't print multiple summaries for multiline jobs
For example

    $ echo 'line
    line2' | sleep 1 &

    fish: Job 1, 'echo 'line' has ended
    fish: Job     line2' | sleep 1 &, '' has ended
2024-04-30 14:00:06 +02:00
Fabian Boehm
8639d7e450 Remove allow-unused-imports 2024-04-29 22:00:59 +02:00
Fabian Boehm
4d4ef7fa40 Remove backports for 1.67
This removes IsOkAnd and the is_some_and method.

I cannot actually find is_none_or in the stdlib?

I've kept the trait name to avoid changing it now and then later, maybe this should
be moved elsewhere to avoid claiming it's an stdlib thing?
2024-04-29 22:00:59 +02:00
Fabian Boehm
16fcc5de7c Increase MSRV to 1.70
It appears we can't find a system that ships rustc >= 1.67 and < 1.70,
so keeping it at 1.67 gains nothing.

1.70 is used in Debian 13, so that will be able to build fish out of
the box (12 was on 1.63 which was already too low).
2024-04-29 22:00:59 +02:00
Fabian Boehm
0aa588a129 CONTRIBUTING: Remove versions
These were outdated already (cmake). Let's keep them in the README for now.
2024-04-29 22:00:59 +02:00
Johannes Altmanninger
964d3fff15 Keep undo history across prompts
After abandoning a commandline (for example with ctrl-c) it's nice to be
able to restore it. There is little reason to discard the requisite undo
information, so keep it.
2024-04-29 09:20:09 +02:00
ridiculousfish
3afe0bb569 Remove LoopedRead and LoopedWrite
These were unused.
2024-04-28 11:15:48 -07:00
Fabian Boehm
55235a27d3 docs/abbr: Add --command to add subcommand synopsis 2024-04-28 11:33:27 +02:00
Johannes Altmanninger
a50419da1c Fix test_version.fish for Ubuntu Noble Numbat Docker build
git_version_gen fails on Noble Numbat because modern Git refuses
to read repo-local config if owned by another user.

    fishuser@a4263f53c93e:~/fish-build$ cd /fish-source/
    fishuser@a4263f53c93e:/fish-source$ git describe --always --dirty
    fatal: detected dubious ownership in repository at '/fish-source'
    To add an exception for this directory, call:

Allow reading it (though that doesn't seem necessary here, it would be better
to ignore it).
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
5152f6534d Fix test_functions.fish for Ubuntu Noble Numbat Docker build
vared.fish is installed at
/home/fishuser/fish-build/test/buildroot/usr/local/share/fish/functions/vared.fish
as oppposed to being sourced from share/functions/.

I'm not 100% sure why this happens but it doesn't seem wrong.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
52ef919aee Require mandoc/nroff for print-help test
Ubuntu Noble Numbat doesn't install this by default.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
e20ce2efea Ubuntu Noble Numbat dockerfile
Currently pinned to rustc 1.75 but only because this is what we use on OBS.
2024-04-28 10:38:26 +02:00
Johannes Altmanninger
c0bcd817ba Remove obsolete bindings
iTerm2 supports CSI u so the custom bindings are no longer needed. Sequences
like \e\eOC are Escape followed by an SS3 arrow key which we can already
decode separately.
2024-04-28 10:38:26 +02:00
Mahmoud Al-Qudsi
40591ba629 Unify convert and magick completions 2024-04-27 11:45:54 -05:00
Jadi
6840ef46f7 Completion for magick (#10307)
In ImageMagick 7 or later, legacy commands have been replaced with
magick. Here a new functions, defines these completions and it is
called for `magick` and `magick convert`.

fixes #7172. Closes #10307.

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-04-27 11:45:12 -05:00
Fabian Boehm
2da5ce7a48 completions/conda: Enable file completions for --file options
Fixes #10463
2024-04-27 17:11:52 +02:00
Johannes Altmanninger
301e4d497e Make shift-delete also delete current autosuggestion
This is a bit more convenient than using "history delete".
2024-04-27 10:54:31 +02:00
Johannes Altmanninger
67197b4b07 Fix cleanup of autogenerated completions
We were inconsistent about this for no apparent reason.

Also cleaning up in ~/.config/fish/completions is
irrelevant by now since we moved to ~/.local/share/fish 8 years ago.

Now that the parent commit moved it again, cleaning up that one seems
reasonable.
2024-04-27 10:54:31 +02:00
Anurag Singh
62a8b48fd1 Move generated completions to cache directory 2024-04-27 10:39:30 +02:00
Fabian Boehm
1503be4287 parse_execution: Use an exhaustive match instead of an assert
This could also be "cancel", which we didn't check and instead
asserted out.
2024-04-27 08:19:00 +02:00
Johannes Altmanninger
fb99edae92 Stop using comma from command substitution in brace expansion
Fixes #5048
2024-04-26 18:15:47 +02:00
Johannes Altmanninger
ec33550cff Fix detection of empty commandline in alt-d binding 2024-04-26 11:16:30 +02:00
Johannes Altmanninger
758b8e7126 commandline.rst: fix typo 2024-04-26 11:16:30 +02:00
Johannes Altmanninger
da94ade2ad README: fix rst syntax 2024-04-26 11:16:30 +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
9954074dde CHANGELOG abbr --command 2024-04-24 18:20:25 +02:00
Fabian Boehm
69583f3030 Allow restricting abbreviations to specific commands (#10452)
This allows making something like

```fish
abbr --add gc --position anywhere --command git back 'reset --hard
HEAD^'
```

to expand "gc" to "reset --hard HEAD^", but only if the command is
git (including "command git gc" or "and git gc").

Fixes #9411
2024-04-24 18:09:04 +02:00
Fabian Boehm
16eeba8f65 pexpects: More timeouts 2024-04-23 21:59:40 +02:00
Fabian Boehm
7ea17bf621 CI: Allow pip3 to install packages system-wide again
Longer term we could switch to a venv
2024-04-23 19:42:54 +02:00
Fabian Boehm
0bb0934bc2 tests: Remove weird triplicated string
I have no idea why this matches the string thrice when it is entered
once and suggestions are disabled.

I've seen this fail even on my local system, I expect it works because
of some terminal integration.
2024-04-23 19:40:49 +02:00
Giorgio Gallo
8a1eae4640 Clarify block command documentation 2024-04-23 19:36:11 +02:00
Johannes Altmanninger
24f0abe780 Fix decoding mulitbyte characters after escape prefix
Fixes #10457
2024-04-23 00:18:14 +02:00
Fabian Boehm
10a1458dea Some more CHANGELOG 2024-04-22 20:13:12 +02:00
Johannes Altmanninger
8d20bbfcd7 Fix bad assertion warning about disowned jobs that don't get their proper pgroup
Running

    echo foo | vim -

gets us in a weird situation because we put the job in fish's process groups.
It causes us to not set a PGID for this job, so it can't be resumed among
other things.

Stopping the job with ctrl-z and try to exit the shell causes a crash in the
"There are still jobs active" warning because the PID for the job is still 0.
Let's remove the assertion to restore previous behavior, and hopefully fix
this later.
2024-04-21 21:32:44 +02:00
Johannes Altmanninger
fd61bad946 Further simplify terminal_protocols scoping
Remove the last non scoped place where we disable protocols (just before
exec(1)); it's not necessary with the current approach because we always
disable inside eval.
There is an edge case where we don't:

    fish -ic "exec bash"

leaving bash with CSI u enabled.  Disable that also in -ic mode where we
don't have a reader.

In future we should use the same approach for restore_term_mode() but I'm
not sure which one is better.
2024-04-21 21:32:44 +02:00
Johannes Altmanninger
99bf3d0dbb Fix imbalanced terminal protocols on SIGCHLD
We enable terminal protocols once at startup, and disable them before exit.
Additionally, we disable them while evaluating commands (see 8164855b7 (Disable
terminal protocols throughout evaluation, 2024-04-02))..

Thirdly, we re-enable protocols inside builtin read (where it's disabled
because we are evaluating something).  All of these three are scoped and
statically guaranteed to not leak into each others scopes.

There is another place where we enable protocols non-scoped: when we
receive a notification that a job is stopped. If this is ever hit, things
will be imbalanced and we'll fail to restore the right terminal state,
or (more likely) crash due the assertion in terminal_protocols_enable().
This code path used to be necessary when we disabled protocols only while
actually executing an external command but we changed that in 8164855b7,
so it should no longer be.  Remove it.

I haven't been able to find a test case, I'll try to do that later.

The main reason we changed the scope of protocols was focus reporting (#10408).
We have given up on that for now (outside tmux where I can't get it to work)
so we might want to reconsider and go back to the "optimized" approach of
enabling it for as long as possible. But this is simpler, easier to verify.
2024-04-21 17:16:23 +02:00
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
Johannes Altmanninger
00432df420 Trigger abbreviations after inserting process separators
On

    a;

we don't expand the abbreviation because the cursor is right of semicolon,
not on the command token. Fix this by making sure that we call expand-abbr
with the cursor on the semicolon which is the end of the command token.
(Now that our bind command execution order is less surprising, this is doable.)

This means that we need to fix the cursor after successfully expanding
an abbreviation. Do this by setting the position explicitly even when no
--set-position is in effect.

An earlier version of this patch used

    bind space self-insert backward-char expand-abbr or forward-char

The problem with that (as a failing test shows) was that given "abbr m
myabbr", after typing "m space ctrl-z", the cursor would be after the "m",
not after the space.  The second space removes the space, not changing the
cursor position, which is weird.  I initially tried to fix this by adding
a hack to the undo group logic, to always restore the cursor position from
when begin-undo-group was used.

    bind space self-insert begin-undo-group backward-char expand-abbr end-undo-group or forward-char

However this made test_torn_escapes.py fail for mysterious reasons.
I believe this is because that test registers and triggers a SIGUSR1 handler;
since the signal handler will rearrange char events, that probably messes
with the undo group guards.

I resorted to adding a tailor-made readline cmd. We could probably remove
it and give the new behavior to expand-abbr, not sure.

Fixes #9730
2024-04-13 20:11:11 +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
cacfcf8089 Reuse parse_util_token_extent for completion insertion
We don't need all of its features here but this makes the "completion is
appended" case more similar to the "completion replaces token" case.
2024-04-13 15:33:05 +02:00
Johannes Altmanninger
dcd6c74248 Inline parse_util_get_quote_type()
Need to access the token extent in a following commit.
2024-04-13 15:33:05 +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
88d6801720 Don't match new-style bindings against raw sequences
On Konsole, given

    bind escape,i 'echo escape i'
    bind alt-i 'echo alt-i'

pressing alt-i triggers the wrong binding.  This is because we treat "escape
followed by i" as "alt-i". This is to support raw sequences like "\ei"
which are probably meant as "alt-i" -- we match such inputs to both mappings.

This double matching is not necessary for new-style bindings which
unambiguously describe the key presses, so let's activate this sequence
matching only for bindings specified as raw sequences.

Conversely, we currently fail to match an XTerm raw binding for ctrl-enter:

    echo 'XTerm.vt100.formatOtherKeys: 0' | xrdb
    xterm -e fish
    bind \e\[27\;5\;13~ execute

because we decode this to a single char; we match the leading CSI but not
the entire sequence. So this is a raw binding where we accidentally
match full, modified keys. Fix that too (two birds with one stone).
2024-04-13 14:36:11 +02:00
Johannes Altmanninger
6858f1100a Remove redundant raw CSI u bindings 2024-04-13 14:36:11 +02:00
Johannes Altmanninger
1d98846e03 Remove some redundant raw bindings
We already decode these, see parse_csi() and parse_ss3().
2024-04-13 14:36:11 +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
edb5cb7226 Fix restoring cursor position on redo with edit groups 2024-04-13 14:36:11 +02:00
Johannes Altmanninger
d1a4b4bc73 Fix undo pexpect test
The assertions were satisfied even though we never triggered any undo.
2024-04-13 11:34:36 +02:00
Johannes Altmanninger
50d93cced1 Remove bad assertion
builtin read pushes a reader instance after enabling terminal protocols,
so this doesn't hold.

Fixes #10438
2024-04-12 14:20:45 +02:00
Johannes Altmanninger
1dd901e521 Maintain cursor in history prefix search
The search term highlighting looks looks really bad on the default theme
because the command is highlighted as dark blue and the search term adds
a dark background.  If this new feature motivates us to finally fix this,
that would be great.

Closes #10430
2024-04-12 13:08:52 +02:00
Lia Lenckowski
90cffb18a1 complete brightnessctl flags 2024-04-12 12:53:55 +02:00
Johannes Altmanninger
13b5322bef Disable failing bind_mode_events.py in FreeBSD for now
I'm pretty sure it's just a timing issue.
2024-04-12 12:34:01 +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
9158395d10 Fix __fish_list_current_token and friends for multiline commandlines
Some of these handled multiline prompts but not multiline command lines. We
first need to move the cursor to the end of the commandline, then we can
print a message.  Finally, we need to move the cursor back to where it was.
2024-04-12 12:00:24 +02:00
Johannes Altmanninger
8386088b3d Update commandline state changes eagerly as well
The new reader_execute_readline_cmd() runs apply_commandline_state_changes()
to make sure that given

    bind x "commandline --insert foo; commandline -f backward-char"

the backward-char command knows about the insertion of "foo".  This
causes problems when running "sleep 1&" and typing some characters -
the commandline will be cleared when the job finishes.  This is because
apply_commandline_state_changes() works with stale information in this case.

Let's call it as soon as we know it's needed.  This is less messy and fits
better with the new bind function semantics ("execute things in the order
they are written").
2024-04-12 12:00:24 +02:00
Johannes Altmanninger
57d3614fd8 Add missing import to fg.py 2024-04-12 11:41:40 +02:00
Johannes Altmanninger
9db53e8d26 Allow abbreviating ctrl-/alt- as c-/a-
This makes them more convenient to use interactively, similar to the existing
\c and \a versions.  The resulting bind output keeps using the canonical
ctrl/alt version.

Not sure about s- because that's somewhat ambiguous, it could be "super".
2024-04-12 11:27:55 +02:00
Johannes Altmanninger
bc4897b2b5 Remove "plus" from named keys
It's not necessary and it's confusing if the canonical version unnecessarily
deviates from the input (we use + for Vi binds).
2024-04-12 11:27:55 +02:00
Johannes Altmanninger
59922d0859 Remove stale bits from CONTRIBUTING 2024-04-12 11:27:55 +02:00
Johannes Altmanninger
5c3a0251b7 funced: don't try to source interactive-only function
Regressed in 2c2ab0c1f (Always `source` file after `funced` (#10318),
2024-02-22) which was only intended for functions that are backed by a file.
2024-04-12 11:27:55 +02:00
Johannes Altmanninger
f062ad3ad6 Try to fix macOS CI by disabling fg.py, signals.py, torn_escapes.py
These work fine AFAICT, just not in CI.
2024-04-12 11:27:55 +02:00
Johannes Altmanninger
15cd74a3bb Fix fish_escape_delay_ms for terminals that send CSI 27 u
See the parent commit for some context.  Turns out that 8bf8b10f6 (Extended &
human-friendly keys, 2024-03-30) broke this for terminals that speak CSI u.
This is pretty complex, probably not worth it.
2024-04-10 22:39:33 +02:00
Johannes Altmanninger
b815319607 Remove redundant default escape delay
When a terminal sends \x1ba, that could be either escape,a or alt-a.
Historically we've handled this with an escape delay that defaults to 30
milliseconds.  If we read nothing for that time, it's escape. Otherwise it's
an alt modifier (or an escape sequence).

As a side effect of 8bf8b10f6 (Extended & human-friendly keys, 2024-03-30) we
added a new way of disambiguating escape: whenever we read the escape byte,
we immediately try another (nonblocking) read.  If it succeeds, we treat it
as modifier, else it's escape. Before that commit, we didn't have a concept
of modifiers.

The new way works fine for disambiguating escape,a from alt-a (as pressed
by the user) because only for alt-a the data is sent in the same packet.

So we no longer need the escape delay to disambiguate the alt from the
escape key.  Let's simplify things by not using it by default.

The escape delay as set by fish_escape_delay_ms also serves another purpose;
it allows to disambiguate "escape,a" from "escape (pause) a". For that use
case we want to keep it.
2024-04-10 22:39:33 +02:00
Johannes Altmanninger
1da2087038 Also refresh TTY timestamps before "commandline -f repaint"
As mentioned in 8a7c3ceec (Don't abandon line after writing control sequences,
2024-04-06) we need to freshed stdout timestamps after writing to stdout
but before we might redraw, in particular when writing control sequences.

Commit a583fe723 ("commandline -f foo" to skip queue and execute immediately,
2024-04-08) made "commandline -f repaint" redraw immediately, while still
executing the bound shell command; at that time we have written "disabling"
sequences but not refreshed timestamps yet, so do that.

This is probably not needed for commands outside the repaint family.
Needless to say that this is messy, maybe we can simplify things in future.

Ref https://github.com/fish-shell/fish-shell/issues/10409#issuecomment-2044863817
2024-04-09 21:53:48 +02:00
Johannes Altmanninger
64bc989e19 Drop invasive control sequences from pexpect debug output
A failing test might emit an OSC 133 prompt marking sequence, confusing
the parent terminal to think the test output contains a shell prompt. Let's
remove these.
2024-04-09 09:51:29 +02:00
Johannes Altmanninger
adb40149a3 Do not insert key's PUA encoding into the command line
If a key's codepoint is in the PUA1 range, it could
be either from our own named keys (like key::Space)
or from a CSI u key that we haven't assigned a name yet
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions
(The latter can still be bound using the \u1234 or the equivalent \e[4660u
raw CSI u sequence.)

It doesn't make sense to insert a PUA character into the commandline when
the user presses PrintScreen; ignore them silently.

This partially reverts b77d1d0e2 (Stop crashing on invalid Unicode input,
2024-02-27). That commit did:
1. convert input byte sequences that map to a PUA codepoint into several
   characters, using our on-char-per-byte PUA encoding.
2. do the same for inputs that are codepoints outside the valid Unicode range.
3. render them as replacement character (one per input byte)

In future, we should probably remove these features altogether, and simply
ignore invalid Unicode code points.
2024-04-09 00:46:16 +02:00
Johannes Altmanninger
a583fe7230 "commandline -f foo" to skip queue and execute immediately
Commit c3cd68dda (Process shell commands from bindings like regular char
events, 2024-03-02) mentions a "weird ordering difference".
The issue is that "commandline -f foo" goes through the input
queue while other commands are executed directly.
For example

    bind ctrl-g "commandline -f end-of-line; commandline -i x"

is executed in the wrong order. Fix that.

This doesn't yet work for "commandline -f exit" but that can be fixed easily.

It's hard to imagine anyone would rely on the existing behavior.  "commandline
-f" in bindings is mostly used for repainting the commandline.
2024-04-09 00:22:41 +02:00
Johannes Altmanninger
9d7116c12d Move readline loop state into reader state
To be used by the next commit.
2024-04-09 00:22:41 +02:00
Johannes Altmanninger
f9bdad3f77 Remove unused function 2024-04-09 00:22:41 +02:00
Johannes Altmanninger
11bd5d7f0c Extract function for handling input event
Will use in a following commit.
2024-04-09 00:22:41 +02:00
Johannes Altmanninger
e934e1b009 Test that bind output can recreate the same bindings 2024-04-09 00:22:41 +02:00
Johannes Altmanninger
8949c44574 Fix __fish_complete_command with multiline tokens 2024-04-09 00:07:27 +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
d025b245f6 Fix parsing of single-digit function keys 2024-04-09 00:07:27 +02:00
Johannes Altmanninger
7fd018e851 Minor changelog update 2024-04-09 00:07:27 +02:00
Johannes Altmanninger
ece4ebaf72 fish_key_reader: show unmapped function key as hex code
We don't yet support all keys from
https://sw.kovidgoyal.net/kitty/keyboard-protocol/#functional-key-definitions
Instead of displaying a private-use character, show the character code;
this can be used to map the key even if we don't know a name for it.

    bind \uE011 'echo print screen'
    bind ctrl-\uE011 'echo do control + print screen'

Note that it's also possible to mape the raw CSI u sequence, like

    bind \e\[57361u 'echo print screen'

but we should not encourage that syntax because it does not allow adding
the modifiers like ctrl.

Of course leaking the PUA character code is not ideal.
2024-04-08 09:16:55 +02:00
Johannes Altmanninger
1c41bcd1a4 fish_key_reader: minimize logic following recent changes 2024-04-08 09:16:22 +02:00
Johannes Altmanninger
405c9c6aaf Remove unused import 2024-04-08 09:16:22 +02:00
Johannes Altmanninger
473191b708 Revert "Run asan and macOS CI in release mode too"
This reverts commit 8ada027f05.

See 8ada027f05 (commitcomment-140718706)
2024-04-08 09:16:22 +02:00
Johannes Altmanninger
d30fab372f Pop CSI u mode on SIGTERM
As implied by the changelog.

Unfortunately it's not obvious how to access the RefCell value in spite
of a potential (albeit unlikely) present mutable borrow. We need to use a
different type to make it work in such cases, hopefully doing that in future.

In future we could even use panic=abort and use this style of cleanup for
panics (instead of RAII).
2024-04-07 13:32:48 +02:00
Johannes Altmanninger
1696b1527a builtin commandline: remove redundant function calls 2024-04-07 13:32:48 +02:00
Johannes Altmanninger
e0bbeb647b Remove unused function 2024-04-07 12:59:16 +02:00
Johannes Altmanninger
866585c6ce Fix accidental truncation of raw sequences
For numpad 1 with nulock, Alacritty sends

    escape,[,5,7,4,0,0,u

which is codepoint \x31, key "1".  We have a terminfo mapping for "sright"
which translates to

    escape,[,1,;,2,C

The first two characters, escape and [ match. Then we accidentally match the
"1" from the mapping against the entire sequence, because that sequence is
canonicalized to codepoint "1" . The most blatant problem is that we discard
the rest of the sequence. Fix that.

This allows us to re-enable raw CSI u mappings like "bind \e[1u ..."
which is what kitty uses for shell integration.
2024-04-07 09:59:28 +02:00
Johannes Altmanninger
b97187c90b Fix crash displaying CSI u codepoints in ASCII control range 2024-04-07 09:59:09 +02:00
Johannes Altmanninger
c8f3659737 Add special_key=1 to prompt marking
Kitty uses this for more graceful mouse handling
when the completion pager is active, see
https://github.com/kovidgoyal/kitty/pull/7316#issuecomment-2041279797
2024-04-07 09:59:09 +02:00
Johannes Altmanninger
3b9e3e251b Emit OSC 133 sequences to mark prompt/command output regions
This allows terminals like foot and kitty to
* scroll to the previous/next prompt with ctrl-shift-{z,x}
* pipe the last command's output to a pager with ctrl-shift-g

Kitty has existing fish shell integration
shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish which we
can simplify now. They keep a state variable to decide which of prompt start,
command start or command end to output.  I think with our implementation
this is no longer necessary, at least I couldn't reproduce any difference.
We also don't need to hook into fish_cancel or fish_posterror like they do;
only in the one place where we actually draw the prompt.

As mentioned in the above shell integration script, kitty disables reflow
when it sees an OSC 133 marker, so we need to do it ourselves,
otherwise the prompt will go blank after a terminal resize.

Closes #10352
2024-04-06 22:22:56 +02:00
Johannes Altmanninger
33701faa8c completions/set: offer private variables if token starts with _ 2024-04-06 21:20:53 +02:00
Johannes Altmanninger
18f6492564 completions/set: strip cursed descriptions from history/fish_killring
If I type

    $ echo $SOME_VARIABLE_WIHT_A_TYPO
    $ set -S SOME_VARIABLE_WIHT

and press tab, I'm always extremely surprised that this completes to

    $ set -S fish_history

which is because $history[1] contains the typo'd variable name.  I don't
think anyone intends to filter by that last 3-4 history items, so let's
remove this pitfall.

Note that I usually hit this scenario with undefined variables, not necessarily
typos.. "set -S" is usually redundant but it's still quite nice in this case,
to rule out any weird empty strings/empty lists.
2024-04-06 19:12:25 +02:00
Johannes Altmanninger
444cda20bc Document focus events 2024-04-06 18:14:17 +02:00
Johannes Altmanninger
8a7c3ceec3 Don't abandon line after writing control sequences
Commit 8164855b7 (Disable terminal protocols throughout evaluation, 2024-04-02)
changed where we output control sequences (to enable bracketed paste and CSI).
Likewise, f285e85b0 (Enable focus reporting only just before reading from
stdin, 2024-04-06) added control sequence output just before we read().

This output causes problems because it invalidates our stdout/stderr
timestamps, which causes us to think that a rogue background process wrote
to the terminal; we react by abandoning the current line and redrawing the
prompt below. Our fix was to refresh the TTY timestamps after we run a bind
command that might add stdout (#3481).

Since commit c3cd68dda (Process shell commands from bindings like regular
char events, 2024-03-02), this timestamp refresh logic is in the wrong place;
shell commands are run later now; we could move it but wait -

... we also need to make sure to refresh timestamps after outputting control
sequences.  Since bracketed paste is enabled after CSI u, we can skip the
latter.  Additionally, since we currently output control sequences before
every single top-level interactive command, we no longer need to separately
refresh timestamps in between commands.

Fixes #10409
2024-04-06 17:45:55 +02:00
Johannes Altmanninger
de730b7885 Extract function for running commands from bindings 2024-04-06 17:45:55 +02:00
Johannes Altmanninger
f285e85b0c Enable focus reporting only just before reading from stdin
Some terminals send the focus-in sequences ("^[I") whenever focus reporting is
enabled.  We enable focus reporting whenever we are finished running a command.
If we run two commands without reading in between, the focus sequences
will show up on the terminal.

Fix this by enabling focus-reporting as late as possible.

This fixes the problem with `^[I` showing up when running "cat" in
gnome-terminal https://github.com/fish-shell/fish-shell/issues/10411.

This begs the question if we should do the same for CSI u and bracketed paste.
It's difficult to answer that; let's hope we find motivating test cases.
If we enable CSI u too late, we might misinterpret key presses, so for now
we still enable those as early as possible.

Also, since we now read immediately after enabling focus events, we can get
rid of the hack where we defer enabling them until after the first prompt.
When I start a fresh terminal, the ^[I no longer shows up.
2024-04-06 11:22:19 +02:00
Johannes Altmanninger
7ffe023735 builtin read: enable terminal protocols again
It's not clear whether builtin read should be able to do everything
that the normal prompt does but I guess we haven't found a problem yet.
Given that read could be used to read a single character at a type,
it's a bit odd to toggle terminal protocols all the time.
But that's not the typical case (at least not for when stdin is a TTY),
and it seems fine.

Teste with

    bind ctrl-4 'echo yay'

Regressed in 8164855b7 (Disable terminal protocols throughout evaluation,
2024-04-02).
2024-04-06 11:22:19 +02:00
Johannes Altmanninger
629cad66a3 Clean up log statement 2024-04-06 11:22:19 +02:00
Fabian Boehm
1a4bb851ff docs: More on dereferencing variables 2024-04-05 18:41:09 +02:00
phanium
0a6e8468cc Avoid invoking extra subshell in __fish_md5 2024-04-05 15:26:48 +02:00
phanium
aa1a390504 Replace __funced_md5 with __fish_md5 2024-04-05 15:26:48 +02:00
phanium
b121b9649b Fix completions for pactree, pkgfile 2024-04-05 15:26:06 +02:00
Klaus Hipp
3c9b5713c9 Update code completions 2024-04-05 15:25:32 +02:00
Armin Brauns
3c0d7d0feb Add typst completions 2024-04-05 15:24:36 +02:00
Felix Luciano Salomon
8bbf760860 Added bruno completions (#10388)
* Added bruno completions

* Modified format completion to include formats as closed list arguments
2024-04-05 15:23:29 +02:00
Fabian Boehm
ce92472af1 input: Comment out flogs
These are *extremely* chatty.

If they are needed we should add them to a subcategory like `input` or
`reader-input` so you can easily disable them.
2024-04-03 20:15:17 +02:00
Fabian Boehm
1f2e0617d1 tests: Pass correct length for buffer
This allocated 64 bytes and then told snprinf it was 128. That's a
no-no even if we never need that much.
2024-04-03 20:15:17 +02:00
Johannes Altmanninger
66c6e89f98 Don't add collateral sentinel key to input queue
This is for bracketed paste and focus reporting where we already add a proper
event to the queue.
2024-04-03 20:02:08 +02:00
Johannes Altmanninger
1baa893e60 Don't end history search on focus in/out events
Apparently VTE terminals send the "focus in" event whenever we re-enable
focus reporting. That's probably a sensible thing to do.

Anyway, our problem is simply that we accidentally end history search on these
focus events which are implemented as anonymous (unmappable) readline cmds.
Perhaps there should be a separate cmd category.

Focus events show up as key::Invalid which is a weird private use code point;
probably we can get rid of this key..

Fixes #10411
2024-04-03 20:02:08 +02:00
Johannes Altmanninger
350598cb99 Decode arrow keys as sent by urxvt
Not sure if we want to support this indefinitely but appears to be free as
of today.
2024-04-03 19:37:03 +02:00
Fabian Boehm
e8eb4822ce input: Fix crash for weird bracketed paste
I can reproduce by pasting after

```fish
echo \cc foo | fish_clipboard_copy
```

in Wezterm
2024-04-03 16:30:38 +02:00
Johannes Altmanninger
cb58a30bf2 Report $PWD changes unconditionally
Similar to 20bbdb68f (Set terminal title unconditionally, 2024-03-30).

While at it, get rid of a few unnecessary guards (we are never called from
a command substitution, so the check only adds confusion).
2024-04-03 13:14:02 +02:00
Johannes Altmanninger
9870faa8be Remove workarounds for Emacs ansi-term
I'm not sure if it's worth supporting a terminal that mishandles unknown OSC
and CSI sequences. Better to fix the terminal.  Note that there are Emacs
terminals available that don't have this problems; for example "vterm".
2024-04-03 13:09:27 +02:00
Johannes Altmanninger
af1b599818 On redo, restore pre-undo cursor position 2024-04-03 13:09:27 +02:00
Fabian Boehm
3af849d739 tests/pexpect: Fix \d escape 2024-04-02 22:41:54 +02:00
Fabian Boehm
171869858a tests/histfile.py: Check for no jobs 2024-04-02 22:24:09 +02:00
Fabian Boehm
3d46987cff tests/histfile.py: Try exiting a second time 2024-04-02 22:19:47 +02:00
Fabian Boehm
fe95e4f4cd curses: Remove f13-f20
No longer supported by keys, and these are not a thing in the real world
2024-04-02 21:33:54 +02:00
Johannes Altmanninger
8164855b70 Disable terminal protocols throughout evaluation
Test changes are very hacky, will cleanup later.

Closes #10408
2024-04-02 21:25:47 +02:00
Fabian Boehm
6501f7ab6f tests: Disable terminal.py under asan
We want asan to tell us about memory errors, not randomly fail tests
because it's too slow.
2024-04-02 19:57:57 +02:00
Johannes Altmanninger
695b408396 kitty keyboard protocol: decode numlock keys
Also disable the legacy matching hack for CSI u sequences, to prevent bindings
from treating this as prefix.
2024-04-02 18:20:35 +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
Fabian Boehm
53961c7759 Fix doc formatting
This is RST, not markdown
2024-04-02 17:39:39 +02:00
Fabian Boehm
ec603790d1 nim prompt: Don't use test
A single-argument use, even!

Fixes #10404
2024-04-02 17:33:30 +02:00
Johannes Altmanninger
e8e91c97a6 fish_key_reader: ignore sentinel key
Also, move the undo grouping for paste to the right place.
2024-04-02 16:48:25 +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
8ada027f05 Run asan and macOS CI in release mode too
I don't know why we're inconsistent about this, and at least asan fails
frequently due to timeouts.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
16c5ca2609 Fix mouse handling tests to send valid escape sequences 2024-04-02 14:35:16 +02:00
Johannes Altmanninger
22717339b4 fish_clipboard_paste: don't bypass pager search field.
To do so add an ad-hoc "commandline --search-field" to operate on pager
search field.

This is primarily motivated because a following commit reuses the
fish_clipboard_paste logic for bracketed paste. This avoids a regression.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
d0cdb142de Make CharEvent a native enum 2024-04-02 14:35:16 +02:00
Johannes Altmanninger
aa40c3fb7e Remove set-mode char event
Use generic shell commands instead.  This keeps us honest.

No functional change expected.
2024-04-02 14:35:16 +02:00
Johannes Altmanninger
20bbdb68fa Set terminal title unconditionally
Terminal titles are set with an OSC 0 sequence.  I don't think we want to
support terminals that react badly to unknown OSC (or CSI) sequences.

So let's remove our feature detection.

This will fix future false negatives along the lines of
https://github.com/fish-shell/fish-shell/pull/10037
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
Johannes Altmanninger
4149a37f1c Pull rust-terminfo-fix for rio terminal
https://github.com/meh/rust-terminfo/pull/42
2024-04-02 08:01:48 +02:00
Johannes Altmanninger
a216b3cf6a Print panic message to stderr, like the stack trace 2024-04-02 07:34:19 +02:00
Johannes Altmanninger
1232cfd3bb Fix typo 2024-04-02 07:33:07 +02:00
Johannes Altmanninger
af6dc9221f Use panic::set_hook instead of catch_unwind to help debug panics 2024-04-02 07:27:22 +02:00
David Adam
698d8bd315 add comment regarding lru hashing algorithm 2024-04-01 22:33:22 +08:00
Fabian Boehm
f4a3dcca3a docs: Clarify command substitution section
Put `$()` version front-and-center and make the quoting more
prominent.

In turn mention `()` as a version that can't be quoted.
2024-04-01 15:40:25 +02:00
David Adam
3a98db46bc build.rs: pick up version file for tarballs from source, not build, directory (#10400) 2024-03-31 00:43:55 -05:00
Felix Luciano Salomon
1f68d66692 Added pbpaste command completions (#10389)
* Added pbpaste command completions
2024-03-30 22:35:53 -05: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
David Adam
792eff42b7 discard serial_test features
The default features are async and log, which are not utilised, and add
a significant number of dependencies to the tree.
2024-03-31 00:47:38 +08: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
8eb7a08035 Document backward-char-passive 2024-03-29 14:23:53 -05: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
Mahmoud Al-Qudsi
674c481d87 Add documentation for forward-char-passive 2024-03-28 00:18:24 -05:00
Mahmoud Al-Qudsi
df09ab598f Add forward-char-passive binding
This binding is akin to ForwardSingleChar but it is "passive" in that is not
intended to affect the meta state of the shell: autocompletions are not accepted
if the cursor is at the end of input and it does not have any effect in the
completions pager.
2024-03-28 00:13:34 -05:00
Fabian Boehm
b535213ac0 CHANGELOG abbr decorators 2024-03-27 22:13:27 +01:00
Fabian Boehm
217b009e18 abbr: expand command abbrs after decorators (#10396)
Currently, we expand command-abbrs (those with `--position command`) after `if`, but not after `command` or `builtin` or `time`:

```fish
abbr --add gc "git checkout"
```

will expand as `if gc` but not as `command gc`.

This was explicitly tested, but I have no idea why it shouldn't be?
2024-03-27 17:17:55 +01:00
Mahmoud Al-Qudsi
326d986186 Fix broken read_ni() not making fd non-blocking on Linux
The incorrect order of operations was being used since && binds tighter than ||
in rust (as with most sane languages).

Under Linux, EAGAIN == EWOULDBLOCK so this would always succeed in the case of a
non-blocking fd without making the call to make_fd_nonblocking().

Comparing to the 3.7.0 C++ code, it looks like this was an oversight introduced
in the migration to rust.
2024-03-26 01:06:42 -05:00
Johannes Altmanninger
62a49acda3 completions/iwctl: fix spurious error on "iwctl device foo" 2024-03-25 20:56:08 +01:00
Johannes Altmanninger
6efe0907e9 Fix --debug-output regression
We accidentally close FLOG output file.  Let's leak it for now; in future
we should close it.
2024-03-25 20:56:08 +01:00
Johannes Altmanninger
f5d6ea6cf6 Basic completions for gdbserver 2024-03-25 05:42:16 +01:00
Johannes Altmanninger
5b324f8ecb Fix regression in parse_util_process_extent
Found on a two-line commandline

    for file in (path base<TAB>
    echo
2024-03-24 16:34:36 +01:00
Johannes Altmanninger
1216801474 Use RAII for restoring term modes
In particular, this allows restoring the terminal on crashes, which is
feasible now that we have the panic handler.  Since std::process::exit() skips
destructors, we need to reshuffle some code.  The "exit_without_destructors"
semantics (which std::process::exit() als has) was mostly necessary for C++
since Rust leaks global variables by default.
2024-03-24 16:34:36 +01:00
Johannes Altmanninger
3cfa09d1bd Make test_init() return a scope guard
To be used in the next commit.
2024-03-24 16:33:35 +01:00
Johannes Altmanninger
ecdc9ce1dd Install a panic handler to avoid dropping crash stacktraces
When fish crashes due to a panic, the terminal window is closed.  Some
terminals keep the window around when the crash is due to a fatal signal,
but today we don't exit via fatal signal on panic.

There is the option to set «panic = "abort"» in Cargo.toml, which
would give us coredumps but also worse stacktraces on stderr.
More importantly it means that we don't unwind, so destructors are skipped
I don't think we want that because we should use destructors to
restore the terminal state.

On crash in interactive fish, read one more line before exiting, so the
stack trace is always visible.

In future, we should move this "read one line before exiting" logic to where
we call "panic!", so I can attach a debugger and see the stacktrace.
2024-03-24 13:36:59 +01:00
Johannes Altmanninger
ccaf06e9d6 Fix incremental rebuild on added/deleted source file
Looks like "add_custom_command(OUTPUT ...)"  assumes the dependencies are
correct which is not always true. We can use "add_custom_target" to always
re-run Cargo.
2024-03-24 12:18:20 +01:00
Johannes Altmanninger
5c5ab4f179 Move termsize test into separate file 2024-03-24 12:18:20 +01:00
Johannes Altmanninger
99ffa4567a Remove unused import 2024-03-24 12:18:20 +01:00
Fabian Boehm
ec7c0e19d0 help: Always print what is used
Makes it easier to debug
2024-03-24 08:51:52 +01:00
Fabian Boehm
bdfa7341e7 help: Only use open on macOS
Unfortunately on Debian "open" is a symlink to "openvt", and there's
no way from outside to tell.

This prevents fish from failing because no browser could be found.
2024-03-24 08:48:58 +01:00
Johannes Altmanninger
c209e6b5fb Fix clippy lint 2024-03-23 14:26:08 +01:00
Johannes Altmanninger
58e477fab3 Changelog Vi mode changes
Closes #10338
2024-03-23 14:26:08 +01:00
Johannes Altmanninger
39ea1d710d Vi mode: add "+yy for fish_clipboard_copy and friends
Obviously not fully correct, and the implementation is not greate but it's
a start.
2024-03-23 14:24:51 +01:00
Johannes Altmanninger
25db4e803c Vi mode: don't cross newline on escape 2024-03-23 14:12:21 +01:00
Johannes Altmanninger
54b8817937 Vi mode: add + as clipboard alias, like * 2024-03-23 14:12:21 +01:00
Johannes Altmanninger
d51f669647 Vi mode: avoid placing cursor beyond last character
Today fish_cursor_selection_mode controls whether selection mode includes
the cursor. Since it's by default only used for Vi mode, perhaps use it to
also decide whether it should be allowed to select one-past the last character.

Not allowing to select to select one-past the last character is much nicer
in Vi mode.  Unfortunately Vi mode sometimes needs to temporarily select
past end (using forward-single-char and such), so reset fish_cursor_selection_mode
for the duration of the binding.

Also fix other things like cursor placement after yank/yank-pop.

Closes #10286
Closes #3299
2024-03-23 14:12:21 +01:00
Johannes Altmanninger
bffc9515a8 Fix bracketed paste regression from input event queue changes
We have

    bind --preset -M $mode --sets-mode paste \e\[200~ __fish_start_bracketed_paste

Commit c3cd68dda (Process shell commands from bindings like regular char
events, 2024-03-02) made it so __fish_start_bracketed_paste is no longer
executed before the bind mode is  updated.
This is a long-awaited fix but it broke __fish_start_bracketed_paste's
assumption that $fish_bind_mode is the mode before we entered paste mode.
This means we never exit paste mode.

Work around that. I forgot about this issue because I already replaced our
bracketed paste handling on my fork.
2024-03-23 14:08:55 +01:00
Fabian Boehm
b3ce8eee60 Remove some more C++-isms 2024-03-23 11:54:23 +01:00
Fabian Boehm
d99a5bae88 Remove trace of corrosion 2024-03-23 11:52:49 +01:00
Fabian Boehm
6eaaa3adc3 Revert "Try to fix OBS tumbleweed builds"
This was a misunderstanding, the OBS tumbleweed builds build from a tarball that's pushed manually.

We no longer use corrosion so this dependency is unused.

This reverts commit bdde2b2b35.

Fixes #10391
2024-03-23 11:51:19 +01:00
Pi-Cla
0cbac81130 Bump serial_test dependency to 1.0.0
The current version of serial_test we use (0.4.0)
depends on parking_lot 0.10.2 which in turn
depends on lock_api 0.3.4.
This version of lock_api is vulnerable to [RUSTSEC-2020-0070](https://rustsec.org/advisories/RUSTSEC-2020-0070)
This was patched in lock_api 0.4.2 but we need to update serial_test
to get the update.
2024-03-23 11:01:35 +01:00
Johannes Altmanninger
8baf7de4c0 Vi mode: remove stale comment 2024-03-23 10:38:28 +01:00
Johannes Altmanninger
0f758f12b7 environment.rs: minor cleanup 2024-03-23 10:38:28 +01:00
Johannes Altmanninger
789a280ee8 Fix {Alt,Shift}-Return bindings not expanding abbreviations
Today,

    bind foo "commandline -f expand-abbr; commandline -i \n"

does not work because this
1. enqueues an expand-abbr readline event
2. "commandline -i" inserts \n
3. processes the expand-abbr readline event

Since there is no abbreviation on the new line, this doesn't do anything.

PR https://github.com/fish-shell/fish-shell/pull/9398 would fix this
particular instance however it does not fix the issue that "commandline -i"
is run before the expand-abbr is processed by the reader. This is harmless
here but there would be a problem if "commandline" tried to read commandline
state that was created by a preceding command.

It's not super clear to me whether the above binding should work as one
would naively expect. That would imply that "commandline" would need to
drain all input events (at least all synthetic ones) from the input queue,
to ensure it sees the current state.

Fortunately the parent commit makes it so if we separate them

    bind foo "commandline -f expand-abbr" "commandline -i \n"

both will be separate events and the commandline state will be synced after
each of them. This fixes abbreviation expansion here.

Also, we can now mix readline cmds and shell commands, which makes it shorter.
2024-03-23 10:06:11 +01:00
Johannes Altmanninger
c3cd68dda5 Process shell commands from bindings like regular char events
A long standing issue is that bindings cannot mix special input functions
and shell commands. For example,

    bind x end-of-line "commandline -i x"

silently does nothing. Instead we have to do lift everything to shell commands

    bind x "commandline -f end-of-line; commandline -i x"

for no good reason.

Additionally, there is a weird ordering difference between special input
functions and shell commands. Special input functions are pushed into the
the queue whereas shell commands are executed immediately.

This weird ordering means that the above "bind x" still doesn't work as
expected, because "commandline -i" is processed before "end-of-line".

Finally, this is all implemented via weird hack to allow recursive use of
a mutable reference to the reader state.

Fix all of this by processing shell commands the same as both special input
functions and regular chars. Hopefully this doesn't break anything.

Fixes #8186
Fixes #10360
Closes #9398
2024-03-23 10:06:11 +01:00
Johannes Altmanninger
c1f601f31e Don't bind Alt-Return in Vi normal mode
It seems wrong because it's for text insertion; if someone actually wants
to use it we can add it back.
2024-03-23 09:54:18 +01:00
Johannes Altmanninger
865118e3b4 On Shift+Return, insert a newline instead of executing the commandline
Most chat programs I found use Shift+Return to insert a newline while plain
Return sends the message. One user reported having only tried Shift+Return
and not knowing about Alt+Return.

No release notes yet because this only works on a very small number of
terminals. Once we enable CSI u, this should work on most modern terminals.
2024-03-23 09:54:18 +01:00
Johannes Altmanninger
232483d89a History pager to only operate on the line at cursor
Multiline search strings are weirdly broken (inserting control characters
in the command line) and probably not very useful anyway.
On the other hand I often want to compose a multi-line command
from single-line commands I ran previously.

Let's support this case by limiting the initial search string to the current
line; and replace only that line.

Alternatively this could operate on jobs (that is, replace a surrounding
"foo | bar") instead of using line boundaries.
2024-03-23 09:54:18 +01:00
Johannes Altmanninger
299fcde808 Better link for POSIX test 2024-03-23 09:51:09 +01:00
Mahmoud Al-Qudsi
0ca199ef98 Change wopen_cloexec() to return File 2024-03-23 01:34:23 -05:00
Mahmoud Al-Qudsi
8d9d4ce1f9 Add and use separate open_dir() method
This is resistant to misuse by including O_DIRECTORY in the open flags and it is
a separate function from {w,}open_cloexec() in preparation for making that one
return a `File` instead of an `OwnedFd`.
2024-03-23 01:15:43 -05:00
Mahmoud Al-Qudsi
99c9d6eef6 IoFile: Wrap File instead of OwnedFd 2024-03-23 00:44:27 -05:00
Mahmoud Al-Qudsi
6f9f9ee400 Use bitflags contains() instead of intersects()
`intersects()` is "any of" while `contains()` is "all of" and while it makes no
difference when testing a single bit, I believe `contains()` is less brittle
for future maintenance and updates as its meaning is clearer.

</pedantic>
2024-03-23 00:24:31 -05:00
Mahmoud Al-Qudsi
6ed4d09c93 Switch more to File/BorrowedFd from OwnedFd/RawFd
More work in prep for having wopen_cloexec() return `File` directly.

This eliminates checking for an invalid fd and makes both ownership and
mutability clear (some more operations that involve changes to the underlying
state of the fd now require `&mut File` instead of just a `RawFd`).

Code that clearly does not use non-blocking IO is ported to use
`Write::write_all()` directly instead of our rusty port of the `write_loop()`
function (which handles EAGAIN/EWOULDBLOCK in addition to EINTR, while
`write_all()` only handles the latter).
2024-03-23 00:01:57 -05:00
Mahmoud Al-Qudsi
c0d68084f7 Add AsFd impl for AutoCloseFd
Will be used to remove RawFd usages.
2024-03-22 23:58:12 -05:00
Mahmoud Al-Qudsi
4e50ae34da Add native read_retry() and write_retry() methods
These are equivalent to read_loop() and write_loop() but operate on native Rust
types without libc ffi.
2024-03-22 23:05:56 -05:00
Mahmoud Al-Qudsi
bdde2b2b35 Try to fix OBS tumbleweed builds
Add git as a build requirement. Package name guessed then confirmed by searching
on rpm.pbone.net against openSUSE Tumbleweed.

Log excerpt:

[   14s] CMake Error at /usr/share/cmake/Modules/ExternalProject.cmake:2910 (message):
[   14s]   error: could not find git for clone of corrosion-populate
2024-03-22 22:42:58 -05:00
Fabian Boehm
a5156e9e0e po/de: Fix a format string 2024-03-21 20:17:14 +01:00
David Adam
9105d6a82f fish.spec: better installation of documentation
The %{_docdir} macro is defined, but due to an oversight is not passed
to CMake in some versions of openSUSE where it should be.

Use doc directives to avoid mucking around with cp.
2024-03-21 22:45:57 +08:00
David Adam
b64c210ade fish.spec: fix documentation path on OpenSUSE
(It's a shame the _docdir macro is unusuable, but even downstream
doesn't use it.)
2024-03-20 23:45:51 +08:00
Fabian Boehm
46cde6cc55 Github Actions: Remove CXXFLAGS for ASAN
The only C++ we have left is fish_test_helper
2024-03-19 16:54:33 +01:00
Fabian Boehm
0ff1e50a33 rustc: Protect against lines starting with -
Fixes #10379
2024-03-19 16:49:46 +01:00
Fabian Boehm
ce62b284b1 test_helper: Give self-signalling a chance to trigger
This abort()ed right after the signal, so it's possible to crash
before the signal is delivered. This could trigger under ASAN on
Github Actions.
2024-03-19 16:41:25 +01:00
Fabian Boehm
c759a98b37 docs: Clarify that disowned jobs won't fire on-process/job-exit
Fixes #10381
2024-03-19 16:39:37 +01:00
David Adam
a551432f5c Merge branch 'Integration_3.7.1' 2024-03-19 20:14:40 +08:00
Mahmoud Al-Qudsi
decf99f71b Use File instead of OwnedFd in a few places (#10355)
This is a step towards converting `wopen_cloexec()` to return `File` instead of
`OwnedFd`/`AutocloseFd`.¹

In addition to letting us use native standard library functions instead of
unsafe libc calls, we gain additional semantic safety because `File` operations
that manipulate the state of the fd (e.g. `File::seek()`) require a `&mut`
reference to the `File`, whereas using `RawFd` or `OwnedFd` everywhere leaves us
in a position where it's not clear whether or not other references to the same
fd will manipulate its underlying state.

¹ We actually wouldn't even need `wopen_cloexec()` at all (just a widechar
wrapper) as Rust's native `File::open()`/`File::create()` functionality uses
`FD_CLOEXEC` internally.
2024-03-17 11:20:44 -05:00
Johannes Altmanninger
bc246d87b2 Add closed issues and PRs to 3.8 changelog
I used below script to list all GitHub issues and PRs that are not yet
mentioned in the changelog. It's almost empty now.

While at it, curate the "notable" section and move some entries around,
notably from "interactive improvements"  to "bindings".

```shell
ms="fish next-3.x"
{
    gh issue list --state closed --milestone "$ms" -L 500
    gh pr list --state all --search "milestone:\"$ms\"" -L 500
} | sort -n | while IFS='
' read line; do
    set -- $line
    grep -qE '\W'$1 CHANGELOG.rst ||
    echo https://github.com/fish-shell/fish-shell/issues/$1 "$line"
done
```
2024-03-17 11:41:32 +01:00
Johannes Altmanninger
cd71359c42 completions/git: complete files iff last token is not a fixupish
Closes #10371
2024-03-16 10:45:57 +01:00
Simon Junod
60ef93b85b Fixed typo in French translations
Closes #10372
2024-03-16 10:45:57 +01:00
Johannes Altmanninger
068f92ce7e Changelog update 2024-03-16 10:31:01 +01:00
Johannes Altmanninger
2972407b9e builtin read: minor code cleanup 2024-03-16 10:31:01 +01:00
Johannes Altmanninger
62d1720605 completions/htop: fix --sort-key completions 2024-03-16 10:31:01 +01:00
fortifiedhill
8678ad8ca0 Update htop completions
Added and updated completions and updated htop link.
2024-03-16 09:00:42 +01:00
Xiretza
8271021fb6 Add completions for dmidecode 2024-03-16 08:57:43 +01:00
The0x539
b8d1dc93d6 ast: Replace can_parse with static dispatch 2024-03-16 08:39:27 +01:00
Andrew Neth
08220c2189 builtin/test: refactor the Token enum to be more granular (#10357)
* builtin/test: Split Token enum into 2-level hierarchy

* builtin/test: Rearrange the Token enum hierarchy

* builtin/test: Separate Token into Unary and Binary

* builtin/test: import IsOkAnd polyfill

* builtin/test: Rename enum variants one more time
2024-03-15 23:24:44 -05:00
Fabian Boehm
360342bb9e pexpect: Check for signalstatus being none
This would happen if e.g. the child shell did `exit 1` before an
`expect()`.
2024-03-12 22:04:23 +01:00
Fabian Boehm
0aa2426552 completions/wg-quick: Complete files after the subcommand
Fixes #10366
2024-03-12 17:32:51 +01:00
Fabian Boehm
a64a50db47 reader: Use our isatty overload
Removes an annoying use of unsafe
2024-03-10 20:47:26 +01:00
Fabian Boehm
ffc4372cad History: Change an assert into return None
I was able to trigger this by flipping around the history pager.

Since the only applicable caller here already stops if it gets None,
just don't assert.
2024-03-10 16:55:43 +01:00
Fabian Boehm
d3a66b2d96 translations: Remove tmpdir from location
This avoids changing the location every time you run fish_xgettext.
2024-03-10 16:40:58 +01:00
Fabian Boehm
074b96640d pager: Make search text translatable 2024-03-10 16:38:05 +01:00
Fabian Boehm
706b85d474 More german
These aren't *good*, but they are there and should be generally understandable.

I want to try to get 100% of src/ translated - that's ~440 messages.
2024-03-10 16:31:45 +01:00
Fabian Boehm
00c68145b8 fmt
I still hate this
2024-03-10 16:17:40 +01:00
Fabian Boehm
46b4ab92e5 Regenerate translations
Also add some more german
2024-03-10 16:15:16 +01:00
Fabian Boehm
25e170141c Fix some translated strings 2024-03-10 16:15:15 +01:00
Johannes Altmanninger
d8d491741b edit_command_buffer: preserve external editor's cursor position
Unless the editor changed to a different file for some reason.

Note that the Kakoune integration uses -always to export the cursor even if
the user temporarily suppressed hooks - possibly a "fish_indent" hook.
2024-03-10 11:08:12 +01:00
Johannes Altmanninger
5fa743337c edit_command_buffer: also detect aliases with arguments
For example

    complete my-vim --wraps 'vim -x'
2024-03-10 11:06:38 +01:00
Mahmoud Al-Qudsi
3f6b009870 Only update env_universal self.last_read_file on success
I don't think the existing logic is correct, as the comment says, our internal
state is only matched if we *actually* wrote out the file. But if we ran into an
error, it doesn't match, does it?
2024-03-10 09:49:54 +01: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
Mahmoud Al-Qudsi
7c173c4b45 Fix formatting of new test 2024-03-09 22:06:33 -06:00
Mahmoud Al-Qudsi
4e95a3713e Add test asserting stdlib uses O_CLOEXEC 2024-03-09 22:05:23 -06:00
Bartłomiej Maryńczak
d5cde80447 Use Result for write_to_fd return value (#10308) 2024-03-09 21:29:50 -06:00
Mahmoud Al-Qudsi
e6687dc61f Make open_temporary_file() fallible again
I was under the apparently mistaken impression that `FLOG!(error, ...)`
triggered an abort when I committed 58a6eb6e45.
2024-03-09 21:21:29 -06:00
amiyzku
bb6b3101ff Shortened some which.fish completions. (#10347)
* Shortened some which.fish completions.

* improve descriptions for which command options
2024-03-09 20:52:55 -06:00
RomainGiraud
f8757d154c Fix scp completion for WSL (with ssh.exe) (#10290)
* Fix scp completion for WSL (with ssh.exe)

* Be more explicit
2024-03-09 15:39:57 -06:00
Mahmoud Al-Qudsi
6d30363090 Simplify control flow in env_universal_common::save() 2024-03-09 15:21:47 -06:00
Mahmoud Al-Qudsi
58a6eb6e45 Convert fish_mkstemp_cloexec() to return an OwnedFd 2024-03-09 15:21:47 -06:00
The0x539
cfe9881eaa Suppress unknown_lints lint
This is to prevent stable from complaining about nightly-only lints.

Closes #10354
2024-03-09 13:49:25 +01:00
The0x539
6c0381c335 Suppress assigning_clones and incompatible_msrv
The incompatible_msrv one is a false positive because we have polyfills for
is_some_and() and is_ok_or() which are Rust 1.74. I'm not yet sure how to
communicate that to Clippy.
2024-03-09 13:49:25 +01:00
The0x539
4296c49a06 Remove unnecessary scoped #[allow] attributes 2024-03-09 13:49:25 +01:00
The0x539
4c3e814a50 Address clippy lints 2024-03-09 13:49:25 +01:00
Fabian Boehm
6869b14fb5 docs: Add fish_should_add_to_history to commands list 2024-03-09 12:09:00 +01:00
Fabian Boehm
b03e727531 Remove unnecessary formatting 2024-03-09 12:06:24 +01:00
Fabian Boehm
f7cc1743c6 Allow deciding if a command should be saved to history (#10302)
Call fish_should_add_to_history to see if a command should be saved

If it returns 0, it will be saved, if it returns anything else, it
will be ephemeral.

It gets the right-trimmed text as the argument.

If it doesn't exist, we do the historical behavior of checking for a
leading space.

That means you can now turn that off by defining a
`fish_should_add_to_history` that just doesn't check it.

documentation based on #9298
2024-03-09 12:04:16 +01:00
Fabian Boehm
d91ad2976c Make fish_xgettext sorta work with rust
This is absolutely disgusting code, but it works out okay-ish.

The problem is xgettext has no rust support (it's stuck in review
limbo). So we use cargo-expand to extract all invocations of
gettext, and massage all that to generate a
messages.pot ourselves.

We also assume any string constant could be translated.
2024-03-09 11:48:29 +01:00
Fabian Boehm
97e7e730e1 Clean up two awkward wgettext_fmt invocations 2024-03-09 11:48:29 +01:00
Johannes Altmanninger
836ee93617 Vi bindings: Control-N to accept autosuggestion
One of the things that keep me from using Vi mode is that it doesn't define an
insert-mode shortcut to accept autosuggestions. Let's use Control-N because
that Vim key is the closest equivalent.

Closes #10339
2024-03-09 11:03:57 +01:00
QianChenglong
b3c610feff add completion for mycli
Closes #10309
2024-03-09 10:28:03 +01:00
Felix Luciano Salomon
90b9bce174 Added completion for ollama
Closes #10327
2024-03-09 10:28:03 +01:00
The0x539
1de7ebcf68 Simplify shared-from-this pattern 2024-03-09 10:09:03 +01:00
Peter Collingbourne
e5f83cd9a7 Fix logic for relocatable directory trees
The existing logic did not work because:

- Path::new("/foo/bar").ends_with("/bar") does not return true.
- PathBuf::shrink_to() only (potentially) reallocates the backing
  storage, and won't have an effect on the stored value.
2024-03-09 09:38:48 +01:00
Next Alone
a1d44a92be fix: #10184 causes adb file completion failures (#10349)
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2024-03-08 21:56:37 -06:00
Johannes Altmanninger
6eddaa37af Revert "feat: adb completion cleared of awk"
It's broken,  see https://github.com/fish-shell/fish-shell/pull/10184
and doesn't really help I don't think.

This reverts commit ee837f254b.
2024-03-08 07:33:18 +01:00
John
b75e5ee823 remove repetitive words (#10348)
Signed-off-by: hishope <csqiye@126.com>
2024-03-07 18:35:41 -06:00
Mahmoud Al-Qudsi
80133c4bc6 Fix safety issues with some static variables (#10329)
Add safe Send/Sync wrapper for main thread data
2024-03-05 12:33:13 -06:00
TAKAHASHI Shuuji
3c7b2af442 docs: Correct default value of read function in read.rst 2024-03-04 17:49:47 +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
ff6fd699fe Fix a warning about an unused import on macOS 2024-03-03 14:12:59 -08: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
721a360707 cmake: Remove a bunch of unnecessary code
We are no longer C++, we no longer support xcode

Note: This will remove a warning "DO NOT EDIT" comment from __fish_build_paths.fish, but
that's unnecessary. The file is typically in /usr or another
package-manager-owned location, so people don't typically edit it.

And if it did we don't actually *care*, it'll work fine.
2024-03-03 20:36:24 +01:00
Johannes Altmanninger
33a7172ee8 Revert to not inserting control characters from keyboard input
As mentioned in the comment the historical behavior is because pressing unknown
control characters like Ctrl+4 inserts confusing characters, so let's back
out that part of b77d1d0e2 (Stop crashing on invalid Unicode input, 2024-02-27).

We still have the code for rendering control characters, for pasted text,
or text recalled from history. It is unclear whether we should strip those.
Some terminals already strip control characters from pasted text -- but not
all of them: see https://codeberg.org/dnkl/foot/pulls/312 for example which
has a follow up called "Don't strip HT when pasting in non-bracketed mode".
2024-03-02 23:31:08 +01:00
Fabian Boehm
2a4e776d92 Reimplement git version generation ourselves
This allows us to remove two dependency crates
2024-03-02 10:05:37 +01:00
Mahmoud Al-Qudsi
1ac17756c2 Also address safety issues with principal_parser() 2024-03-01 19:54:28 -06:00
Mahmoud Al-Qudsi
2ecbc56de9 Change MainThread<T> abstraction
Don't force the internal use of `RefCell<T>`, let the caller place that into
`MainThread<>` manually. This lets us remove the reference to `MainThread<>`
from the definition of `Screen` again and reduces the number of
`assert_is_main_thread()` calls.
2024-03-01 19:42:43 -06:00
zuisong
a1e46a94f6 Add --url-query completion for curl (#10332)
Add missing completion for curl's `--url-query` option
2024-02-29 12:09:51 -06:00
Mahmoud Al-Qudsi
5c94ebd095 Fix output::stdoutput() safety issues
Fairly straightforward, with the only unfortunate part of this being that
`Screen` isn't as pure and now encodes the facte that we use it with
main-thread-only stdout `Outputter`.
2024-02-29 11:29:37 -06:00
Mahmoud Al-Qudsi
f67ce2ac4b Add Sync/Send wrapper for main-thread-only data 2024-02-28 13:06:04 -06:00
Fabian Boehm
29af775390 abbr: Box the regex
The regex struct is pretty large at 560 bytes, with the entire
Abbreviation being 664 bytes.

If it's an "Option<Regex>", any abbr gets to pay the price. Boxing it
means abbrs without a regex are over 500 bytes smaller.
2024-02-28 18:48:24 +01:00
Fabian Boehm
3d1e8a6106 pager: Simplify some code 2024-02-28 18:34:57 +01:00
Fabian Boehm
31c2eb3f3c pager: Use selected color for parentheses if applicable
This always used pager_completion even for the selected one, now it
uses pager_selected_completion for that.

Fixes #10328
2024-02-28 18:14:05 +01:00
Fabian Boehm
5641ae71b8 ast: Box a large enum variant
IfStatement is 680 bytes, much larger than the other
variants (SwitchStatement is next at 232). An enum is as large as its
largest variant, so this saves a bunch, especially since
DecoratedStatement is much more likely than IfStatement.

This will speed up the no-execute benchmark by 1.07x.
2024-02-28 18:14:05 +01:00
Mahmoud Al-Qudsi
e7b94454df Add unsafety warnings
See https://github.com/rust-lang/rust/issues/114447
2024-02-28 10:09:53 -06:00
Mahmoud Al-Qudsi
5eb6b22fa4 Allow unused fns in ConcreteNodeMut 2024-02-28 09:44:11 -06:00
Mahmoud Al-Qudsi
50ff6b8a34 Remove using statements already imported by preludes 2024-02-28 09:41:51 -06:00
Johannes Altmanninger
b77d1d0e2b Stop crashing on invalid Unicode input
Unlike C++, Rust requires "char" to be a valid Unicode code point.  As a
workaround, we take the raw (probably UTF-8-encoded) input and convert each
input byte to a char representation from the private use area (see commit
3b15e995e (str2wcs: encode invalid Unicode characters in the private use
area, 2023-04-01)).  We convert back whenever we output the string, which
is correct as long as the encoding didn't change since the data was input.

We also need to convert keyboard input; do that.

Quick testing shows that our reader drops PUA characters.  Since this patch
converts both invalid Unicode input as well as PUA input into a safe PUA
representation, there's no longer a reason to not add PUA characters to
the commandline, so let's do that to restore traditional behavior.

Render them as � (REPLACEMENT CHARACTER); unfortunately we show one per
input byte instead of one per code point. To fix this we probably need our
own char type.

While at it, remove some special cases that try to prevent insertion of
control characters. I don't think they are necessary. Could be wrong..
2024-02-27 22:59:49 +01:00
Fabian Boehm
f60b6e6cd4 CHANGELOG 2024-02-27 16:28:20 +01:00
Fabian Boehm
78c9482822 Reformat share/**.fish with newlines collapsed 2024-02-27 16:25:01 +01: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
Mathis Chenuet
73d760560b Add completion for pstree (#10317)
* Add completion for pstree.fish

* use fish functions, much better
2024-02-26 17:39:11 +01:00
Fabian Boehm
f87c892ed8 Update cc dependency
Removes annoying "running cc --version" and such debug messages.
2024-02-26 16:17:47 +01:00
Fabian Boehm
d0cf07c4b3 Format __fish_cache_sourced_completions 2024-02-26 16:17:47 +01:00
may
66aab66670 add recent commits to completion for git diff (#10321) 2024-02-25 14:36:05 -06:00
Fabian Boehm
46b7e91c91 Update deps
Notably this removes the jobserver dependency
2024-02-24 10:07:47 +01:00
Fabian Boehm
f62f1aaf99 Remove remaining mentions of curses 2024-02-23 16:36:10 +01:00
Fabian Boehm
8712bd5a4b CHANGELOG terminfo 2024-02-22 20:15:24 +01:00
Fabian Boehm
c408342d65 CI: Install terminfo-db on FreeBSD 2024-02-22 20:10:16 +01:00
Fabian Boehm
da6a9bad5f Add additional paths for NetBSD and Nix
These seems weird to add upstream, and we might want to read
more here.
2024-02-22 20:10:16 +01:00
Fabian Boehm
785d784482 Make term warning less shouty
We don't need to know that it tried these five before finally getting
one, the list is *right there*.

It is also very unlikely that someone has "xterm" or "ansi" but not "xterm-256color"

For xterm-256color, we don't warn *at all* because we have that one hardcoded.
2024-02-22 20:10:16 +01:00
Fabian Boehm
75f7cda6ab Add xterm-256color fallback
And use it if $TERM is xterm-256color and could not be found, *without* warning.

These barely change, especially in the parts we use.
2024-02-22 20:10:16 +01:00
Fabian Boehm
8c86336109 Remove useless use of cstring 2024-02-22 20:10:16 +01:00
Fabian Boehm
57317fdaf2 Remove now unused assert helpers 2024-02-22 20:10:16 +01:00
Fabian Boehm
fc794bab4c Switch to the terminfo crate
This allows us to get the terminfo information without linking against curses.

That means we can get by without a bunch of awkward C-API trickery.

There is no global "cur_term" kept by a library for us that we need to invalidate.

Note that it still requires a "unhashed terminfo database", and I don't know how well it handles termcap.

I am not actually sure if there are systems that *can't* have terminfo, everything I looked at
has the ncurses terminfo available to install at least.
2024-02-22 20:10:16 +01:00
Mahmoud Al-Qudsi
2c2ab0c1fa Always source file after funced (#10318)
... even if the file hasn't changed. This addresses an oddity in the following
case:

* Shell is started,
* function `foo` is sourced from foo.fish
* foo.fish is *externally* edited and saved
* <Loaded definition of `foo` is now stale, but fish is unaware>
* `funced foo` loads `type -p foo` showing changed definition, user exits
  $EDITOR saving no changes (or with $status 0, more generally).
* Stale definition of `foo` remains
2024-02-22 12:45:20 -06:00
Jadi
e207f8464e Make descriptions shorter: iex, jhipster, lpadmin, mocp, rmmod 2024-02-22 18:59:08 +01:00
Jason Nader
fc58b9c68f completions: add ssh -D option 2024-02-22 18:58:04 +01:00
Paul Gier
6c9c033126 functions: handle hostname starting with dash
If a hostname starts with a dash `-` character, the prompt_hostname function
fails because the `string` function interprets it as an option instead
of an argument.
2024-02-22 21:21:31 +08:00
Jason Nader
2f332f0019 completions: update 'echo' 2024-02-20 17:40:35 +01:00
Fabian Boehm
b7cc7db93c fish_key_reader: Remove unnecessary parser
I have no idea what this would be used for, it's instantiated, we set
is_interactive, and then we never use it.
2024-02-20 16:55:32 +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
Fabian Boehm
8667ed5c17 fish_git_prompt: Count type changes as dirty too
Fixes #10305
2024-02-17 08:37:22 +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
0d9c737a47 builtins/history: Remove unnecessary unwrap 2024-02-16 19:40:42 +01:00
Fabian Boehm
46afbea72b exec: Pass some cstrs as cstr instead of converting to ptr and back 2024-02-16 19:40:41 +01:00
Fabian Boehm
7e8a4dbe5c highlight: Stop copying pending variables 2024-02-16 19:40:41 +01:00
Fabian Boehm
1160bf84ed input: Resolve a TODO 2024-02-16 19:40:39 +01:00
Fabian Boehm
035948eb2f Correct and shorten a comment
There is no more "input.cpp"
2024-02-16 19:11:45 +01:00
Fabian Boehm
983af732dd Add test for history pager crash 2024-02-16 18:43:16 +01:00
Fabian Boehm
9ff02d6a7f Fix crash in the history pager
Delete the last shown entry and it'll subtract with overflow
2024-02-16 18:22:37 +01:00
Johannes Altmanninger
26ea024e74 completions/xdg-mime: fix off-by-one error and allow multiple filetypes 2024-02-16 07:45:22 +01:00
Johannes Altmanninger
2915c525fa Revert "history: Skip lines with tabs when importing from bash"
We still don't support tabs but as of the parent commit, there are no more
weird glitches, so it should be fine to recall those lines?

This reverts commit cc0e366037.
2024-02-15 01:39:45 +01:00
Johannes Altmanninger
0627c9d9af Render control characters as Unicode Control Pictures
Inserting Tab or Backspace characters causes weird glitches. Sometimes it's
useful to paste tabs as part of a code block.

Render tabs as "␉" and so on for other ASCII control characters, see
https://unicode-table.com/en/blocks/control-pictures/. This fixes the
width-related glitches.

You can see it in action by inserting some control characters into the
command line:

	set chars
	for x in (seq 1 0x1F)
		set -a chars (printf "%02x\\\\x%02x" $x $x)
	end
	eval set chars $chars
	commandline -i "echo '" $chars

Fixes #6923
Fixes #5274
Closes #7295

We could extend this approach to display a fallback symbol for every unknown
nonprintable character, not just ASCII control characters.

In future we might want to support tab properly.
2024-02-15 01:39:45 +01:00
Johannes Altmanninger
d3b700f98c Promote debug-only assertion 2024-02-15 01:27:23 +01:00
Johannes Altmanninger
a1ed63fd83 Make wcwidth an isize
Seems more consistent with the rest of our code.
2024-02-15 01:27:23 +01:00
Johannes Altmanninger
8545b5debe Remove obsolete no_mangle directives 2024-02-15 01:22:37 +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
Johannes Altmanninger
2137467f0b Trigger rebuild if builtin source changes 2024-02-12 22:28:29 +01:00
ridiculousfish
e1d539c7b6 Stop using errno for input_terminfo_get_sequence errors
Use a real error type. Fixes a TODO and cleans up the code.
2024-02-11 15:03:27 -08:00
ridiculousfish
5021639db1 Correct some comments and duplicative error messages
If we fail to create a pipe, we will report that fact in multiple places; remove
some redundant error reporting.
2024-02-11 12:16:58 -08:00
PolyMeilex
b9ba9e57e8 Use nix & Results 2024-02-11 11:40:27 -08:00
PolyMeilex
971d774e67 Use OwnedFd in AutoClosePipes 2024-02-11 11:40:27 -08:00
David Adam
59fe52851e CMake: add entry point to binary dependency 2024-02-11 21:07:43 +08:00
David Adam
7dfe6f2c07 common.rs: drop unused PACKAGE_BUGREPORT constant 2024-02-11 21:06:37 +08:00
Henrik Hørlück Berg
59fa7479ee Add documentation and release notes for #10282 2024-02-11 12:43:13 +01:00
Himadri Bhattacharjee
4e6e897781 string repeat: allow omission of -n (#10282) 2024-02-11 12:19:02 +01:00
Fabian Boehm
662fde7b71 Error out when share/config.fish can't be read
This file contains important configuration, so if we can't get it
something is broken.

We don't *exit*, but we will stop reading configuration.
2024-02-10 20:54:22 +01:00
Emily Grace Seville
623f3463a5 feat: cobra-cli support (#10293)
* feat: cobra-cli support

* fix: cobra-cli completion
2024-02-10 16:52:31 +01:00
Fabian Boehm
06426604b7 cmake: Remove rlib, let cargo build directly
This removes an extra step, should hopefully save some time.
2024-02-10 16:31:54 +01:00
Fabian Boehm
ed59cbe536 ast: Only reserve 16 nodes for each list
This reserved 64, which is *gigantic*.

Over all of share/**.fish, 75% of lists are empty, 99.97% are 16
elements or fewer.

Reducing this to 16 reduces memory usage for a gigantic example
script (git.fish pasted a bunch of times for a total of almost 100k
lines) by ~10% and speeds up "--no-execute" time by the same amount.

For smaller scripts it's less noticeable simply because parse time
matters less.

There are other options, like creating the vec ::with_capacity, or
using 8 instead of 16, or even letting the vec just grow
naturally (rust's vec currently grows from 0 to 4 and then doubles,
which isn't terrible for this use), but the point is that 64 is
wasteful and never comes out on top, always in the last two places
comparing a bunch of choices.
2024-02-10 11:33:32 +01:00
David Adam
2bc197fe74 cmake: add -g to existing RUSTFLAGS if required
Makes it possible to use the sanitizers again.

Note that this requires RUSTFLAGS to be set when running CMake, and will not be
updated when running the build system if the environment variable changes.
2024-02-08 00:28:30 +08:00
Simon Börjesson
7768952749 Reset scroll position when clearing pager
Closes #10288
2024-02-07 02:57:34 +01:00
Simon Börjesson
d51ecb7fb3 Scroll down to reveal the selected item after expanding pager 2024-02-07 02:57:19 +01:00
Johannes Altmanninger
47aa79813d Open command script in external editor on Alt+o
Fish functions are great for configuring fish but they don't integrate
seamlessly with the rest of the system. For tasks that can run outside fish,
writing scripts is the natural approach.

To edit my scripts I frequently run

    $EDITOR (which my-script)

Would be great to reduce the amount typing for this common case (the names
of editor and scripts are usually short, so that's a lot of typing spent on
the boring part).

Our Alt+o binding opens the file at the cursor in a pager.  When the cursor
is in command position, it doesn't do anything (unless the command is actually
a valid file path). Let's make it open the resolved file path in an editor.

In future, we should teach this binding to delegate to "funced" upon seeing
a function instead of a script. I didn't do it yet because funced prints
messages, so it will mess with the commandline rendering if used from
a binding.  (The fact that funced encourages overwriting functions that
ship with fish is worrysome. Also I'm not sure why funced doesn't open the
function's source file directly (if not sourced from stdin). Persisting the
function should probably be the default.)

Alternative approach: I think other shells expand "=my-script" to
"/path/to/my-script".  That is certainly an option -- if we do that we'd want
to teach fish to complete command names after "=".  Since I don't remember
scenarios where I care about the full path of a script beyond opening it in
my editor, I didn't look further into this.

Closes #10266
2024-02-07 00:07:47 +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
Johannes Altmanninger
144df899f5 Remove some obsolete comments 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
Fabian Boehm
70a5267682 Make any character insertion end history search
Currently, if you enter `echo` and press up-arrow, it might select
e.g. `echo foo`.

You can then enter text, making it `echo foobar` and press up-arrow
again, but the search string is *still* `echo`.

Many *other* input functions will end history search, including e.g.
expand-abbr, so pressing space by default will already end it.

So this ends the history search once you input something.

Incidentally this allows suggestions to work in this case, so it

Fixes #10287

Note that autosuggestions have been disabled while history search is
active since a08450bcb6, I'm not sure
it's actually *needed*, so it would also be possible to enable it in
that case.

But since this is already awkward (history search is *active* but with
the old search string) and I'm not sure if e.g. suggestions during
history search would be too busy, let's do this first.
2024-02-06 17:35:22 +01:00
David Adam
698be5b9fe cmake: make binaries depend on generated library
Fixes incremental builds by removing the custom target
2024-02-06 20:48:38 +08:00
Fabian Boehm
ea5adcac9d CHANGELOG: Work on next release
Including some preliminary bits on packaging.
2024-02-04 09:47:21 +01:00
Fabian Boehm
168d567250 cmake: Make default build type Debug
With LTO, Release builds are now a lot slower.
For development debug builds are much nicer.

We'll ask packagers to pass Release when building a package.
2024-02-04 09:46:05 +01:00
Fabian Boehm
94d3307469 docs/argparse: Add some more examples, something on -x
Fixes #10284
2024-02-03 21:41:50 +01:00
Fabian Boehm
f8da013f33 docs/prompt: A few small fixes
`set_color` does *just* the formatting, the string to color needs to
be added separately
2024-02-03 11:12:11 +01:00
Fabian Boehm
8e73a4c5af cmake: Do add dependencies
Unfortunately ninja does not want to be tricked.

I tried `touch`ing a file and writing the date to a file,
and even removing that file before cargo runs, it doesn't work.

So instead we'll do the imperfect solution of enumerating sources.

And yes, we use a GLOB because listing source files is terrible.
Any build system that wants you not to glob is a build system made for
build system people who like touching build systems, not me.
2024-02-03 09:57:11 +01:00
Johannes Altmanninger
d9381d1ab6 Use default number of codegen units in release build
The default codegen units is 16 but we set it to 1*.  On my system, this
saves 0.1 MB (2%) in the unstripped binary, while adding 10s (20%) to the
build time.  This doesn't seem worth, better stick to the defaults.

[*] along enabling fat LTO which is debatable too
2024-02-03 08:02:59 +01:00
Johannes Altmanninger
f8ca2b0419 Revert "Bump CMake version for IMPORTED_RUNTIME_ARTIFACTS"
This reverts commit fdc45452b6.

We no longer depend on IMPORTED_RUNTIME_ARTIFACTS.
2024-02-03 08:02:36 +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
Daniel Kahn Gillmor
b265152fba tab completions: avoid completing gpg --use-embedded-filename
gpg's --use-embedded-filename is a dangerous option that can cause gpg
to write arbitrary content to arbitrary files.

According to the GnuPG maintainer, this is not an option recommended
for use (https://dev.gnupg.org/T4500).  Fish shouldn't encourage users
to supply it.

I've offered https://dev.gnupg.org/T6972 to upstream to make it even
more clear that this option is a bad idea.

While removing it, we might as well also remove
--no-use-embedded-filename, since it is effectively a no-op.
2024-02-02 21:57:55 +01:00
Fabian Boehm
7c0cc2d2ab cmake: It seems like always_rebuild needs to output something 2024-02-02 21:44:54 +01:00
Fabian Boehm
5d2d44feed Reduce some numbers to make cargo test run faster
This reduces the test time by ~33% on my system (23s to 15s)

Given that it takes ~180-240s on Github Actions, if we get a reduction
like that we can save over a minute.
2024-02-02 16:44:36 +01:00
Fabian Boehm
bcebcdc0ad CI: Run macOS tests as debug
These are dog-slow at building, and the tests themselves are barely
sped up running as release.

Given that we have ~10 minute build and ~3 minute test time on Github
Actions on macOS, let's see if this speeds it up

(we can also do it for the others, but the most important is the
slowest test because that's what stops the checkmark appearing)
2024-02-02 16:16:08 +01:00
Fabian Boehm
36efb1ce48 cmake: Fix incremental build
This just always reruns cargo, which is fine.
2024-02-02 16:00:04 +01:00
Fabian Boehm
67a3aaa66a Remove uses of LC_GLOBAL_LOCALE
We only use this

1. if we have localeconv_l
2. to get the decimal point / thousands separator for numbers

So we can ignore all this and directly create a purely LC_NUMERIC locale.

This *was* more useful when we were in C++ and the printing functions
all relied on locale, but we only use this in printf and that only
extracts the number stuff.
2024-02-01 22:15:24 +01:00
Fabian Boehm
d50b614250 fish_key_reader: fix off-by-one crash 2024-02-01 21:42:55 +01:00
Mahmoud Al-Qudsi
cf3d3f6497 Fix incremental compilation of src/libc.c with cargo
src/libc.c changes were not being picked up.
2024-02-01 13:51:04 -06:00
Mahmoud Al-Qudsi
c53a494f52 libc.c: Include xlocale.h under macOS 2024-02-01 13:45:11 -06:00
Fabian Boehm
c959bcbb57 Remove one more #cfg 2024-02-01 20:23:07 +01:00
Fabian Boehm
640e25d557 Remove missed #cfg that prevented build on NetBSD 2024-02-01 20:21:33 +01:00
Mahmoud Al-Qudsi
5169302303 Make LC_GLOBAL_LOCALE shim less brittle
Make sure the function is defined on all platforms, and don't split conditional
compilation logic between C and rust.
2024-02-01 13:16:32 -06:00
Fabian Boehm
a9a70e0149 Clippy: Allow "manual_range_contains"
This complains that `scale < 0 || scale > 15` should be

`!(0..=15).contains(&scale)`

and I'm sorry, but no. Just no.
2024-02-01 19:52:32 +01:00
Fabian Boehm
d3fd815eb3 Use set_flog_file_fd via import 2024-02-01 19:41:13 +01:00
Fabian Boehm
caac869b6e Use a normal File for debug-output
Like the TODO said, we no longer need this.
2024-02-01 19:06:27 +01:00
Fabian Boehm
76a80a0678 Remove unneeded second UVARS global
This was apparently never used
2024-02-01 17:35:44 +01:00
Theodore Ehrenborg
263197dcb7 Typo 2024-01-31 08:06:34 +01:00
Demian Ferreiro
bbbef75978 Fix rounding error on math docs 2024-01-30 20:12:56 +01:00
David Adam
cb46396b67 cmake: build executables by driving cargo directly
Drops the requirement for Corrosion, as almost none of its extensive features
are required.
2024-01-30 18:18:55 +08:00
David Adam
7d33f6706f Import FindRust from Corrosion 2024-01-30 18:18:55 +08: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
Mahmoud Al-Qudsi
6f0894c652 macOS: Fix warning reintroduced in 2ca102193c 2024-01-28 18:33:24 -06:00
Mahmoud Al-Qudsi
f16c132f3c Fix unused import when pipe2 isn't available 2024-01-28 18:33:11 -06:00
Mahmoud Al-Qudsi
99bd2e71d0 Unify how file mode is specified
The lines of code I commented on in #10254 were meant to serve only as examples
of the changes I was requesting, not the only instances.

Also just use `Mode::from_bits_truncate()` instead of unsafe or unwrapping since
we know the modes are correct.
2024-01-28 18:09:52 -06:00
Fabian Boehm
6877773fdd Fix build on NetBSD (#10270)
* Fix build on NetBSD

Notably:

1. A typo in `f_flag` vs `f_flags` - this was probably never tested
2. Some pointless name differences  - `st_mtimensec` vs
`st_mtime_nsec`
3. The big one: This said that LC_GLOBAL_LOCALE() was -1 "everywhere".
   Well, not on NetBSD.

* ifdef for macos
2024-01-28 21:45:14 +01:00
Mahmoud Al-Qudsi
45285b3870 Refactor error handling in binary_semaphore_t 2024-01-28 12:43:53 -06:00
Bartłomiej Maryńczak
2ca102193c Statically type binary_semaphore_t mode of operation (#10272)
* Cleanup binary_semaphore_t by removing `sem_ok_` checks

* Fix unused import on non-Linux platforms

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2024-01-28 12:21:15 -06:00
Fabian Boehm
a03162bd5b Update dependencies 2024-01-28 14:23:16 +01:00
Fabian Boehm
aa5649ca99 Add # as a path component char
Fixes #10271
2024-01-28 10:41:15 +01:00
PolyMeilex
05ac1b770c Use AsFd for maybe_lock_file 2024-01-27 20:42:13 +01:00
PolyMeilex
341fd7ca16 Revert to octal mode repr in autoload and io 2024-01-27 20:42:13 +01:00
PolyMeilex
6ef8125c96 Return OwnedFd from open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
2512849ece Use nix OFlag for open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
6915aeb44c Use nix mode for open_cloexec 2024-01-27 20:42:13 +01:00
PolyMeilex
23301e4895 Return Result from wopen_cloexec 2024-01-27 20:42:13 +01:00
bitraid
86afc7832d Call fish_vi_cursor_handle also for interactive read
Not doing this results in the cursor not being initially set for `read`.
2024-01-27 20:13:47 +01:00
bitraid
a5dfa84f73 fish_vi_cursor: skip if stdin is not a tty
Instead of skipping for non-interactive shells, skip when stdin is not a tty.
This allows the cursor to be set for scripts that use the `read` command.
2024-01-27 20:13:47 +01:00
Johannes Altmanninger
33a9659cd1 Fix stale name of --tokens-expand option
Missed in 368017905 (builtin commandline: -x for expanded tokens, supplanting
-o, 2024-01-06).
2024-01-27 20:09:33 +01:00
Fabian Boehm
1deb065f59 build.rs: canonicalize CARGO_MANIFEST_DIR
We use this so you can run fish from the build directory and it picks
up its data files.

If this wasn't canonicalized, that would break if you're building with
a $PWD through a symlink.
2024-01-27 20:00:10 +01:00
Daniel Bretoi
6f797ac958 Update just.fish to handle descriptions for completions (#10260)
* Update just.fish to handle descriptions for completions

This change updates fish completions to also include descriptions for justfile recipes. It has been tested with descriptions for recipes with arguments as well

* rely on fish only (avoid sed)
2024-01-27 18:58:24 +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
Fabian Boehm
677e4ff698 anypython: Add more versions 2024-01-27 18:47:38 +01:00
Fabian Boehm
c735dafb98 tests: Exit early if python is missing for littlecheck 2024-01-27 18:47:38 +01:00
Fabian Boehm
019a082d5d Remove unused import 2024-01-27 18:47:38 +01:00
Johannes Altmanninger
9a1226684e Fixup formatting 2024-01-27 18:08:02 +01:00
Johannes Altmanninger
37c380d885 completions/git: add send-email 2024-01-27 17:57:48 +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
033f64fde6 Fix indentation in bitflags macro 2024-01-27 17:57:48 +01:00
Johannes Altmanninger
623ad21b47 Remove code clone in completion insertion 2024-01-27 17:57:48 +01:00
Fabian Boehm
1e5a585875 builtins: Remove some uses of .unwrap()
.unwrap() is in effect an assert(). If it is applied mistakenly, the
program crashes and there isn't a good error.

I would like it to be used as a last resort. In these cases there are
nicer ways to do it that handle a missing result properly.
2024-01-27 16:06:36 +01:00
Jason Nader
28d9f1878d completions: fix wg-quick interface completions
wg outputs space separated list
2024-01-27 11:40:57 +01:00
Johannes Altmanninger
5f459446a8 functions/funced: harmonize interpretation of VISUAL/EDITOR
Like other tools, we split $EDITOR by spaces and remove backslashes in Alt+e
and Alt+o but not in funced. Let's' fix this inconsistency.
2024-01-27 09:38:51 +01:00
Johannes Altmanninger
a9618477ec Merge branch 'completions-to-use-expanded-tokens'
The grandparent commit has a regression which is fixed by the parent, hence
the merge commit to communicate the grouping.
2024-01-27 09:36:07 +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
798527d79a completions: fix double evaluation of tokenized commandline
Fix cases like

    eval my-cmd (commandline -o)
    complete -C "my-cmd $(commandline -o)"

In both cases, we spuriously evaluate tokens like "(inside-quoted-string)"
as command substitutions. Fix this by escaping the strings.  The momentarily
regresses the intended purpose of "eval" -- to expand variables -- but the
next commit will fix that.
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
David Adam
9ac5e79e46 CI: use make VERBOSE=1 everywhere
Having visible build commands helps reproducibility.
2024-01-26 07:33:24 +08:00
Fabian Boehm
b8b062eb84 docs: Update qmark-noglob status
Note: The version number needs to be adjusted
2024-01-25 18:47:41 +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
Fabian Boehm
ac9c5ed1b2 Retry open_cloexec for signals other than SIGINT
Fixes #10250
2024-01-25 11:14:31 +01:00
Mahmoud Al-Qudsi
ea980c19db Make string_tests.rs deterministic regardless of qmark-noglob
Move all qmark tests to `scoped_test()` sections with explicitly set feature
flags. We already test the default qmark behavior in the functionality tests.
2024-01-24 22:42:02 -06:00
Mahmoud Al-Qudsi
34a5443cfd Disable ? as a glob by default
aka, enable the qmark-noglob feature by default.
2024-01-24 21:17:36 -06:00
ridiculousfish
42bb4b55d3 Add default-run = fish to Cargo.toml
This makes fish the default binary, so that "cargo run" will launch fish.
2024-01-23 19:49:35 -08:00
Fabian Boehm
f7b57065db docs/command: Simplify
This prefers `-s` to `-v` - we have a *lot* more uses of `command -s`, it's the easier
mnemonic *and* the more compatible-with-fish option.

Also we don't really need the separate section that explains what
these options do *again*.
2024-01-22 21:44:59 +01:00
Daniel Bretoi
c78750499d Dynamic Completion for Justfile Recipes (#10244)
* Create just.fish

justfile completions for tasks similar to make completions for targets

* no need for the match at all
2024-01-22 20:13:10 +01:00
Asuka Minato
0f97111290 add more strace completion (#10227)
* Update strace.fish

* Update strace.fish

* upper case
2024-01-22 20:12:43 +01:00
Fabian Boehm
4157c28cc6 Update cargo.lock 2024-01-22 17:23:24 +01:00
Fabian Boehm
db361644c4 Remove unused num-derive dependency 2024-01-22 17:21:40 +01:00
Fabian Boehm
d74519081e fish_key_reader: Exit after "--version" 2024-01-22 17:18:11 +01:00
Mahmoud Al-Qudsi
977b97a236 Fix assertion failure in FZF keybindings
It seems the logic for calculating the cursor position was not ported correctly,
because the correct place to insert it is at the cursor_pos regardless of
range.start, going by the parameters submitted to the function and the expected
result.
2024-01-21 23:11:20 -06:00
ridiculousfish
ce19f82c19 Fix some clippy warnings 2024-01-21 19:12:33 -08:00
ridiculousfish
9a0728eed6 Stop using num_traits in common.rs
This was a rather silly usage only for estimating string capacity in a rarely
used function. We can do without it.
2024-01-21 18:19:40 -08:00
ridiculousfish
1a42bdf182 Stop using num_traits in builtin return
This can be simplified using the builtin abs() function.
2024-01-21 18:19:40 -08:00
ridiculousfish
66ebd88c44 Stop using num_traits in printf
This wasn't needed at all.
2024-01-21 18:19:40 -08:00
ridiculousfish
26abb97198 Clean up builtin status
This is a cleanup with no user-visible changes. In particular we stop using
num_derive and num_traits.
2024-01-21 18:19:40 -08:00
ridiculousfish
3ce6a5fdd1 Make sets_bind_mode in input an Option<WString>
Previously this used an empty string to mean a sentinel; use an option instead.

Fixes a TODO.
2024-01-21 18:19:40 -08:00
ridiculousfish
b4b5cff3d8 Move input tests into their own module in the tests dir 2024-01-21 18:19:40 -08:00
Mahmoud Al-Qudsi
15a82b462f Remove unnecessary copies in build.rs 2024-01-21 17:20:38 -06:00
Johannes Altmanninger
38397734e2 Fix build on OpenSUSE Tumbleweed
Fix a search & replace gone wrong in 1234c77b1 (Support linking against
reentrant-configured curses, 2024-01-21).
2024-01-21 22:22:30 +01:00
Fabian Boehm
89282fd9bc Use CARGO_MANIFEST_DIR to see if we're running from build dir
This allows running a fish built from `cargo build` *and* built via
cmake.

In future, we should make this an optional thing that's removed from
installed builds.
2024-01-21 21:25:05 +01:00
ridiculousfish
3ecd835f58 Clean up some stale comments and restore libc usage in flog_safe
flog_safe should be explicitly async-signal-safe functions; let's avoid
nix in that module for this reason.
2024-01-21 12:03:56 -08:00
PolyMeilex
f3e8272c5d Move from libc read/write to nix read/write
Replace std from_raw_fd/into_raw_fd dance with nix write

Fixup notifyd build
2024-01-21 11:49:40 -08:00
Mark Huang
65cf6ada56 completions for apt and apt-get 2024-01-21 14:21:44 +01:00
Fabian Boehm
423829a634 Rename existing cache files
We're already moving them, we can remove the awkward dot that hides
them, and while we're doing that remove the useless $USER as well.

Most systems will have only one of these files - it's rare to run a
second package manager (especially for anything more than
bootstrapping a container).
2024-01-21 14:18:50 +01:00
Fabian Boehm
a66fa5262e Cache ykman completions
Also 140ms
2024-01-21 14:18:50 +01:00
Fabian Boehm
b4d9189fd3 Cache pip{,2,3,env} completions
These take a *lot* of time - `pip3` takes 180ms, `pipenv` takes 320ms
on my system.

Note that this removes a number of obsolete workarounds - pip's was
fixed in 2017 (and pip2 is less and less of a thing), pipenv's change
was in 2019.

Since these are packaging tools with access to the internet they
should really be kept up-to-date, so it is unlikely someone still uses
these old versions.
2024-01-21 14:18:50 +01:00
Fabian Boehm
e5b2c3e4be Add helper to cache | source completions
We have a lot of completions that look like

```fish
pip completion --fish 2>/dev/null | source
```

That's *fine*, upstream gives us some support.

However, the scripts they provide change very rarely, usually not even
every release, and so running them again for every shell is extremely
wasteful.

In particular the python tools are very slow, `pip completion --fish`
takes about 180ms on my system with a hot cache, which is quite
noticeable.

So what we do is we run them once, store them in a file in our cache
directory, and then serve from that.

We store the mtime of the command we ran, and compare against that for
future runs. If the mtime differs - so if the command was up or
downgraded, we run it again.
2024-01-21 14:18:50 +01:00
Fabian Boehm
7e087d8eda __fish_make_cache_dir: Create fish subdir and optionally deeper
This will move all current cache uses to e.g. ~/.cache/fish/

That's better anyway because it makes it easier to remove.

Also it allows supplying a subdir so you can do `__fish_make_cache_dir
completions`
to get ~/.cache/fish/completions.
2024-01-21 14:18:50 +01:00
王宇逸
2f373d839c Enable LTO 2024-01-21 13:31:13 +01:00
Fabian Boehm
120dc5c49f cmake: Include PushCheckState again
This was included in one file and used in another. Just include it here.
2024-01-21 12:17:33 +01:00
Fabian Boehm
8cf4d666b3 Remove more cmake configurechecks
PCRE2 is now handled by the crate, we don't need WCHAR_T_BITS anymore
2024-01-21 12:01:38 +01:00
Johannes Altmanninger
1234c77b15 Support linking against reentrant-configured curses
NCurses headers contain this conditional "#define cur_term":

	print  "#elif @cf_cv_enable_reentrant@"
	print  "NCURSES_WRAPPED_VAR(TERMINAL *, cur_term);"
	print  "#define cur_term   NCURSES_PUBLIC_VAR(cur_term())"
	print  "#else"

OpenSUSE Tumbleweed uses this configuration option; For reentrancy, cur_term
is a function.  If the NCurses autoconf variable @NCURSES_WRAP_PREFIX@
is not changed from its default, the function is called _nc_cur_term.

I'm not sure if we have a need to support non-default @NCURSES_WRAP_PREFIX@
but if we do there are various ways;
- search for the symbol with the cur_term suffix
- figure out the prefix based on the local curses installation,
  for example by looking at the header files.

Fixes #10243
2024-01-21 11:26:07 +01:00
Johannes Altmanninger
5dfcfa336b edit_command_buffer: if aliasee is a recognized editor, pass cursor position too
If I alias "e" to "emacsclient" it will probably accept the same options.
Let's dereference the alias so we can detect support for passing the cursor
position in more cases.

This does not solve the problem for recursive cases (e.g. alias of another
alias). If we want to handle that we would need cycle detection.
2024-01-21 09:39:59 +01:00
Fabian Boehm
f7b541af99 tests/parse_util: Check against localized message
This is run in the current locale, without resetting to en_US.UTF-8
like our integration tests do.

So if you want to check for a specific message you need to check the
localized version.
2024-01-20 12:28:59 +01:00
Paul Ouellette
2cb60bed10 Remove share/completions/highlight.fish
Highlight ships its own completion script:
https://gitlab.com/saalen/highlight/-/blob/master/sh-completion/highlight.fish
2024-01-20 11:39:48 +01:00
Fabian Boehm
84b03c24d5 README: Remove chsh section
This is awkward because some systems really want $SHELL to be
sh-compatible, it's also duplicated with the actual docs and not
really something you have to do in the first five minutes of using
fish.

Supersedes #10229
2024-01-20 11:38:33 +01:00
Himadri Bhattacharjee
e014c981f2 Disallow background operator before && or ||
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Closes #10228
Fixes #9911
2024-01-20 11:32:44 +01:00
Johannes Altmanninger
87d434a98d Improve failure message in test_error_messages 2024-01-20 11:30:13 +01:00
Johannes Altmanninger
c52c03b03c Fix clippy warnings 2024-01-20 11:30:13 +01:00
Johannes Altmanninger
2059e5a171 Allow finding for empty strings with wstr::find
I hit this temporarily in a test; it seems reasonable to allow this.
std::str does too.
2024-01-20 11:30:13 +01:00
Johannes Altmanninger
f356e2d82f Remove redundant fallbacks for installation dir variables
They are redundant as of a5e35abeb (build.rs: Default variables, 2024-01-15).
2024-01-20 10:26:54 +01:00
Fabian Boehm
e73d7e26e4 Remove some more cmake bits 2024-01-20 09:13:04 +01:00
Fabian Boehm
6f31ec7a61 Remove cmake policies
CMP0066: Honor per-config flags in try_compile() source-file
signature.

CMP0067: Honor language standard in try_compile() source-file signature.

We no longer have any try_compile
2024-01-20 09:02:43 +01:00
Mahmoud Al-Qudsi
2f30d8f949 Stop caching CURSES_LIBRARY_LIST
Just treat it as if we are building without cmake when it's not present.
2024-01-20 08:56:29 +01:00
Mahmoud Al-Qudsi
66a4beadce Simplify a few things in build.rs 2024-01-20 08:56:29 +01:00
Fabian Boehm
6be6890fa3 Remove config.h
We don't actually use anything in there anymore.

We keep the WCHAR_T_BITS define in cmake because that's
used to find pcre2.
2024-01-20 08:56:29 +01:00
Fabian Boehm
f0af165348 build.rs: Try ncurses if curses couldn't be found
That's gonna be the typical one
2024-01-20 08:56:29 +01:00
Fabian Boehm
5aa622daef Remove some more unused cmake bits 2024-01-20 08:56:29 +01:00
Fabian Boehm
cfeddcedb7 Remove unused bits from config.h 2024-01-20 08:56:29 +01:00
Fabian Boehm
a5e35abeba build.rs: Default variables
So we can build without cmake
2024-01-20 08:56:29 +01:00
ridiculousfish
9747ab19d1 Eliminate UVAR_FILE_SET_MTIME_HACK checks
This was previously limited to Linux predicated on the existence
of certain headers, but Rust just exposes those functions unconditionally. So
remove the check and just perform the mtime hack on Linux and Android.
2024-01-19 09:33:33 -08:00
ridiculousfish
70ed4806b4 Use libc O_EXLOCK instead of our own
Rust libc supports O_EXLOCK on supported platforms (BSD/macOS), use that instead
of re-exposing it.
2024-01-19 09:33:33 -08:00
Johannes Altmanninger
2ffec7463e build.rs: fix formatting 2024-01-19 09:18:02 +01:00
Johannes Altmanninger
7597288c18 test_error_messages: add back missing validation
Make sure to also look for the error part that occurs after the last format
specifier.

Still not great because it won't fail if there's unexpected output at the
beginning or end of the string.
2024-01-19 06:26:31 +01:00
Mahmoud Al-Qudsi
21b4a2e5d6 Simplify rsconf has_symbol() libc lookups 2024-01-18 18:22:07 -06:00
Mahmoud Al-Qudsi
a1147c7c4f Fix outdated build.rs comments 2024-01-18 18:10:47 -06:00
Ikko Eltociear Ashimine
1e925857f0 Update iwctl.fish
colum -> column
2024-01-18 19:34:30 +01:00
Johannes Altmanninger
800f2414fb Fix regression in split_string_tok()
If there's no more separator we break early but dont update pos, so we go
into the code path that asserts we have reached the limit.
2024-01-18 10:24:40 +01:00
Johannes Altmanninger
fff8e8163b Control-C to simply clear commandline buffer again
Commit 5f849d0 changed control-C to print an inverted ^C and then a newline.

The original motivation was

> In bash if you type something and press ctrl-c then the content of the line
> is preserved and the cursor is moved to a new line. In fish the ctrl-c just
> clears the line. For me the behaviour of bash is a bit better, because it
> allows me to type something then press ctrl-c and I have the typed string
> in the log for further reference.

This sounds like a valid use case in some scenarios but I think that most
abandoned commands are noise. After all, the user erased them. Also, now that
we have undo that can be used to get back a limited set of canceled commands.

I believe the original motivation for existing behavior (in other shells) was
that TERM=dumb does not support erasing characters. Similarly, other shells
like to leave behind other artifacts, for example when using tab-completion
or in their interactive menus but we generally don't.

Control-C is the obvious way to quickly clear a multi-line commandline.
IPython does the same. For the other behavior we have Alt-# although that's
probably not very well-known.

Restore the old Control-C behavior of simply clearing the command line.

Our unused __fish_cancel_commandline still prints the ^C. For folks who
have explicitly bound ^C to that, it's probably better to keep the existing
behavior, so let's leave this one.

Previous attempt at #4713 fizzled.

Closes #10213
2024-01-17 19:54:57 +01:00
Himadri Bhattacharjee
5389d84285 shorten long descriptions for the cargo command 2024-01-16 22:16:36 +01:00
Fabian Boehm
34c09b1816 reader: Fix infinite loop for up/downcase bindings
This could *probably* be rewritten nicer with a for-loop

Fixes #10222
2024-01-16 18:13:18 +01:00
Fabian Boehm
5d3aea363e Fix PagerAndSearch not focusing the search field
Boolean confusion

Fixes #10220
2024-01-16 16:39:05 +01:00
Johannes Altmanninger
fdc45452b6 Bump CMake version for IMPORTED_RUNTIME_ARTIFACTS
This was added in CMake 3.21 which is only 1.5 years old.
2024-01-15 21:35:06 +01:00
ridiculousfish
9bd4b3f878 Adopt count_newlines in additional places 2024-01-14 10:04:55 -08:00
ridiculousfish
4ea222cd34 Improve codegen of line_offset_of_character_at_offset
This function is a hotspot, but it has inefficient codegen:

1. For whatever reason, the chars() iterator of wstr is slower
   than that of a slice. Use the slice.

2. Unnecessary overflow checks were preventing vectorization.

Switch to a more optimized implementation.

This improves aliases benchmark time by about 9%.
2024-01-14 10:04:37 -08:00
Johannes Altmanninger
e8ebeedfca Don't assume libc::c_char is signed
Fixes #10214
2024-01-14 17:12:02 +01:00
Johannes Altmanninger
10891d2985 build.rs: remove dead code 2024-01-14 13:20:52 +01:00
Johannes Altmanninger
68d1207d53 Rename flag that fails expansions with command substitutions
SKIP_CMDSUBST does not pass through command substitutions, unlike
SKIP_VARIABLES and SKIP_WILDCARDS.
2024-01-14 13:19:38 +01:00
Johannes Altmanninger
126036c980 Silence a dead code warning
This is still used in commented-out code.
2024-01-14 13:17:59 +01:00
Fabian Boehm
bf2fa6ef46 docs: Explain globs more in fish-for-bash-users 2024-01-14 11:06:51 +01:00
Fabian Boehm
f4ba2866fc docs: Add overview table of "operators"
Fixes #10201
2024-01-14 11:06:37 +01:00
Fabian Boehm
af366862f4 docs: Call it "reserved words"
"Reserved keywords" is a mouthful and some of these arguably aren't
"keywords".
2024-01-14 10:40:51 +01:00
Fabian Boehm
f8cb8284b2 docs: Add argparse examples on how to use the flags 2024-01-14 10:20:11 +01:00
David Adam
deedb92a35 sync COPYING file with doc_src/license.rst 2024-01-14 14:07:27 +08:00
ridiculousfish
509d4fa122 Remove mbrtowc_invalid_utf8.cpp
This was used in CMake to detect invalid mbrtowc implementations. The only known
case was on SnowLeopard, which is no longer supported. Remove this file.
2024-01-13 15:35:46 -08:00
ridiculousfish
0f56db55a2 Correct "fire_exit" event back to "fish_exit"
This was causing fish_exit to not fire, which caused (among other things)
leaking tmux processes from the tests.

This was bisected to eacbd6156d
2024-01-13 15:20:59 -08:00
Mahmoud Al-Qudsi
5233370cda Fix build.rs formatting 2024-01-13 16:04:05 -06:00
Mahmoud Al-Qudsi
33f33c5f41 Simplify (and fix?) build.rs HAVE_XXX detection
Since none of the compiles(xxx) calls are to particularly complex code, we can
just use `rsconf` directly to test for the presence of the symbols or headers as
needed.

Note that it seems at least some of the previous detection was not working
correctly; in particular HAVE_PIPE2 was evaluating to false on my WSL install
where pipe2(2) was available (caught because it revealed some compilation errors
in that conditional compilation path after porting).

I kept the cfg names and the tests themselves mostly as-is, though we might want
to change that to conform with the rust convention of lowercase cfg names and
decide whether we want to prefix all these with have_, fish_, or nothing at all.
Also the posix_spawn() test should probably check for the symbol `posix_spawn()`
rather than the header `spawn.h` since we don't use it via the header but rather
via the symbol (but in reality they're almost certainly going to give the same
result).
2024-01-13 15:45:42 -06:00
Mahmoud Al-Qudsi
e02c572738 Fix build error when HAVE_PIPE2 is true
NB: I only encountered this when rewriting the cfg detection, which means that
the previous detection wasn't correct since I have pipe2 on Linux but didn't run
into this build error before.
2024-01-13 15:44:03 -06:00
Mahmoud Al-Qudsi
6e002b6d80 Use cfg directly instead of going through features
Features should be for user-specifiable build configurations but our dynamic,
target-based conditional compilation is something else.
2024-01-13 15:16:47 -06:00
Mahmoud Al-Qudsi
4f8265db47 Inline the localconv_l test
It's just one line.
2024-01-13 14:58:58 -06:00
ridiculousfish
8554eb5f80 Further cleanup of FdMonitor 2024-01-13 12:51:36 -08:00
ridiculousfish
d8da79717e Remove some FFI bits from FdMonitor 2024-01-13 12:51:36 -08:00
Mahmoud Al-Qudsi
30f70f02de Feature-detect localeconv_l() presence 2024-01-13 14:21:14 -06:00
Mahmoud Al-Qudsi
195852b562 Use locale::LOCALE_LOCK for all setlocale() calls
I had originally created a safe `set_locale()` wrapper and clippy-disallowed
`libc::setlocale()` but almost all our uses of `libc::setlocale()` are in a loop
where it makes much more sense to just obtain the lock outright then call
`setlocale()` repeatedly rather than lock it in the wrapper function each time.
2024-01-13 13:50:31 -06:00
Mahmoud Al-Qudsi
a138d74688 Fix unused code warning on cannot-be-WSL platforms
No need to use cfg_attr and have to worry about syncing the preconditions for
the cfg_attr with the preconditions for where `slice_contains_slice()` is used
in the codebase, just mark it as `allow(unused)` with a comment.
2024-01-13 13:15:31 -06:00
David Adam
a533d836dd bump minimum CMake version 2024-01-13 22:55:13 +08:00
David Adam
f65ed782e8 Drop unused CMake module CheckIncludeFiles
This was only needed for certain configure checks, now elided, and for
CMake < 3.11.
2024-01-13 22:55:13 +08:00
David Adam
c9712aeda2 Drop additional unused CMake directives 2024-01-13 22:55:12 +08:00
David Adam
d418cce493 correct workflow name for static PCRE2 2024-01-13 21:23:37 +08:00
David Adam
e59d164658 Drop unused configure checks
All of these checks are handled in external crates now.
2024-01-13 21:15:24 +08:00
David Adam
db9bb96910 Drop CMake PCRE2 download/linking and allow statically-linked PCRE2 crate
pcre2-sys includes a vendored copy of PCRE2, which allows for
statically-linked PCRE2. Hook this up to the CMake build variable, and
remove the C++ integration for PCRE2.
2024-01-13 20:43:12 +08:00
Fabian Boehm
0a92d03498 Remove L! from sprintf calls
Remove unnecessary L!
2024-01-13 08:52:54 +01:00
Fabian Boehm
1da9af781c Delete widestring-suffix 2024-01-13 08:52:54 +01:00
Fabian Boehm
507d634cfa Remove widestring-suffix from Cargo 2024-01-13 08:52:54 +01:00
Fabian Boehm
fae780d666 clippy
There are a bunch more now that widestrs is gone
2024-01-13 08:52:54 +01:00
Fabian Boehm
09cd7c7ad9 Remove widestring-suffix uses
This removes both the `#[widestrs]` annotation as well as all `"foo"L`
suffixes, and does a `cargo fmt` run on the result
2024-01-13 08:52:54 +01:00
David Adam
ca972f6e0f fix permissions on source file 2024-01-13 11:12:02 +08:00
David Adam
5e8a7fb862 Drop unused C++ fishlib 2024-01-13 11:12:02 +08:00
Johannes Altmanninger
3ae20bdba0 Move fish-rust to project root 2024-01-13 03:58:33 +01:00
Johannes Altmanninger
22873cacf4 Enable tests that were accidentally disabled 2024-01-13 03:58:33 +01:00
Johannes Altmanninger
a707cd09c4 Enable clippy::unnecessary_unwrap lint 2024-01-13 03:58:33 +01:00
Johannes Altmanninger
fd7f76c180 Enable clippy::unnecessary_to_owned lint
Meh
2024-01-13 03:58:33 +01:00
Johannes Altmanninger
65064ac976 Remove dead code, enable dead_code lint 2024-01-13 03:58:33 +01:00
Johannes Altmanninger
5512f44899 Enable doctests
They are probably not terribly useful for us but let's see what happens.

Unfortunately cargo does not properly forward the combination of "RUSTFLAGS"
and "--target" that is currently required to build with ASan [1].  Hence doctests
will fail to link on ASan builds. Let's disable doctests when ASan is active.

[1]: https://github.com/rust-lang/cargo/issues/10666 et al
2024-01-13 03:58:33 +01:00
Johannes Altmanninger
07e3459fb0 Address clippy lints on 1.67.0 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
4bae1f3de9 Address clippy lints on stable Rust 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
6896898769 Add [lints] table to suppress lints across all our crates
This was stabilized in 1.74.  Until that's our MSRV, keep the warnings also in
"lib.rs", to prevent warning spew on old builds (CI logs etc.).
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
36b7723a93 Remove stale lint suppression
Feature fish-ffi-tests is no more so we don't need this warning.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
d6c96a0a68 Fix some minor warnings 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
793fb8f8f6 Minor cleanup in fish.rs
For now we always define FISH_BUILD_DIR though we could reconsider.
2024-01-13 03:07:29 +01:00
David Adam
d6cb049aff fish.rs: use some bare returns 2024-01-13 03:07:29 +01:00
David Adam
1683e720a8 Use Rust for executables
Use Rust for executables

Drops the C++ entry points and restructures the Rust package into a
library and three binary crates.

Renames the fish-rust package to fish.

At least on Ubuntu, "fish_indent" is built before "fish".
Make sure export CURSES_LIBRARY_LIST to all binaries to make sure
that "cached-curses-libnames" is populated.

Closes #10198
2024-01-13 03:07:29 +01:00
David Adam
4a2edbf97e Disable doc tests temporarily
None of the existing code blocks compile, so disable them running as tests
for now.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
5a570f187a Remove obsolete LSAN workaround 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
26d359b071 Ubuntu ASAN Dockerfile 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
e89a4f6cb4 Suppress _nc_doalloc memory leak
With the next commit, if I run

    docker/docker_run_tests.sh --shell-after docker/jammy-asan-clang.Dockerfile

I get this in test_string.fish and test_git.fish:

    =================================================================
    ==8339==ERROR: LeakSanitizer: detected memory leaks
    Direct leak of 72 byte(s) in 1 object(s) allocated from:
        #0 0x55a8a637eb45 in realloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:85:3
        #1 0x7facb841b6cc in _nc_doalloc (/lib/x86_64-linux-gnu/libtinfo.so.6+0x106cc) (BuildId: e22ba7829a55a0dec2201a0b6dac7ba236118561)
    SUMMARY: AddressSanitizer: 72 byte(s) leaked in 1 allocation(s).

Strangely there is no tparm in the call stack.  It does not seem to happen
in CI.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
2871f5070f CMake: re-enable cargo-test under ASAN
With autocxx/cxx gone, this seems to work fine now.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
e98a794d1c Fix memory leak in inotify tests 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
2d493621f4 test_cargo-test: use Corrosion target dir
This makes "ninja test" write only to the build directory, not to the source
tree. This enables our docker script which mounts the source as read-only.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
6c2271a6da cargo test: change directory to the build directory again
Some tests create files like "./test/test-home".  Traditionally the did so
in the first parent directory that contained tests/test.fish; so either a
build directory or the root.

The new rust version always changes directory to the root.  This blows up
when running with our docker/ files, which mount the source as read-only.

Fix this by always changing directory to the build directory.

In future we could extend this to not chdir if FISH_BUILD_DIR was not
specified, to match traditional behavior. No strong opinions here.
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
7686c39d76 test_cargo-test: inherit same variables as Corrosion build targets
In particular, pass the build directory, which is required in some test
scenarios (see next commit).
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
a20525c44f build.rs: deduplicate the build-dir heuristic 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
67de32fe2d Enable pexpect tests in ASAN CI again 2024-01-13 03:07:29 +01:00
Johannes Altmanninger
6ab74c6b09 Human-readable ASAN stack traces CI
Show file names, line numbers and function names in ASAN stack traces
(instead of object file + raw memory address).
2024-01-13 03:07:29 +01:00
Johannes Altmanninger
537e3cb9e1 CI: remove UBSAN_OPTIONS
Rust does not support  UBSan today.
2024-01-13 03:07:29 +01:00
Peter Collingbourne
0b3e9609f1 completions/fastboot: declare -s as taking an argument, add argument completions 2024-01-12 20:45:56 +01:00
Fabian Boehm
23a8967ecb fish_config: Fix on python < 3.12 if not on Windows 2024-01-12 18:42:55 +01:00
ahaoboy
8009469f8f Add support for the Windows MSYS environment. 2024-01-12 17:55:49 +01:00
yinm
b583145a00 Shorten long descriptions 2024-01-12 17:53:49 +01:00
Manlio Perillo
a953b7984d doc_src: add print media support to the Sphinx theme
Update the pydoctheme.css file to add support for print media.

The code was adapted from the existing support for screens that are less than
700px wide, with the following changes:

  - Remove the documents and sections index
  - Remove the quick search
  - Remove dead CSS code

Additionally, add section numbers and ensure that code blocks are never split
across multiple pages.
2024-01-12 17:52:43 +01:00
Mahmoud Al-Qudsi
fdbda18418 Use updated crates.io release for dev dependencies
The versions on crates.io now have the patches we need upstreamed.
2024-01-11 16:58:32 -06:00
Fabian Boehm
40feed56cf fmt
I wish this was shorter, but oh well
2024-01-10 20:59:50 +01:00
Fabian Boehm
2e14c32c5e fish_indent: Another crash
NUL at the end, which is now ignored.

Not *great*, but better than crashing.
2024-01-10 20:56:13 +01:00
Fabian Boehm
50acc4f4de fish_indent: Fix crash with NUL in the source
Really we should *reject* this
2024-01-10 20:47:39 +01:00
Fabian Boehm
52a3e1393f Add tests 2024-01-10 19:36:06 +01:00
Fabian Boehm
445406d251 fish_indent: Don't panic for gap text
It should be fine to just write the space out here.

This one triggered by `echo b\|\{ | ./fish_indent`
2024-01-10 19:33:47 +01:00
Fabian Boehm
ed251578d1 fish_indent: Fix crash if errors aren't sorted
I've found this for `echo \x1e\<\) | ./fish_indent`

Which is *extremely* broken script, to be fair
2024-01-10 19:33:00 +01:00
Fabian Boehm
76ddfca420 ast: Actually format debug messages
Also fixes two format strings
2024-01-10 19:20:07 +01:00
Fabian Boehm
b5ccacf5b5 fish_indent: Fix crash with redirection at the end of the source 2024-01-10 18:54:25 +01:00
Fabian Boehm
cb51b236f3 cmake: Include GNUInstallDirs earlier for BINDIR etc to take effect
GNUInstallDirs is what defines CMAKE_INSTALL_FULL_BINDIR and such, so
the setting in Rust.cmake didn't work.

This also makes build.rs error out if any of these aren't defined
2024-01-10 17:51:23 +01:00
Fabian Boehm
2aee930659 Revert "Remove redundantly set corrosion env vars."
This reverts commit 114ebe3b8f.
2024-01-10 17:21:05 +01:00
Fabian Boehm
fbfc6f8d8c Fix highlighting for slices with quotes
This would highlight `$var["foo"]` as an error because
parse_util_slice_length didn't advance the iterator.

There's got to be a nicer way to write this.
2024-01-10 17:04:54 +01:00
Johannes Altmanninger
e84d110995 Fix arithmetic overflow in up-line
The C++ code implicitly relied on wrapping behavior.

There are probably more cases like this.  Maybe we should disable
"overflow-checks" in release mode.
2024-01-10 09:38:45 +01:00
Johannes Altmanninger
114ebe3b8f Remove redundantly set corrosion env vars.
They should already be set in Rust.cmake.
See https://github.com/fish-shell/fish-shell/pull/10198#discussion_r1446402611
2024-01-10 09:38:45 +01:00
Johannes Altmanninger
113f76eecb Address minor clippy lint 2024-01-10 09:38:45 +01:00
Fabian Boehm
b82dad0160 Fix tokenizer crash
This would crash from the highlighter for something like

`PATH={$PATH[echo " "`

The underlying cause is that we use "char_at" which panics on
overread.

So instead this implements try_char_at and then just returns None.
2024-01-09 19:12:16 +01:00
Fabian Boehm
f7c9538fb0 wildcard: Check trailing components against
Forward-port of c31e194120,
Revert of 6823f5e337,
Fixes #10205
2024-01-09 19:08:52 +01:00
Fabian Boehm
96caee837c docs: Add else and end to keywords list 2024-01-09 16:27:33 +01:00
Fabian Boehm
a3c4d74ecd Don't always regenerate the exported array
This made launching external commands about 30% slower.
2024-01-08 17:50:02 +01:00
ridiculousfish
40fad20d7f Remove additional unnecessary uses of unsafe 2024-01-07 17:39:23 -08:00
ridiculousfish
92f49ca071 Remove unsafe from handling of DISOWNED_PIDS
This can be trivially safe.
2024-01-07 17:34:27 -08:00
ridiculousfish
5bff483fe1 Clean up io_chain in IoStreams
Previously this was a pointer; now it can just be a reference.
2024-01-07 17:28:36 -08:00
ridiculousfish
7d7c59611f Implement AtomicRef and use that instead of Lazy strings
This improves thread safety since we're now using actual atomics.
2024-01-07 17:04:41 -08:00
ridiculousfish
1914c3a513 Clean up wgettext
Because wgettext stores strings forever, we can simply leak them onto the heap;
this cleans up some call sites and type signatures.
2024-01-07 15:51:02 -08:00
ridiculousfish
9aa5a97530 Migrate truncate_at_nul to common and write some tests
This encapsulates a common pattern of truncating a wstr at its first NUL
character.
2024-01-07 15:41:36 -08:00
Johannes Altmanninger
29bd6eebd0 Remove cxx and autocxx
Notably this gets rid of the Cargo target directory inside build directories,
in favor of "target/" at workspace root.
2024-01-07 22:19:56 +01:00
Johannes Altmanninger
8a67abfeaa CMake: remove stale lint targets 2024-01-07 22:19:56 +01:00
Johannes Altmanninger
bb2a012c7b Use _PATH_BSHELL again in posix_spawn ENOEXEC fallback 2024-01-07 22:19:56 +01:00
Johannes Altmanninger
f7c9753c4b Rename compat.rs to libc.rs
Matches Rust convention better.
2024-01-07 22:19:56 +01:00
ridiculousfish
e110d4c672 Remove some unnecessary L! 2024-01-07 12:36:50 -08:00
Fabian Boehm
0d6c6b2c8a Check MB_CUR_MAX() outside of loop
This is more correct - we don't want to change how we encode this
string in the middle of encoding it, and also happens to be a bit
faster in my benchmarks because this is actually a function call
according to valgrind.
2024-01-07 20:48:47 +01:00
Fabian Boehm
ae24d98356 benchmarks: Run glob only once
We assume that you use something like hyperfine to run warmups, like
our driver script does.

This allows the script to be run e.g. in valgrind without being too
much of a pain in the gluteus.
2024-01-07 19:33:15 +01:00
Johannes Altmanninger
8d2fa4ae95 fish_indent: fix accidentally quadratic perf regression due to chars().last()
Iterator::last() consumes the entire iterator, even for DoubleEndedIterator,
see https://github.com/rust-lang/rust/pull/28125#issuecomment-145070161

Because of this, "at_line_start()" took 90% of

    fish_indent share/completions/git.fish

making it take 1000ms instead of 30 ms. Fix that.
2024-01-07 19:04:54 +01:00
Johannes Altmanninger
57d7c46d22 completions: fix some completions to not look at other commands on the command line 2024-01-07 19:04:54 +01:00
Johannes Altmanninger
d71aae7d3b completions/ip: remove obsolete workaround
This workaround already exists in core completion machinery.
2024-01-07 19:04:54 +01:00
Johannes Altmanninger
17bdf28b7a Remove unused moveit dependancy 2024-01-07 16:09:51 +01:00
Johannes Altmanninger
47c503bbf3 Make rand_pcg a test-only dependency 2024-01-07 16:09:51 +01:00
Fabian Boehm
244d882984 Fix ASAN workflow 2024-01-07 15:39:48 +01:00
Fabian Boehm
16c2c14fb4 Restyle 2024-01-07 15:13:34 +01:00
Fabian Boehm
0f5b2d4837 Remove C++ style/lint cruft 2024-01-07 15:12:21 +01:00
Fabian Boehm
53f7d1aa11 Remove ffi_init 2024-01-07 14:37:35 +01:00
Fabian Boehm
1e7e6e6379 Remove unixstring dependency
I don't believe this was ever used
2024-01-07 13:21:33 +01:00
Johannes Altmanninger
102ab2c90d Remove FFI code and C++ files
There's a lot more to remove, like
- cxx/autocxx
- now-unused CMake code
- C++ pcre
- C++ entry points
- remaining mentions of "ffi"
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
ab98566c67 Remove fish_tests
The remaining tests are all obsolete or already ported.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
77550a2f0d Turn FFI tests into native Rust tests
Keep running tests serially to avoid breaking assumptions.

I think many of these tests can run in parallel and/or don't need test_init().
Use the safe variant everywhere, to get it done faster.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
ae9e7a25f8 Port unit test initialization routine
Here are the differences to the C++ version in fish_tests:
1. we don't need to chdir to repo root, cargo test already does.
2. we don't need srandom because we already use deterministic RNGs for tests.
3. we don't yet call asan_before_exit(). Not yet sure how to hook into
  "cargo test" before exit.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
b2d4619125 Link against curses in build.rs too
This will allow to use "cargo test" for unit tests that depend on our
curses.rs.

This means that Rust.cmake depends on ConfigureChecks, so move that one to
the front.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
cc93a6b073 Pull rsconf fix for rsconf::enable_feature and rsconf::link_libraries 2024-01-07 12:12:09 +01:00
Johannes Altmanninger
2f13279423 Remove obsolete tests 2024-01-07 12:12:09 +01:00
Johannes Altmanninger
1b7d4f3b90 Fix latent crash in test_wwrite_to_fd
For whatever reason this did not crash until we made it a proper Rust
unit test.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
3e3441429a Port wgettext wrapper from wutil.cpp
This introduces a string allocations on lookups of strings that are not
known at compile time; we should get rid of these allocations in future.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
cd19f00531 Port setenv_lock/unsetenv_lock 2024-01-07 12:12:09 +01:00
Johannes Altmanninger
d1e3de7c8a Remove some obsolete C++ FFI calls 2024-01-07 12:12:09 +01:00
Johannes Altmanninger
5d299d21a1 Remove some obsolete bridged C++ functions
Most of these were doubled and the C++ variant is obsolete.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
c758765503 Port shell_modes
The C++ one is still there but it's only used in dead code.
2024-01-07 12:12:09 +01:00
Johannes Altmanninger
6a64ba6638 Fix build on alpine
musl libc::pthread_t is a pointer so we need to tell Rust it's safe to send
across threads.

Fixes #10195
2024-01-07 02:46:41 +01:00
Johannes Altmanninger
3e31de295a Update alpine build config 2024-01-07 02:46:41 +01:00
Johannes Altmanninger
7f110ed4c0 Port fish_key_reader 2024-01-07 00:54:22 +01:00
ridiculousfish
90fde1a9cd Snapshot env when adding to history
[ja: this seems a little bit safer?]
2024-01-07 00:54:22 +01:00
Johannes Altmanninger
55fd43d86c Port reader 2024-01-07 00:54:22 +01:00
Johannes Altmanninger
1093c636e5 Add missing expect_prompt to test_sigint.py
Somehow the Rust port of reader requires this.
2024-01-07 00:54:22 +01:00
Johannes Altmanninger
d8ac0508f8 Stop requiring Send from debounce completion callbacks
Today, debounce-style work items are only created from the main thread.
The work to compute the result is done in a background thread but the
completion callback is called on the main thread again.

The completion callbacks used by the reader capture a shared reference to
ReaderData, which includes a Parser.  Neither of those types needs to be
sent across threads.

The debounce machinery moves the completion callback into a function object
that is moved to the background thread and back again.  Because of this
there is a Send requirement on the completion callback.

Since we already synchronize on MAIN_THREAD_QUEUE, we don't need Send from
the function object. Lift the requirement.
2024-01-07 00:54:22 +01:00
Johannes Altmanninger
3c12864436 docs: fix double space in example fish_greeting
Closes #10176
2024-01-06 15:26:20 +01:00
David Adam
094f10874b bump copyright year to 2024 2024-01-06 22:24:55 +08:00
Johannes Altmanninger
cfd1e760a4 Update sourcehut FreeBSD config 2024-01-06 14:28:09 +01:00
Johannes Altmanninger
f42b7d30b3 completions/ant: don't look at tokens from adjacent commands 2024-01-06 08:44:23 +01:00
Fabian Boehm
06de374ffd Log original exit code used when a builtin returns a negative exit code
Port of b91723dab6
2024-01-05 16:52:18 +01:00
Fabian Boehm
4286b049ca docs: Fix two formatting errors
sphinx *really* needs an empty line after a `::` code block starter
2024-01-05 16:49:49 +01:00
Fabian Boehm
3213883510 Add error messages where the errors are generated
This removes an awkward hack from ParseError::describe_with_prefix,
where it added errors for two error codes.

andor_in_pipeline was already there, so we just need bare_variable_assignment.
2024-01-04 18:07:40 +01:00
Josef Litoš
ee837f254b feat: adb completion cleared of awk 2024-01-04 16:13:03 +01:00
Damien Picard
4f3e7ddef0 Completions: fix Blender completions when it prints to stderr
Some of the completions recently introduced called Blender itself to query some
arguments, and Blender sometimes prints messages to stderr. This output was not
filtered, resulting in the shell printing irrelevant messages during completion.
2024-01-04 16:11:51 +01:00
Nethum Lamahewage
a36ff7d143 history: fix deleting last entry 2024-01-04 16:10:08 +01:00
David Adam
c10d00599b completions/ninja: add --verbose option 2024-01-03 23:17:55 +08:00
Fabian Boehm
1fdbac3320 tests: Lengthen a timeout
This fails on ASAN a bunch now, let's see if it's just slower
2024-01-02 22:42:19 +01:00
Fabian Boehm
ff8563cfdb docs/set: Fix typo
Fixes #10185
2024-01-02 21:54:07 +01:00
Fabian Boehm
5a77db8353 fish_key_reader: Only name keys if they match the entire sequence
This would misname `\e\x7F` as "backspace":

bind -k backspace 'do something'
bind \e\x7F 'do something'

because it would check if there was any key *in there*.

This was probably meant for continuous mode, but it simply doesn't
work right. It's preferable to not give a key when one would work over
giving one when it's not correct.
2024-01-02 17:27:20 +01:00
Abdo Omar
744fa72d9c Update README.rst
windows 10 -> windows 10/11
2024-01-02 22:24:58 +08:00
David Adam
365027d55d drop obsolete headers 2024-01-02 01:59:02 +08:00
David Adam
3cdca4738a drop unused wildcard module
Some of the definitions in wildcard.h are still used in C++.
2024-01-02 01:59:02 +08:00
David Adam
118dfe776a drop unused path functions 2024-01-02 01:59:02 +08:00
Johannes Altmanninger
d8feb0bcd1 builtin bind: remove unused parameter
This file uses the questionable "self.somemethod(self.somefield)" pattern.
We should either set the functions free or stop passing redundant parameters.
Not sure.

For now fix one of them to avoid a string clone.
2024-01-01 18:40:34 +01:00
Johannes Altmanninger
971359876d Work in clippy lint 2024-01-01 18:40:34 +01:00
Johannes Altmanninger
69881f4251 Merge pull request #10180 from ridiculousfish/riir-input
Rewrite input machinery in Rust
2024-01-01 18:38:32 +01:00
David Adam
1b6374d2ce Merge branch 'Integration_3.7.0' 2024-01-02 00:08:49 +08:00
Fabian Boehm
6618ca17f2 set: Fix set -e without arguments
This didn't actually error out because we passed all of args.

It *might* be cleaner to pass a slice?
2024-01-01 16:21:08 +01:00
ridiculousfish
8190e3419d Add remaining input FFI bits and port builtin_bind
This implements input and input_common FFI pieces in input_ffi.rs, and
simultaneously ports bind.rs. This was done as a single commit because
builtin_bind would have required a substantial amount of work to use the input
ffi.
2023-12-31 17:17:43 -08:00
ridiculousfish
7ffb62d1d9 Port input.cpp to input.rs
This is not yet adopted.
2023-12-31 15:45:08 -08:00
ridiculousfish
01b04c802e Port input_common.cpp to input_common.rs 2023-12-31 15:45:08 -08:00
ridiculousfish
55054a4bae Add keys to our curses Term structure
This will support rewriting the input machinery in Rust.

Note that while there are a lot of keys here, in practice this is very fast -
taking on the order of microseconds to populate.
2023-12-31 15:44:50 -08:00
Fabian Boehm
b895cf49ca umask: Correctly handle empty symbolic value
Simple return/echo confusion.

Fixes #10177
2023-12-31 19:39:23 +01:00
David Adam
850c57bbb3 completions/funced: clarify -i description
Work on #10053.
2023-12-31 23:04:19 +08:00
jydeng
b9b850f286 add more subcommands for apt (#10100) 2023-12-31 23:00:15 +08:00
David Adam
6c599d8f22 docs/license: tidy up formatting 2023-12-31 21:49:38 +08:00
David Adam
413ba192a0 drop unused code:
fish_tests.cpp:
* comma_join

env.cpp:
* env_get_inherited
* env_get_runtime_path
* check_runtime_path (from tmux)
2023-12-31 21:14:40 +08:00
Johannes Altmanninger
efa37b6a2e Add back poll of change signaller after adding starting fd monitor
This was missed in ce559bc20 (Port fd_monitor (and its needed components),
2023-02-17).

Fixes the wrong color in

    echo (set_color yellow; date +%T; set_color blue)

as reported in https://github.com/fish-shell/fish-shell/issues/10176#issuecomment-1872658589
2023-12-31 11:07:18 +01:00
David Adam
31eb429add themes/Nord: include license tag 2023-12-31 12:54:31 +08:00
David Adam
ea34f71e1c docs/license: note Nord theme license 2023-12-31 12:44:29 +08:00
Fabian Boehm
4c1e25b141 fish_git_prompt: Add separator even if state is empty
This would leave off the separator if the repo was just bare or had
upstream difference, but no status (e.g. dirty) applied.

Fixes #10175
2023-12-30 19:38:22 +01:00
Johannes Altmanninger
7d10a72bb3 builtin read: enable bracketed paste
We run __fish_enable_bracketed_paste on every shell prompt, and inside
edit_command_buffer. This protects from accidents when pasting control
characters, and makes sure the paste results in a single undo group.

Let's do the same for builtin read.

Found while doing the research for #10101
2023-12-30 16:58:24 +01:00
Damien Picard
9132684617 completions: improve Blender completions
- Replace short options with old-style options: even though they are
  single-letter, Blender's options cannot be combined.
- Add comments to separate blocks of options, mirroring Blender's help message.
- Add missing options: render-frame, python-use-system-env, register-allusers,
  unregister, unregister-allusers.
- Remove options: debug-gpu-disable-ssbo, debug-gpu-renderdoc, -R.
- Fix typos:
  - debug-depsgraph-eval (was -evel)
  - debug-depsgraph-pretty (was -time)
  - app-template (was open-last)
- Update output formats:
  - Add descriptions.
  - Add HDR, TIFF, OpenEXR, OpenEXR Multilayer, FFmpeg, Cineon, DPX, JPEG 2000,
    and WebP, which are optional but generally available.
  - Remove IRIZ, which is no longer available.
- Fix arguments for --use-extension: they should be 0 or 1, not true or false.
- Make env-system-* options require a parameter.
- Improve --add-ons by querying the list of add-ons inside Blender rather than a
  hardcoded path. This is because Blender's add-on modules may come from many
  different paths which depend on platform.
- Fix __blender_echo_input_file_name, by relying on extension.
- Fix listing of scene datablocks inside Blend file.
- Add listing of Python text datablocks to execute inside Blend file.

Closes #10150
2023-12-30 16:20:39 +01:00
Amy Grace
6fe4e3d8a9 completions: add xxd
Closes #10137

(cherry picked from commit 36ed2b79c2)
2023-12-30 10:18:59 +01:00
Grzegorz Milka
c369080963 Add git stash push completions
Closes #10147

(cherry picked from commit 03198b7fd3)
2023-12-30 10:09:48 +01:00
tangowithfoxtrot
cf98b27544 add completions for bws
Closes #10165

(cherry picked from commit 7370e38069)
2023-12-30 09:33:05 +01:00
ridiculousfish
a54bb8dc14 Clean up tests/checks/bind.fish
This had some unnecessary bits and a CHECKERR was in a very confusing place.
2023-12-29 16:26:39 -08:00
ridiculousfish
7bd8328243 Fix some clippy lints 2023-12-29 12:17:22 -08:00
David Adam
c02cb3b260 CHANGELOG: work on 3.8.0 2023-12-29 23:48:44 +08:00
Shou Ya
182a42becc fix typo 2023-12-29 14:54:51 +01:00
ridiculousfish
2a46b24526 Remove some unnecessary imports and suppress unused import warnings 2023-12-28 22:11:50 -08:00
ridiculousfish
534c00bdbf Changelog fix for #10168 2023-12-28 13:38:01 -08:00
Eric N. Vander Weele
48ef682cad themes: Synchronize Nord theme in adherence to color palette guidelines
Adhere as best as possible to the style guidelines at
https://www.nordtheme.com/docs/colors-and-palettes. Some adaptations were made
so that `functions <function>` is also syntax highlighted per the upstream
recommendations.

Additionally, the theme file has been reordered to follow the order of variables
defined in interactive syntax-highlighting-variables documentation.
2023-12-28 13:36:41 -08:00
Fabian Boehm
e318585021 Don't replace tilde for error messages if we have no $HOME
This was an issue with "--no-execute", which has no variables and
therefore no $HOME:

```fish
fish --no-execute /path/to/file
```

would say the error is in `~/path/to/file`.

Instead, since this is just for a message, we simply return the
filename without doing the replacement.

Fixes #10171
2023-12-28 10:19:48 +01:00
Johannes Altmanninger
81c8cd1b61 completions: use POSIX character classes with sed
\s and \S are not supported BSD sed.

Fixes #10163
2023-12-27 17:11:01 +01:00
David Adam
6f7d5f427b CHANGELOG: work on 3.8.0 2023-12-27 22:59:24 +08:00
Fabian Boehm
b1a1a3b0a7 prompt_pwd: Fix missing --
Fixes #10169
2023-12-25 18:46:23 +01:00
Shou Ya
b44bdea230 Enable globbing in history-pager
The existing subsequence search commonly returns false positives.
Support globs, to allow searching for disconnected substrings in a better way.

Closes #10143
Closes #10131
2023-12-24 09:08:03 +01:00
Shou Ya
31d157f117 Disable redundant filtering in history pager
Part of #10143
2023-12-24 08:42:20 +01:00
Johannes Altmanninger
2358d4dec8 Fix MoveWordStyle naming convention 2023-12-24 08:42:20 +01:00
David Adam
60777f99b4 CHANGELOG: update current branch to aim for 3.8.0 2023-12-23 23:20:34 +08:00
Johannes Altmanninger
e194f35a5e Port test_word_motion 2023-12-22 18:10:29 +01:00
Johannes Altmanninger
afe9013b4c Port test_pthread 2023-12-22 18:10:29 +01:00
Johannes Altmanninger
daf96a35b5 Fix regression treating read -P as -p
Fixes #10161
2023-12-19 08:24:50 +01:00
Rudolf Lovrenčić
2e89e0c205 Add object files to ninja completions
When working on a C or C++ projects, it is often handy to compile a
single file (e.g. large refactoring where many files fail to compile so
compiling a single file results in less compiler errors making the compiler
output significantly easier to read and navigate). Current completion offers
only ninja targets which are usually just top level binaries. This commit makes
object files and library files to be offered in the ninja completion.

The change is inspired by the zsh ninja completion [1], but aims to reduce noise
by only matching for entries ending in ".o", ".so" or ".a".

[1] c828f06e08/src/zsh/_ninja (L30)
2023-12-17 20:50:41 -08:00
sigmaSd
df3c5ab402 use a better method 2023-12-17 20:39:58 -08:00
sigmaSd
f924f06df7 fix deno task completion for jsonc 2023-12-17 20:39:58 -08:00
Johannes Altmanninger
9b1acd5260 Fix regression not ignoring fish_trace when writing title 2023-12-17 17:12:13 +01:00
Johannes Altmanninger
6446289f41 abbrs: fix naming convention 2023-12-17 17:12:13 +01:00
Johannes Altmanninger
b83f3b0e98 __fish_anypager: prefer less over other pagers
This is our traditional behavior; "man" and "git" do the same.
2023-12-17 17:12:13 +01:00
Fabian Boehm
8c555505c0 README: Remove useless use of echo 2023-12-17 12:50:12 +01:00
David Adam
ea256323ab docs: standardise name for vi mode
Vi mode, vi-mode and various permutations are used.

Standardise on "vi mode".
2023-12-17 17:40:45 +08:00
Amy Grace
00ffc397b4 completions: add rename (#10136)
* completions: add rename

* add completions for other versions of `rename`
2023-12-10 21:40:38 +01:00
Fabian Boehm
2be36fbfb6 Use c_char instead of a fixed i8
Char signedness sucks sooooo bad.

Anyway, this broke the build on aarch64 linux.
2023-12-10 17:04:01 +01:00
Johannes Altmanninger
c6f7933999 io: use Condvar::wait_while 2023-12-10 14:35:43 +01:00
Johannes Altmanninger
38d52b7835 Port perf_convert_ascii
The "#[bench]" attribute is not allowed in stable Rust, so keep it behind
a new feature flag. Run on nightly Rust with

    $ cargo bench --features=bechmark
    test tests::encoding::bench::bench_convert_ascii ... bench:     125,988 ns/iter (+/- 1,128) = 1040 MB/s
2023-12-10 14:35:43 +01:00
Johannes Altmanninger
f3dd8d306f Port make_autoclose_pipes, fd_event_signaller_t
This allows to get rid of the C++ autoclose_fd_t.
2023-12-10 14:35:43 +01:00
Johannes Altmanninger
f2cd916f65 Remove unused io_data_t structs 2023-12-10 14:35:43 +01:00
Amy Grace
b7a85fe172 completions: add smerge (Sublime Merge CLI tool) (#10135)
* completions: add smerge (Sublime Merge CLI tool)

* completions: add `-o` (and file completion) to `smerge mergetool`
2023-12-10 11:50:22 +01:00
Amy Grace
d1a906026a completions: add BSD calendar 2023-12-10 11:49:34 +01:00
Ivan Kovnatsky
8c36c21e2e Add git branch --[no-,contains] completions (#10133)
* Add `git branch --[no-,contains]` completions

* Add __fish_git_commits as an argument
2023-12-10 11:41:58 +01:00
SanskritFritz
684f44bca3 Tab completions for ncdu completed 2023-12-10 11:41:26 +01:00
Nater0214
ca705fcbb5 completions: add airmon-ng 2023-12-10 11:40:53 +01:00
NextAlone
382005c33e completion(usbip): support ipv6 (#10113)
* completion(usbip): support ipv6

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>

* completion(usbip): use fish string match

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>

* fix: support --remote and -r both

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>

---------

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
2023-12-10 11:40:17 +01:00
Fabian Boehm
a2d0016cc1 completions/git: Disable log signatures
Fixes #10144
2023-12-10 10:41:03 +01:00
Fabian Boehm
dbdef5d267 vi-bindings: Make "/" open pager and go to insert mode
Fixes #10141
2023-12-10 10:37:05 +01:00
Fabian Boehm
eb196c8330 Encode all ENCODE_DIRECT codepoints with encode_direct
forward-port of 09986f5563
2023-12-10 09:29:42 +01:00
Johannes Altmanninger
e380654fff Port test_convert_nulls 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
a31ef0aeaa Delete test_wcstod
This seems to be ported already.
2023-12-09 21:35:08 +01:00
Johannes Altmanninger
a55e95f5fb Port test_env_snapshot 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
fe19cbded0 Port test_wwrite_to_fd 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
d5ccbb6e9c Port test_error_messages 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
f3d1e0d63a Port test_new_parser_errors 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
a7791aab4d Port test_new_parser_ad_hoc 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
d5cfa0e346 Port test_new_parser_ll2 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
af4b8ccc91 Port test_new_parser_fuzzing 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
afddb5dd3e Port test_new_parser_correctness 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
3fab9adab6 Port test_illegal_command_exit_code 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
c74cc71e26 Port rest of test_parser
Most of this is already ported into the "test_parser" test.
2023-12-09 21:35:08 +01:00
Johannes Altmanninger
09b7f3892f Port test_pipes 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
9430d5c542 Port test_wgetopt 2023-12-09 21:35:08 +01:00
Johannes Altmanninger
44a9a873af lru tests don't need porting since we'll drop our implementation 2023-12-09 16:55:20 +01:00
Johannes Altmanninger
4217fc9bf6 Address clippy lint for debounce test 2023-12-09 16:54:26 +01:00
Johannes Altmanninger
749e760cf5 Port debounce tests 2023-12-09 16:48:02 +01:00
Johannes Altmanninger
0942ace6c9 Fix begin-undo-group regression
Fixes #10145
2023-12-09 16:12:54 +01:00
Johannes Altmanninger
8fe82fcfcf build.rs: remove rebuild_if_path_changed for C files
Repeated

    CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo b

show that we always rebuild because of "compat.c".  Not sure why.
Let's disable this for now so we can use the cache (for test targets etc.).
2023-12-09 16:11:42 +01:00
Johannes Altmanninger
f118dbc4b9 Fix "fish --private" regression
Introduced in eacbd6156 (Port and adopt main written in Rust, 2023-08-18).

Fixes #10146
2023-12-09 09:34:57 +01:00
ridiculousfish
f49efcc691 Use -DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic"
This works around the new linker breaking on old macOS, as documented in the
Xcode 15 release notes.

See https://stackoverflow.com/questions/77193298/crash-running-app-build-on-macos-13-6-clang-15-when-running-on-macos-11-dyna
2023-12-07 22:12:40 -08:00
Johannes Altmanninger
bb16cad9dc Simplify call to is_sorted_by()
I con no longer reproduce an error/warning for this.
2023-12-06 19:01:22 +01:00
Johannes Altmanninger
360c9043cb Disable unstable_name_collisions warning
We rarely attach trait methods to stdlib types so this warning is unlikely to
be a true positive It is a false positive for the methods defined in future.rs.
It's not always obvious which method is selected when it's available in the
stdlib but I haven't seen a build failure yet.  So let's disable the warning.

In future we might be able suppress it per method, see Rust issue 48919.
2023-12-06 19:00:37 +01:00
Johannes Altmanninger
b361d1a0cf Address some clippy lints
I got these with clippy 1.67 but not with 1.73 (possible regression?).
2023-12-06 19:00:37 +01:00
Johannes Altmanninger
d7a6c7f66a Backport is_ok_and
On Rust versions that have it, this will be unused, so ignore the unused
import warning.
2023-12-06 11:02:19 +01:00
Johannes Altmanninger
aa2f817b3b fish_indent: readd missing return on -h/-v 2023-12-06 10:29:01 +01:00
Johannes Altmanninger
b28521c3d5 Port fish_indent 2023-12-06 09:59:16 +01:00
Johannes Altmanninger
3842d03473 Reformat fish files 2023-12-06 09:33:05 +01:00
Johannes Altmanninger
57e96e791e Remove some deprecated code
rust-analyzer completions are good enough so we don't need these.
2023-12-06 09:19:36 +01:00
Johannes Altmanninger
e2a0e1652e Clean up some std::io calls 2023-12-06 08:59:52 +01:00
Johannes Altmanninger
f5712af132 Add printf!/eprintf! convenience wrappers around fprintf!
We often want to format and print a string to a fd, usually stdout/stderr.

In general we can't use "format!", "print!", "eprint!" etc. because they don't
know about our use of WString where we encode of invalid Unicode characters
in the private use area.

Instead we use "wwrite_to_fd()".
Since we unfortunately don't have a "wformat!()" yet, we use "sprintf!()"
to create a formatted wstring to pass to "wwrite_to_fd()".

Add "printf!" and "eprintf!" to stand in for "print!" and "eprint!".
For printing to files other than stdout and stderr, keep "fwprintf!" but
drop the "w" since our "sprintf!" always produces wide strings.

Replace "fputws" with "fprintf" though we could also use "wwrite_to_fd"
if performance matters.

Unlike std::io::stdout(), we don't use locking yet.

Remaining work:

- There are more places where we use \be?print(ln)?!
  Usually we print strings that are guaranteed to be valid UTF-8, but not
  always. We should probably make all of them respect our WString semantics
  but preferrably keep using the native Rust format strings (#9948).
- I think flog.rs currently uses String so it won't handle invalid Unicode
  characters. We should probably fix this as well.
2023-12-06 08:59:52 +01:00
Johannes Altmanninger
e88e7dbf7a Remove stale comment 2023-12-04 23:03:36 +01:00
Thomas Queiroz
a64324421f Port builtin ulimit
Closes #10121
2023-12-03 11:39:15 +01:00
Johannes Altmanninger
31ecc5e0f9 compat.rs: group declarations 2023-12-03 11:34:31 +01:00
Johannes Altmanninger
43e2d7b48c Port pager.cpp 2023-12-03 11:02:04 +01:00
Johannes Altmanninger
f7b5ebc79f screen: rename size() to len() 2023-12-03 11:02:04 +01:00
Johannes Altmanninger
fadf0f2e5b Port editable_line_t 2023-12-02 20:04:07 +01:00
Johannes Altmanninger
020b990c81 screen: remove unused lifetime parameter 2023-12-02 19:22:03 +01:00
Johannes Altmanninger
29ec464767 Remove obsolete cur_term() wrapper 2023-12-02 16:39:27 +01:00
Fabian Boehm
05b024c675 fixup! fmt
It seems my emacs integration broke
2023-12-01 18:17:07 +01:00
Fabian Boehm
fe9d1228e1 function: Fix a broken format string 2023-12-01 18:15:11 +01:00
Fabian Boehm
aa904f0304 Correct a formattting FLOG 2023-12-01 18:15:11 +01:00
Johannes Altmanninger
31ad182aa5 Port screen.cpp 2023-12-01 11:59:33 +01:00
Johannes Altmanninger
5f1499cd67 curses: terminfo numeric capabilities are unsigned 2023-12-01 11:59:33 +01:00
Johannes Altmanninger
18654b1872 build.rs: silence error output of compile checks
These compile checks are expected to produce compiler errors on some systems.
The errors show up when there is an unrelated error, this is probably quite
confusing so fix that. Should revisit this later.
2023-12-01 11:59:33 +01:00
Fabian Boehm
0aa08cf267 Make wgettext_fmt! require an argument *to* format
Like FLOGF!, this now needs at least one argument to format.

This avoids some issues with missing variables and broken format
strings - it is how I found 13ba5bd405 -
where disown had a format string, with two placeholders, but no
arguments to fill them with.

For use in e.g. macros, where it's otherwise hard to tell if we have
something to format or not, this adds a wgettext_maybe_fmt! version to
"maybe" format, if necessary.
2023-11-29 21:12:21 +01:00
Johannes Altmanninger
f57c5e3a5f history: remove bogus assertion crashing on empty history items
In LastC++11, an empty history item means we either reached the end of history,
or the item is actually empty. The second meaning is still true.  We never
append empty history items but the history file might have been modified.

Fixes #10129
2023-11-29 20:26:36 +01:00
Fabian Boehm
b23057ee61 fix fmt 2023-11-29 17:03:10 +01:00
Fabian Boehm
13ba5bd405 disown: Fix a format string
Missed in 77aeb6a2a8, this would crash otherwise.
2023-11-29 16:59:53 +01:00
ridiculousfish
9b54e243b1 Add FFI bindings to universal notifiers and adopt in input_common
This removes the C++ bits for universal notifiers.
2023-11-26 17:29:53 -08:00
ridiculousfish
acd0bf1a43 Migrate uvar notifier test helper into its own module
Reduce the amount of stuff in mod.rs
2023-11-26 17:29:48 -08:00
ridiculousfish
a950a8270d Create an inotify based universal notifier for Linux
Recall that universal notifiers are used to report changes to universal
variables to other shell instances. This adds a new strategy based on using
inotify to directly monitor the universal variables
file.

We have tried this in the past and abandoned it because it doesn't properly
work on some CI systems - let's try again.
2023-11-26 17:29:48 -08:00
ridiculousfish
38d198a83a Port macOS universal notifiers to Rust
This ports the notifyd-based universal notifier to Rust.
2023-11-26 17:29:48 -08:00
ridiculousfish
0f29e0de2f Remove extract_most_significant_digit
This is now unused.
2023-11-26 17:23:37 -08:00
ridiculousfish
99dfbaffb9 Remove an unreachable_code "allow" declaration
This is no longer necessary - all of the code is readable.
2023-11-26 17:23:02 -08:00
Alex Chan
ccc8308d41 Add a missing space after a comma 2023-11-26 22:44:54 +08:00
David Adam
f2f41c6eec drop unused functions and configure checks
Remove the following C++ functions/methods, which have no callers:

common.cpp:
- read_loop
- narrow_string_safe
- escape_string_for_double_quotes
- read_unquoted_escape
- format_size
- format_size_safe
- valid_func_name
- get_executable_path

env.cpp:
- env_stack_t::set_empty
- env_stack_t::set_argv

fallback.cpp:
- fish_mkstemp_cloexec
- flock

proc_util.cpp:
- parse_util_slice_length
- parse_util_argument_is_help

path.cpp:
- path_get_path
- path_as_implicit_cd
- path_apply_working_directory
- path_emit_config_directory_messages
- path_get_data_remoteness
- path_get_config_remoteness
- path_is_valid
- paths_are_same_file

wcstringutil.cpp:
- split_string_tok

wutil.cpp:
- wgetcwd
- wunlink
- wrealpath
- wrename
- file_id_for_path
- fish_wcstoull

Also drop unused configure checks/defines:
- HAVE_FLOCK
2023-11-26 22:35:51 +08:00
ridiculousfish
f773697bc1 Fix a clippy lint in ConstPointer 2023-11-25 19:12:14 -08:00
ridiculousfish
0f3d4b754f Fix some bogus unused import warnings 2023-11-25 19:12:11 -08:00
ridiculousfish
cf4f07b837 Correct a misseplling 2023-11-25 16:01:58 -08:00
Fabian Boehm
62b9a0f983 path: Keep metadata around for special permissions 2023-11-24 17:05:08 +01:00
Fabian Boehm
9d1c0da773 path: Reduce syscalls for special permissions
This

1. Skips access() if we only have "special" permissions like the owner
that need stat
2. Does the geteuid()/getegid() *once* outside of filter_path, if we
need it

In the extreme case of `path filter --perm user,group` it will remove
3 syscalls per file.
2023-11-24 17:05:08 +01:00
Yonas Yanfa
1c2440c3ac Enable dynamic title in Rio and Foot terminals (#10115) 2023-11-24 17:04:50 +01:00
Christian Fersch
1980a22522 git completion: Handle aliases referencing other aliases (#9992) 2023-11-24 17:03:02 +01:00
Husam Harazi
3c814bf53d Add wpctl completions (#10043)
* Add wpctl completions

* Reviewed comments
2023-11-24 16:59:01 +01:00
Asuka Minato
9f9accf203 Update tar.fish (#10079)
* Update tar.fish

* add more long options

* add more options
2023-11-24 16:58:32 +01:00
Fabian Boehm
21b5f6f163 docs: Fix markdown links 2023-11-22 18:42:34 +01:00
Fabian Boehm
ed489d0d52 Add __fish_anypager helper
This makes it easier to get *any pager* in the number of places we do.

Unfortunately:

1. It can't just execute the pager because that might block
2. We can't really set the necessary options for less here
   so they still need to be set outside.

This

Fixes #10074

by falling back to `cat` in that case. We could also decide to abort
instead of using a non-pager, but for history that's probably fine.
2023-11-20 17:16:35 +01:00
Fabian Boehm
6361362996 Replace some direct uses of libc with wrappers (#10090)
This removes some spurious unsafe blocks and makes usage a bit nicer
2023-11-19 20:07:24 +01:00
Fabian Boehm
45829804af tests: Skip job_summary under ASAN in CI 2023-11-19 19:46:05 +01:00
Nater0214
1a42c97f75 completions: add checkinstall 2023-11-19 09:42:37 -08:00
ridiculousfish
c1e4a447fd Remove C++ UTF-8 bits
These are no longer used.
2023-11-18 19:21:25 -08:00
ridiculousfish
a718852ad4 Fix a typo and suppress an annoying clippy lint 2023-11-18 19:03:23 -08:00
ridiculousfish
da646a38ba Remove some unnecessary widestrs 2023-11-18 19:03:23 -08:00
ridiculousfish
f0eaa516c0 Stop boxing ParseExecutionContext
This wasn't necessary - probably a holdover from using unique_ptr in C++.
2023-11-18 19:03:23 -08:00
ridiculousfish
89376d5fd0 Fix a clippy lint 2023-11-18 19:03:23 -08:00
Johannes Stölp
1cba28c120 [doc]: fix --path description of set cmd 2023-11-18 19:00:56 -08:00
ridiculousfish
c38a7e4f84 Revert "completions: add chezmoi completions"
This reverts commit ee2c0c4a4c.

chezmoi installs completions to vendor_completions.d - unclear if we want to
ship this.
2023-11-18 18:56:55 -08:00
Jasmin Oster
ee2c0c4a4c completions: add chezmoi completions 2023-11-18 18:54:03 -08:00
a-kenji
17eadcff03 Fix small typos 2023-11-18 18:27:25 -08:00
ridiculousfish
a9f346acf0 Remove some environment and null_terminated_array ffi bits
These are now unused and can be removed.
2023-11-18 11:12:25 -08:00
ridiculousfish
377ef9786e Remove null_terminated_array C++ bits
These are now unused.
2023-11-18 10:28:52 -08:00
Johannes Altmanninger
7df70e18f4 Add hint to error message about cmdsub in command position
We might end up allowing this but let's add some help for now.

See #5575
2023-11-18 12:26:45 +01:00
Fabian Boehm
366b3f21c6 tests: Increase a sleep 2023-11-15 17:58:42 +01:00
Johannes Altmanninger
f3ce78bc53 history: remove spurious UTF-8 check regression
Closes #10102
2023-11-15 16:31:33 +01:00
Johannes Altmanninger
7f67588e63 fish_tests: label tests to indicate if they need porting 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
4e37dc29dc Fix autosuggestion dropping too many keyword tokens 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
6569943cb8 Port builtin read 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
77aeb6a2a8 Port execution
Drop support for history file version 1.

ParseExecutionContext no longer contains an OperationContext because in my
first implementation, ParseExecutionContext didn't have interior mutability.
We should probably try to add it back.

Add a few to-do style comments. Search for "todo!" and "PORTING".

Co-authored-by: Xiretza <xiretza@xiretza.xyz>
(complete, wildcard, expand, history, history/file)
Co-authored-by: Henrik Hørlück Berg <36937807+henrikhorluck@users.noreply.github.com>
(builtins/set)
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
c4155db933 Rename Rust-side parser_t/io_streams_t to Parser/IoStreams
This reduces noise in the upcoming "Port execution" commit.

I accidentally made IoStreams a "class" instead of a "struct".  Would be
easy to correct that but this will be deleted soon, so I don't think we care.
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
aaa48e89a5 Temporarily rename Rust-native IoStreams to make way
The next commit will use this name.
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
6280fcc8c5 Don't use virtual dispatch for OutputStream
It's not really needed since we know all specializations.
Also this allows us to define generic methods like

    fn append(&self, s: AsRef<wstr>);
2023-11-15 11:09:48 +01:00
Johannes Altmanninger
7fd4ad025a Traced refcell and mutex wrappers for debugging 2023-11-15 11:09:48 +01:00
Johannes Altmanninger
aec6b9e5e1 common: simplify a variable definition 2023-11-15 11:09:48 +01:00
Fabian Boehm
723bfb9aaf docs/complete: List --description with the options 2023-11-14 16:32:43 +01:00
Dmitriy Shishkov
bd4adf86f4 Replaced double quotation marks with single in dnf.fish completions 2023-11-12 18:35:49 +01:00
exploide
a390e36e9d completions: improved netcat completions
- fixed a copy and paste error from 7b8684e
- enhanced ncat completions
2023-11-10 15:43:39 +01:00
Fabian Boehm
67faa107b0 expand_cmdsubst: Make more errors known
These printed "Unknown error while evaluating command substitution".

Now they print something like

```
fish: for: status: cannot overwrite read-only variable
for status in foo; end
    ^~~~~^
in command substitution
fish: Invalid arguments
echo (for status in foo; end)
     ^~~~~~~~~~~~~~~~~~~~~~~^
```

for `echo (for status in foo; end)`

This is, of course, still not *great*. Mostly the `fish: Invalid
arguments` is basically entirely redundant.

An alternative is to simply skip the error message, but that requires some
more scaffolding (describe_with_prefix adds some error messages on its
own, so we can't simply say "don't add the prefix if we don't have a
message")

(cherry picked from commit 1b5eec2af6)
2023-11-09 17:51:15 +01:00
Fabian Boehm
f81c9cba50 docs: Make the vendor dirs a nested list 2023-11-07 17:55:36 +01:00
Fabian Boehm
ddd9d183e2 Document $__fish_vendor_confdirs and __fish_build_paths
Fixes #10078
2023-11-07 17:48:54 +01:00
Fabian Boehm
676da369b4 completions/dnf: Remove "offline-upgrade upgrade"
Fixes #10081
2023-11-07 17:48:54 +01:00
Fabian Boehm
8fea3cb56d docs: Fix link 2023-11-07 17:48:54 +01:00
Nicholas Rodrigues Lordello
93b3a0c1f5 Additional checks for -F support 2023-11-07 17:45:45 +01:00
Nicholas Rodrigues Lordello
5cf36bf3f8 ls No Longer Sets LS_COLORS 2023-11-07 17:45:45 +01:00
Wadii Hajji
3f7fdd5693 fix(git): add force-if-includes completion 2023-11-06 20:29:29 +01:00
Asuka Minato
754e81afa3 Update find.fish
add -D and -nowarn
2023-11-06 20:27:01 +01:00
Kid
84e6344c91 Add --verbose completion to fish_key_reader
This was missing from #8467.
2023-11-06 20:21:01 +01:00
Fabian Boehm
496fc03b98 docs: More on key timeout, key chord limitations 2023-10-24 18:25:49 +02:00
Fabian Boehm
e494e15574 funcsave: Always use local $funcdir
This abused default scope
2023-10-19 22:36:58 +02:00
Fabian Boehm
dd12f55dc2 docs/read: Specify default scope
Fixes #10061
2023-10-19 21:12:54 +02:00
Nunzio Cicone
85deb76c5f update entr completions 2023-10-18 19:09:39 +02:00
Florian Meißner
b16a869907 Fix typo in read doc 2023-10-18 19:09:11 +02:00
exploide
5d0efbf2e8 completions: added userdel from shadow-utils 2023-10-18 19:08:50 +02:00
Oliver Schrenk
631f2c073c fix typo in set -U option 2023-10-18 19:08:09 +02:00
NextAlone
7250e6fa6a completion(loginctl): fix sessions with ssh or other states (#10038)
Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
2023-10-18 18:36:54 +02:00
Fabian Boehm
913eddbdcf docs: Underline *all* body links, not just internal ones 2023-10-18 18:35:02 +02:00
ridiculousfish
7fa3dd1747 Refresh and fix some web config bugs
Refresh some stale CSS, improve some rendering, and fix some bugs.

Some of the CSS no longer applied. Remove the bright red X in history
and use a tamer color. Fix the prev/next paginator buttons from moving
for large paginations. Fix the calculation about disabling prev/next.
2023-10-15 13:00:26 -07:00
Fabian Boehm
0f8bcb0414 wildcard: Rationalize file/command completions (#10052)
* wildcard: Remove file size from the description

We no longer add descriptions for normal file completions, so this was
only ever reached if this was a command completion, and then it was
only added if the file wasn't a regular file... in which case it can't
be an executable.

So this was dead.

* Make possible_link() a maybe

This gives us the full information, not just "no" or "maybe"

* wildcard: Rationalize file/command completions

This keeps the entry_t as long as possible, and asks it, so especially
on systems with working d_type we can get by without a single stat in
most cases.

Then it guts file_get_desc, because that is only used for command
completions - we have been disabling file descriptions for *years*,
and so this is never called there.

That means we have no need to print descriptions about e.g. broken symlinks, because those are not executable.

Put together, what this means is that we, in most cases, only do
an *access(2)* call instead of a stat, because that might be checking
more permissions.

So we have the following constellations:

- If we have d_type:
  - We need a stat() for every _symlink_ to get the type (e.g. dir or regular)
    (this is for most symlinks, if we want to know if it's a dir or executable)
  - We need an access() for every file for executables
- If we do not have d_type:
  - We need a stat() for every file
  - We need an lstat() for every file if we do descriptions
    (i.e. just for command completion)
  - We need an access() for every file for executables

As opposed to the current way, where every file gets one lstat whether
with d_type or not, and an additional stat() for links, *and* an
access.

So we go from two syscalls to one for executables.

* Some more comments

* rust link option

* rust remove size

* rust accessovaganza

* Check for .dll first for WSL

This saves quite a few checks if e.g. System32 is in $PATH (which it
is if you inherit windows paths, IIRC).

Note: Our WSL check currently fails for WSL2, where this would
be *more* important because of how abysmal the filesystem performance
on that is.
2023-10-14 08:45:15 +02:00
Johannes Altmanninger
773a507b01 fish.rs: fix regression in fish_xdm_login_hack_hack_hack_hack
This is off by one from the C++ version.

It wasn't super obvious why this worked in the first place.
Looks like args[0] is "-" because we are invoked like

    fish -c 'exec "${@}"' - "${@}"

and it looks like "-" is treated like "--" by bash, so we emulate that.
See https://github.com/fish-shell/fish-shell/issues/367#issuecomment-11740812
2023-10-13 19:58:50 +02:00
Johannes Altmanninger
b8c5627eb1 io: use Vec::with_capacity 2023-10-13 19:53:45 +02:00
Fabian Boehm
c6e905a1b9 docs/read: Mention the more common mode first
Printing to stdout is a thing it can do, yes, but writing to variables
is the more typical way to use it.
2023-10-12 22:35:43 +02:00
Johannes Altmanninger
bba0103103 build.rs: re-run if compat.c changed 2023-10-12 21:55:11 +02:00
David Adam
0f70b2c0d3 README: bump CMake requirements for Rust build
file(real_path) added in 35baa883 requires CMake 3.19.
2023-10-12 15:48:38 +08:00
ridiculousfish
57335ebb02 Reformat colorutils.js using Prettier 2023-10-08 12:27:39 -07:00
ridiculousfish
98018753e5 Replace references to angular with alpine
Updates our license references.
2023-10-08 12:25:43 -07:00
ridiculousfish
5e06e80136 Remove angular "partials"
These are no longer used as we are fully on Alpine.js
2023-10-08 12:22:56 -07:00
Mahmoud Al-Qudsi
0233c0c437 fix is_windows_subsystem_for_linux(), check for post-fork-safety
This function only ever returns true if target_os=linux, so we need to invert
the OS check.

In the first invocation, this function may allocate heap memory.
Clarify that this is safe.

[ja: I don't have the original commit handy so I made up the log message]
2023-10-08 20:48:24 +02:00
Johannes Altmanninger
0a48f4b55c common: remove deprecated methods 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
b583c51238 Sort clippy lints 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d15e475440 event: reduce lock scope to allow re-locking in event handler
The following "Port execution" commit will use RefCell for the wait handle
store.  If we hold a borrow while we are running an event (which may run
script code) there will be a borrowing conflict. Avoid this by returning
the borrow earlier.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
575c271461 job_group: reuse RelaxedAtomicBool 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d764625069 getcwd: fix bad error message 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
ad75c72621 flog: reuse write_to_fd 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
637926a7fd env: fix porting regression recording inherited vars 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
d8de497ebc Use shorter escape() function 2023-10-08 20:46:53 +02:00
Johannes Altmanninger
0b25793097 wildcard: use "zelf" over "this" for consistency
The following "Port execution" commit will add lots of variables called "zelf".
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
6ef5ae0935 env: skip env lines without equal sign
Given an env like

    foo
    bar=baz

we would set "foo" to empty due to a typo.
The typo is pointed out by a PORTING comment.

Luckily I don't think we ever hit this case because that would mean our
parent process has a serious bug.  Rust's std::env::vars_os() skips env
lines that don't contain a "=" char.  This seems like a reasonable behavior
for us too. Do that.
2023-10-08 20:46:53 +02:00
Johannes Altmanninger
e8712af0c3 builtin random: make option parsing consistent with other builtins again
As suggested in a comment on2fb352a9e (Address some clippy lints from nightly
clippy, 2023-10-03).
2023-10-08 20:46:53 +02:00
Fabian Boehm
86803e4442 Reduce stat calls for wildcards ending in "/" (#10032)
This makes it so expand_intermediate_segment knows about the case
where it's last, only followed by a "/".

When it is, it can do without the file_id for finding links (we don't
resolve the files we get here), which allows us to remove a stat()
call.

This speeds up the case of `...*/` by quite a bit.

If that last component was a directory with 1000 subdirectories we
could skip 1000 stat calls!

One slight weirdness: We refuse to add links to directories that we already visited, even if they are the last component and we don't actually follow them. That means we can't do the fast path here either, but we do know if something is a link (if we get d_type), so it still works in common cases.
2023-10-08 16:46:59 +02:00
Fabian Boehm
c4ca1a68d3 Add a clear-screen bind function to clear the screen (#10044)
This can be bound like `bind \cl clear-screen`, and is, by default

In contrast to the current way it doesn't need the external `clear`
command that was always awkward.

Also it will clear the screen and first draw the old prompt to remove
flicker.
Then it will immediately trigger a repaint, so the prompt will be overwritten.
2023-10-08 11:41:30 +02:00
ridiculousfish
f7e7396c69 Fix a deadlock affecting fish_config
This fixes the following deadlock. The C++ functions path_get_config and
path_get_data lazily determine paths and then cache those in a C++ static
variable. The path determination requires inspecting the environment stack.
If these functions are first called while the environment stack is locked
(in this case, when fetching the $history variable) we can get a deadlock.

The fix is to call them eagerly during env_init. This can be removed once
the corresponding C++ functions are removed.

This issue caused fish_config to fail to report colors and themes.

Add a test.
2023-10-07 15:20:14 -07:00
ridiculousfish
b315b66cb0 Minor comment cleanup of main.rs 2023-10-07 14:39:24 -07:00
Fabian Boehm
e62f32c16b CI: Remove --deny=warnings from clippy test
This was pretty annoying on rust release day, because it introduced
new warnings.

Specifically 1.73 introduced a spurious one about PartialOrd and Ord
disagreeing when both were in fact #derive-d.
2023-10-07 19:48:54 +02:00
Johannes Altmanninger
79bbf5247a builtin set_color: use naming convention 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
28a38946a5 common: port err!() test helper
Unlike our C++ tests, our Rust tests fail as soon as an assertion fails.
Whether this is desired is debatable; it seems fine for
most cases and is easier to implement.

This means that Rust tests usually don't need to print anything besides
what assert!/assert_eq! already provide.
One exception is the history merge test. Let's add a simple err!() macro to
support this. Unlike the C++ err() it does not yet print colors.

Currently all of our macros live in common.rs, to keep the import graph simple.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
618834c4b5 Port UVAR_FILE_SET_MTIME_HACK
Notably this exposes config.h to Rust (for UVAR_FILE_SET_MTIME_HACK).
In future we should move the CMake checks into build.rs so we can potentially
get rid of CMake.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
3020c90856 Upgrade bitflags
This allows us to use some newer functionality (I forgot which one I ended
up using).
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
1bfdc33f76 Make stream.append call sites consistent
Maybe the wrong direction.. but this seems to be the majority.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2fb352a9e4 Address some clippy lints from nightly clippy
Note that in general we should not respect nightly clippy because it might
contradict stable clippy which is run in CI.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
10fed02572 Work around ASan complaining about buffer overflow in DirIter
On the following "Port execution" commit, ASan will complain if we read
beyond a terminating null byte in get_autosuggestion_performer().  This is
actually working as intended but we need to appease ASan somehow..
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
55683b29cd CMakeLists: sort 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
379ad03d9d parse_util: return Result in parse_util_detect_errors_in_argument
This makes it consistent with some other public parse_util_* functions.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
2334424234 parse_util: fix regressions from port
Tested by the upcoming highlighting unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
c7c0bb9bb2 env: fix boolean sense in get_pwd_slash()
get_pwd_slash() uses "if var.is_empty()" but it should be "if !var.is_empty()".
This wasn't a problem so far because in practice most code paths use the
get_pwd_slash() override from EnvStackImpl. The generic one is used in the
upcoming unit tests.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
48ce8f8721 Remove test_history_speed benchmark
Doesn't seem terribly important? We can add it back easily.
2023-10-07 19:30:46 +02:00
Johannes Altmanninger
ffbb56c4a9 common: port test_format 2023-10-07 19:30:46 +02:00
Johannes Altmanninger
408161f4d6 Port test_tokenizer 2023-10-07 19:30:46 +02:00
Mathijs Henquet
a809672412 Fix out of scope opt variable (#10020)
* Fix out of scope opt variable

* Update ls.fish
2023-10-07 18:00:17 +02:00
Fabian Boehm
098b7093da fish_config: Fix save with variable with multiple values
Your basic quoting problem, regressed in 3.6.0
2023-10-06 22:15:35 +02:00
Fabian Boehm
496d65fb5d Apply variable overrides for exec
Fixes #9995
2023-10-06 18:15:25 +02:00
Fabian Boehm
6775b0b1ad Implement PartialEq manually to shut up clippy 2023-10-06 17:10:59 +02:00
Fabian Boehm
1073f59929 Shut up Clippy 1.72 2023-10-06 16:54:16 +02:00
Fabian Boehm
ff433b0cb2 reader: Only move cursor if needed for repaint-mode
This uses "screen.reset_line" to move the cursor without informing the
reader's machinery (because that deals with positions *in the
commandline*), but then only repainted "if needed" - meaning if the
reader thought anything changed.

That could lead to a situation where the cursor stays at column 0
until you do something, e.g. in

```fish
bind -m insert u undo
```

when you press alt+u - because the *escape* calls repaint-mode, which
puts the cursor in column 0, and then the undo doesn't, which keeps it
there.

Of course this binding should also `repaint-mode`, because it changes
the mode.

Some changes might be ergonomic:

1. Make repaint-mode the default if the mode changed (we would need to
skip it for bracketed-paste)
2. Make triggering the repaint easier - do we need to set
force_exec_prompt_and_repaint to false here as well?

Anyway, this

Fixes #7910
2023-10-06 16:38:26 +02:00
Fabian Boehm
3ce67ecbd2 printf: Fix octal escapes with leading zeroes
Octal escapes can be written as `\057` or as `\0057`.

Simply ported wrong initially.
2023-10-05 15:39:50 +02:00
Fabian Boehm
8cc0bdeed8 pexpect: Remove some unnecessary empty lines
This strips the newline from "code_context" (which is really just the
called function), and from the unescaped output.

Rather, in case the output doesn't end with a newline it'll mark it
with an explicit message "(no trailing newline)".
2023-10-04 18:51:44 +02:00
Fabian Boehm
7a22dcb687 pexpect: Check if the process exited with a signal
This would have been helpful in #10044:

> signals.py:28: SIGNAL SIGSEGV from expect_prompt()

instead of "EOF".
2023-10-04 16:02:13 +02:00
Fabian Boehm
f8e38819a5 open: Don't run xdg-open in the background
This was introduced as a workaround to #7215 - xdg-open's generic path
wouldn't background graphical apps.

This has been fixed a month ago in xdg-open, so we can stop doing it.

The good news is this also allows terminal apps to be used again, so
it

Fixes #10045
2023-10-04 15:57:32 +02:00
Hauke Strasdat
4ab34f2e86 fix: don't make assumptions about signedness of libc::c_char 2023-10-01 13:27:10 -07:00
Xiretza
0cdf801d0b completions/pacman: fix -Qp completing packages, not files
--file/-p makes -Q interpret the command line argument as a package file
rather than a package name.
2023-10-01 08:46:33 +02:00
Kevin F. Konrad
269c9c3f0c add completions for crc and oc (#10034) 2023-10-01 08:38:27 +02:00
Roland Fredenhagen
e6bef40c22 completions: add watchexec (#10027)
* completions: add watchexec

* review
2023-10-01 08:37:42 +02:00
Fabian Boehm
10d91b0249 screen: Unset color at the end of a line even without clr_eol
This is a sensible thing to do, and fixes some cases where we're
state-dependent.

E.g. this fixes the case in the pager where some things are bold and
some aren't, because that bolding is (rather awkwardly) implicitly
triggered when we have a background, and so we don't notice we need to
re-do that bolding after we moved to the next line because we think we
still have the same color.

Fixes #9617
2023-09-30 15:32:54 +02:00
Gregory Anders
b32cc65166 Do not use is_some_and
This was stabilized in Rust 1.70.0, but CI uses 1.67.0 where this function was
still marked unstable.
2023-09-30 10:09:52 +02:00
Gregory Anders
33c6eee9d2 Check terminfo for ts capability to determine title setting support 2023-09-30 10:09:52 +02:00
Fabian Boehm
ff8a79a823 Add a test for fish_add_path with relative paths 2023-09-29 16:54:23 +02:00
Fabian Boehm
9fa70d3ace Remove two calls to builtin realpath
path was added in 3.4, it's old enough that we can use it now.
2023-09-29 16:47:00 +02:00
Fabian Boehm
35baa88334 cmake: Canonicalize binary dir
This would otherwise fail to set $fish_function_path to
share/functions etc if run through a symlink.
2023-09-28 17:34:10 +02:00
Charlotte
7c5777a82a completions/pkill: use locals. 2023-09-27 19:53:17 +02:00
David Adam
4fab9e525a drop now-unused postfork C++ module 2023-09-25 21:47:19 +08:00
ridiculousfish
555171cb55 Adopt Rust postfork code
This adopts the Rust postfork code, bridging it from C++ exec module.

We use direct function calls for the bridge, rather than cxx/autocxx, so that we
can be sure that no memory allocations or other shenanigans are happening.
2023-09-24 13:04:00 -07:00
ridiculousfish
c862a06874 Implement postfork code in Rust
This implements the "postfork" code in Rust, including calling fork(),
exec(), and all the bits that have to happen in between. postfork lives
in the fork_exec module.

It is not yet adopted.
2023-09-24 13:04:00 -07:00
ridiculousfish
c5d770c78a Introduce flog_safe module in fork_exec module
This introduces a new module called fork_exec, which will be for posix_spawn,
postfork, and flog_safe - stuff concerned with actually executing binaries,
and error reporting.

Add a FLOG_SAFE! macro which writes errors to the flog fd in an
async-signal-safe way. This implementation differs from the C++ in that we
allow printing integers directly - no requiring them to be converted to a
buffer first.
2023-09-24 13:04:00 -07:00
ridiculousfish
6a6cde50d5 Stop using widestrs macro in flog
Use L! directly. Fewer proc-macros is good.
2023-09-24 13:04:00 -07:00
NextAlone
3bcde90a88 completion(loginctl): complete sessions, users, seats (#10023)
* completion(loginctl): complete sessions, users, seats
* fix: rename functions and use builtin to parse strings
* fix: duplicate commands
2023-09-23 22:49:43 +02:00
Fabian Boehm
e682ffaf11 Add doctl completion
Just calling a generation thing
2023-09-23 15:09:59 +02:00
Fabian Boehm
2cf22596e7 Disable reflow handling for WezTerm too
Seems to work fine
2023-09-22 17:13:28 +02:00
Fabian Boehm
4d2f7b0c0d ast: Require --help to parse more keywords as decorated statement (#10000)
This makes it so

```fish
if -e foo
    # do something
end
```

complains about `-e` not being a command instead of `end` being used
outside of an if-block.

That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!

The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).

The same goes for switch, while and begin.

It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
2023-09-19 17:34:13 +02:00
Fabian Boehm
6194899c6b tests: Remove a misunderstanding 2023-09-15 20:04:13 +02:00
Henrik Hørlück Berg
731f06bdb9 fixup! Forward-port #9931 2023-09-15 15:10:14 +02:00
Johannes Altmanninger
280e72c152 Merge pull request #9916 from henrikhorluck/riir/wildcard
Port wildcard to Rust
2023-09-15 15:02:55 +02:00
Henrik Hørlück Berg
0cc1aef725 Forward-port #9931 2023-09-15 14:58:54 +02:00
Henrik Hørlück Berg
6ee81c0f15 Crash if invariant is broken 2023-09-15 14:46:53 +02:00
Henrik Hørlück Berg
5407d0b785 Apply code review fixes 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d6a9ad66a7 Allow CancelChecker to be FnMut 2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
d277a50564 Combine previous attempt into this
*singing it's the best of both worlds*
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
e0bbf3eee9 Port wilcard.{cpp,h} to Rust
- This is untested and unused, string ownership is very much subject to change
- Ports the minimally necessary parts of complete.rs as well
- This should fix an infinite loop in `create_directory` in `path.rs`, the first
  `wstat` loop only breaks if it fails with an error that's different from
  EAGAIN
2023-09-15 14:44:58 +02:00
Henrik Hørlück Berg
80d92dcc6d Port the easy part of wildcard.{h,cpp}
- wildcard_match is now closer to the original that is linked in a comment, as
  pointer-arithmetic translates very poorly. The act of calling wildcard
  patterns wc or wildcard is kinda confusing when wc elsewhere is widechar.
2023-09-15 14:38:30 +02:00
Johannes Altmanninger
e1f5751ba0 fixup! builtin status: use program name constant again 2023-09-14 20:46:42 +02:00
Johannes Altmanninger
61d506afd0 builtin status: use program name constant again 2023-09-14 20:42:25 +02:00
Johannes Altmanninger
e2ee8a0beb isolated-tmux: fix quoting error 2023-09-14 20:42:25 +02:00
Fabian Boehm
ebb8368464 docs/read: Some reorganization
This just had *all the options* in one gigantic list, and some very
stuffy wording - "prompt-str" sounded like it was discouraged for some reason?
2023-09-13 17:18:19 +02:00
Fabian Boehm
ad54f07328 docs/set: Correct some errors 2023-09-13 17:08:52 +02:00
Fabian Boehm
778f4e6732 docs: Improve quoting variables section
This now specifically explains quoting with `set`, and the contrast to bash.
2023-09-11 17:31:00 +02:00
Fabian Boehm
136dc6ce28 Test for mktemp completion
Turns out fish isn't in $PATH on the CI systems
2023-09-11 16:52:38 +02:00
Fabian Boehm
110de8e0df Harden test
Turns out the order wasn't the same on CI as it was on my system. Just
match it.
2023-09-10 20:56:58 +02:00
Fabian Boehm
b03327f5d2 __fish_complete_command: Fix --foo= logic
This was already supposed to handle `--foo=bar<TAB>` cases, except it
printed the `--foo=` again, causing fish to take that as part of the
token.

See #9538 for a similar thing with __fish_complete_directories.

Fixes #10011
2023-09-10 18:16:41 +02:00
Fabian Boehm
fc95eca257 share/config.fish: Skip __fish_set_locale if $LANG is already set
This is the most common and sensible env var, we check it outside,
so we can skip loading the function at all if we already know it's not
gonna do anything.

This is done on every startup of every single fish, and it saves ~0.2ms.
2023-09-09 15:53:20 +02:00
Marcelo Mendes Spessoto Junior
7534572d99 Shortening node.fish completions
Signed-off-by: Marcelo Mendes Spessoto Junior <marcelospe@shinji.linux.ime.usp.br>
2023-09-09 08:31:19 +02:00
Jason Nader
d6e234c60c completions: add ibmcloud (#10004)
* completions: add ibmcloud

* Update ibmcloud.fish
2023-09-09 08:30:16 +02:00
Asuka Minato
3bf80b2374 add gcc completion for link lib (#10007)
* add completion for lib

* use path basename && use -a
2023-09-09 08:29:39 +02:00
Fabian Boehm
5b44c26a19 reader: Use existing search string when opening the history pager
I sometimes find myself doing something like this:

- Look for a commandline that includes "echo" (as an example)
- Type echo, press up a few times
- I can't immediately find what I'm looking for
- Press ctrl-r to open up the history pager
- It uses the current commandline as the search string,
  so now I'm looking for "echo foobar"

This makes it so if the search string already is in use, that's what
the history-pager picks as the initial search string.
2023-09-09 08:29:24 +02:00
Fabian Boehm
0e81d25b36 docs/commandline: Add more on the -oc/-ct thing
This was the remaining immediately actionable part of #7375.

It's not definitely the last word, but a change here would require a
bigger plan.

Fixes #7375
2023-09-08 18:27:34 +02:00
Fabian Boehm
180692fb29 completion: Set up wrapping for gw/gradlew
These were set up as commands in the actual gradle completions, but
they would never be loaded.
2023-09-07 08:06:55 +02:00
Fabian Boehm
46de22561a README: Link via matrix, not gitter
Gitter is now just another matrix server, so it's pretty useless and
not as well-known as a service.
2023-09-06 15:48:12 +02:00
Fabian Boehm
5e775d1607 Upgrade actions/checkout to v4
Otherwise it's gonna start throwing node warnings soon.

Isn't software great?
2023-09-06 10:13:04 +02:00
Fabian Boehm
d6a6d77429 cmake: Fix SYSCONFDIR and friends 2023-09-06 09:49:24 +02:00
Fabian Boehm
4f888d79ee README: Do give the path dynamically in the switching instructions
Apparently this is actually a point of confusion.

Unfortunately we can't use `which` here because 1. it might not be
installed, 2. it might be trash.

So we give instructions from inside fish, and explain that they
should *typically* work.

See #10002
2023-09-05 22:38:47 +02:00
Fabian Boehm
fa390334a8 Remove wcs/wcwidth ffi calls
This was ported a while back, we can just call the rust version
2023-09-05 21:57:38 +02:00
Xiretza
fff320b56b completions: make: respect line continuations in recipes
Without this, a recipe containing a trailing backslash followed by a line not
beginning with tab (like any non-continued recipe lines would) would result in
the continuation showing up in completions.

Whenever a line ends in a backslash, consider the next line invalid as a target.

Regex explanation:

^([^#]*[^#\\])? -- optional prefix not containing comment character and not
                   ending in backslash
(\\\\)*\\$      -- 2n+1 backslashes at end of line (handles escaped backslashes)
2023-09-05 11:40:05 +02:00
Henrik Hørlück Berg
676c3c9bc2 Re-use DEFAULT_PATH in setup_path
- No need to hard-code a different default
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
008764a2cd Make DEFAULT_PATH allow overriding system binaries
This is in regards to a comment on 290d07a833, which resulted in 46c967903d.
Those commits handled the default path when it is unset on startup.
DEFAULT_PATH is used when PATH is unset at runtime as far as I can tell.

As far as I can tell this has had the non-overidding ordering behavior since inception
(or at least 17 years ago ea998b03f2).
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
3a4149a9e7 Add test that confirms behavior when PATH is unset 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
6283274c24 Remove C++ version of start_private_mode 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
fca41c0459 Fully migrate to Rust env_init 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
ea704179c1 Remove now unused in C++ hacks 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
eacbd6156d Port and adopt main written in Rust
We don't change anything about compilation-setup, we just immediately jump to
Rust, making the eventual final swap to a Rust entrypoint very easy.

There are some string-usage and format-string differences that are generally
quite messy.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
96e58dac21 Port env_init to Rust
- This does not adopt it.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
e7f8fb04cc Add BUILD_VERSION to lib.rs
In CMake this used a `version` file in the CARGO_MANIFEST_DIR, but
relying on that is problematic due to change-detection, as if we add
`cargo-rerun-if-changed:version`, cargo would rerun every time if the file does
not exist, since cargo would expect the file to be generated by the
build-script. We could generate it, but that relies on the output of `git
describe`, whose dependencies we can only limit to anything in the
`.git`-folder, again causing unnecessary build-script runs.

Instead, this reads the `FISH_BUILD_VERSION`-env-variable at compile time
instead of the `version`-file, and falls back to calling git-describe through
the `git_version`-proc-macro. We thus do not need to deal with extraneous
build-script running.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
360ba46660 Make ConfigPaths store as PathBuf
- These are paths, we can just store them raw.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
55302629cd Add various FFI-interop-functions
- `libc::setlinebuf` is not available through Rust's libc it appears.
- autocxx fails to generate bindings using `*mut FILE`, instead go through
  `void*`
- rust_main needs `parse_util_detect_errors_in_ast`, which is _partially_
  ported, instead add FFI interop for C++.
- We need to set the filename if we are sourcing a file
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
25d207a8ce Make get_current_exe use impl AsRef<Path>
- It does not need to require the default to be valid UTF8
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
a92804a8a1 Port MISSING_HELP and MISSING (arg)
C++ main used getopt (no w!), which appears to internally print
error-messages. The Rust version will use `wgetopter_t`, and therefore needs to
print this itself.
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
7c2311abd7 Make methods in path not unnecessairly take &mut 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
cf8e0ae1b5 Make ParsedSource::new pub
It will be used from main
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
3777bc941f Port history::start_private_mode to Rust 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
c5c5043d7e Make PROGRAM_NAME safe, fix cmp
- It is currently never set, but will be set once `main` is ported
- `should_suppress_stderr_for_tests` used to be PROGRAM_NAME !=
  TESTS_PROGRAM_NAME, but the equivalent C++ code was
  `!std::wcscmp(program_name, TESTS_PROGRAM_NAME)`, and `wcsmp` returns
  zero if they are equal, thus is equivalent to `==` in Rust
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
e4df340f43 Forward CMake configs to Cargo 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
5db08e1126 Make CARGO_MANIFEST_DIR for fish-rust equal to src 2023-09-05 11:38:59 +02:00
Fabian Boehm
dcebffb9e7 funced: Note --wait
See #9999
2023-09-05 09:19:21 +02:00
Johannes Altmanninger
a3311c9b09 Fix incorrect port of write_to_fd 2023-09-03 14:03:14 +02:00
ghostflyby
c17fc65321 Update CHANGELOG.rst 2023-09-01 10:27:18 -07:00
ghostflyby
33ec25da8a completion for macOS java_home 2023-09-01 10:27:18 -07:00
Fabian Boehm
e52e7cea43 CHANGUELOGUE 2023-08-30 23:15:01 +02:00
Fabian Boehm
9f5f34267d key delay: Add tests
I already forsee these being annoying on CI, because they involve a timeout.
2023-08-30 23:13:10 +02:00
Fabian Boehm
f9b51cf8a6 docs: Add key timeout 2023-08-30 23:13:09 +02:00
yanshay
01db48a712 Added fish_sequence_key_delay_ms to set time to wait between sequence key presses (#7401) (#9926)
* added support for fish_sequence_key_delay_ms to set how long to wait between sequence key presses

* fixed cargo fmt
2023-08-30 23:12:22 +02:00
Fabian Boehm
b54faf9469 webconfig: Fix box shadow in dark mode
This changed from a separate div to directly on the body
2023-08-29 14:29:20 +02:00
Fabian Boehm
209af84a37 webconfig: Make prompt selectable 2023-08-29 14:29:20 +02:00
Fabian Boehm
4b4cd4c45a Merge pull request #9554 from septatrix/rewrite/webconfig-to-alpinejs
WIP: Proof of concept for replacing AngularJS with Alpine.js in webconfig component
2023-08-29 14:28:39 +02:00
Fabian Boehm
5e6f187ca6 Merge branch 'master' into rewrite/webconfig-to-alpinejs 2023-08-29 14:25:02 +02:00
Henrik Hørlück Berg
5734630966 Replace ATiltedTree/setup-rust with rust-toolchain
- https://github.com/ATiltedTree/setup-rust has not been committed to since May
  2022, I am uncertain about how widely used it is.
- It appears to have a bug with restoring its internal cache whenever there
  comes a new stable version (immediate guess would be the cache-key does not
  resolve `stable` to a specific version, which somehow breaks rustup, but I have not investigated)
- https://github.com/dtolnay/rust-toolchain is a more sensible take of https://github.com/actions-rs/toolchain,
  where the original repo appears to be unmaintained.
  It is implemented in one file of yaml/bash
  https://github.com/dtolnay/rust-toolchain/blob/master/action.yml, we could
  easily fork it if it becomes unmainted, unlike the other actions which uses
  unnecessary javascript
2023-08-28 23:15:25 +08:00
Yuntao Zhao
9d0d16686e Improve completion for rpm-ostree (#9910)
* Some temporary change until compose - commit

* First draft

* Fix an error that prints double completion

* Fix completion errors. Add rpm-ostree alias.

Fix cimpletion where it trigger by multiple commands.
Add update and remove, which are aliases for upgrade and uninstall.

* Remove -r when it is unnecessary

Some command need path completion for arguments no matter what,
which makes -r flag useless

* Remove -x for compose image
-x does not block the path anyway

* Add missing short otpion in compose image

Revert the last change to block -l completion

* Fix description

Fix multiple description.
2023-08-26 15:05:52 +02:00
Jason Nader
f6123d235c scp completions: fix path escaping 2023-08-26 15:04:48 +02:00
Fabian Boehm
7b5667b11f parse_execution: Remove dead tcgetattr code
This used to be assigned to the job, but that was removed in
f30ce21aaa.

Since then this was vestigial. It could have technically errored out,
but we should be catching that where we use the actual modes, not here.
2023-08-26 14:58:14 +02:00
Fabian Boehm
b454b3bc40 Also allow command and in a pipeline
Similar to `time`, except that one is more common as a command.

Note that this will also allow `builtin and`, which is somewhat
useless, but then it is also useless outside of a pipeline.

Addition to #9985
2023-08-26 13:45:54 +02:00
Fabian Boehm
55c425a0dd fish_key_reader: Humanize key descriptions
This used to print all codepoints outside of the ASCII range (i.e.
above 0x80) in \uXXXX or \UYYYYYYYY notation.

That's quite awkward, considering that this is about keys that are
being pressed, and many keyboards have actual symbols for these on
them - I have an "ö" key, so I would like to use `bind ö` and not
`bind \u00F6`. So we go by iswgraph.

On a slightly different note, `\e` was written as `\c[ (or \e)`. I do
not believe anyone really uses `\c[` (the `[` would need to
be escaped!), and it's confusing and unnecessary to even mention that.
2023-08-26 10:43:42 +02:00
Fabian Boehm
d803ebbff9 docs: Some teensy bits on if/while
The ``test`` thing was just duplicated, and ``while`` linked to the
if-*command* page, where the syntax section is probably nicer
2023-08-26 09:32:05 +02:00
Fabian Boehm
03e659f96d Bring back "(deleted)" hack for status fish-path
This is untested mostly because it is supremely awkward to test.

Fixes #9925
2023-08-25 22:02:55 +02:00
Fabian Boehm
482616f101 parse_util: Only reject time in a pipeline without decorator
This allows e.g. `foo | command time`, while still rejecting `foo | time`.

(this should really be done in the ast itself, but tbh most of
parse_util kinda should)

Fixes #9985
2023-08-25 19:45:15 +02:00
Fabian Boehm
b48fa1f1a0 Css refresh (#9982)
This cleans up the CSS, reduces the number of different colors and special settings we use.

It increases contrast so we now pass WCAG AAA (according to chromium), and switches to css variables for colors to make dark mode simpler to implement.
2023-08-25 17:13:35 +02:00
Fabian Boehm
03402e572d format 2023-08-25 16:28:41 +02:00
Fabian Boehm
e555f1b235 math: Fix docs on --scale
Fixes #9983
2023-08-25 16:17:59 +02:00
Fabian Boehm
06b89083d5 tinyexpr: Check for wcstod errors
This would otherwise unwrap() an Err and crash.
2023-08-25 16:15:52 +02:00
Fabian Boehm
b3ff982ad7 docs: Remove some jquery leftovers 2023-08-24 21:55:57 +02:00
Fabian Boehm
e3b1d327f1 docs: Remove reference to nonexistent style.css 2023-08-24 21:55:57 +02:00
Henrik Hørlück Berg
05c44df1a4 Run cargo fmt with Rustfmt 1.6.0
- "1.6.0" now supports formatting let-else statements which we use liberally,
  and appears to have some fixes in regards to long-indented-lines with macros
  like `wgettext_ft!`
- This commit updates the formatting so that devs with the latest stable don't
  see random format-fixes upon running `cargo fmt`
2023-08-24 18:16:24 +02:00
Fabian Boehm
0aa21440d1 docs/path: Remove incorrect status comments
During development, for a while `path change-extension` would return 0
when it found an extension to change.

This was later changed to returning 0 if there are any path arguments.

Neither of which is *super* useful, I admit, but we've picked one and
the docs shouldn't contradict it.
2023-08-24 18:06:03 +02:00
Fabian Boehm
8abd0319fb docs: Some slight rewordings 2023-08-23 23:08:56 +02:00
Fabian Boehm
5b1ff9459a sample_prompts/scales: Silence one last git call
Fixes #9975
2023-08-23 19:15:05 +02:00
Fabian Boehm
81cd035950 print_apt_packages: Go back to apt-cache for non-installed packages
Unfortunately, /var/lib/dpkg/status on recent-ish Debian versions at
least only contains the *installed* packages, rendering this solution
broken.

What we do instead is:

1. Remove a useless newline from each package, so our limit would now
let more full package data sets through
2. Increase the limit by 5x

This yields a completion that runs in ~800ms instead of ~700ms on a
raspberry pi, but gives ~10x the candidates, compared to the old
apt-cache version.

This partially reverts 96deaae7d8
2023-08-22 22:17:22 +02:00
Fabian Boehm
36a7924fa8 CHANGELOG: Document incompatible changes 2023-08-22 15:27:00 +02:00
figurantpp
6473a9c763 Shortens rsync completion description 2023-08-21 17:51:15 +02:00
figurantpp
5a934e7ae3 Removed type declarations from node descriptions 2023-08-21 17:51:15 +02:00
Kevin Cali
716001789b docs: correct insert mode key 2023-08-21 17:50:45 +02:00
Fabian Boehm
79aeb1656c docs/type: Correct "--no-functions"
This was accidentally changed in 3.2.0, when type was made a builtin.

Since it's been 4 releases and nobody has noticed, rather than
breaking things again let's leave it as it is, especially because the
option is named "--no-functions", not "--no-functions-or-builtins".
2023-08-21 17:44:21 +02:00
Fabian Boehm
53598d6a21 docs: More on if-conditions 2023-08-21 17:43:43 +02:00
Fabian Boehm
3711d0e06c docs: Clarify a sentence in the test docs 2023-08-20 22:10:30 +02:00
Fabian Boehm
eaa3f0486c math: Add tests for args via stdin and argv
This reads stdin and ignores argv, which is certainly a choice.

Leaving it this way for now, and possibly discussing later.
2023-08-20 14:52:58 +02:00
Fabian Boehm
3caabdcbc9 Switch math to using Arguments
Removes some duplicated code and lets this do chunked reading.
2023-08-20 14:52:58 +02:00
ridiculousfish
46f9a8bb28 Stop using sprintf in builtin_random 2023-08-19 20:19:54 -07:00
ridiculousfish
e500250775 Minor improvement to get_depth in ast.rs 2023-08-19 20:19:38 -07:00
ridiculousfish
04299cb4c9 Remove RgbColor::description
This was unused; deriving Debug is sufficient.
2023-08-19 20:04:23 -07:00
ridiculousfish
eeecd6517d Remove FileId::dump
Instead just derive Debug. No reason for this to be custom.
2023-08-19 17:45:17 -07:00
ridiculousfish
d2f7a3507b Implement to_wstr() for ParseTokenType and ParseKeyword
This cleans up some messy call sites.
2023-08-19 17:45:10 -07:00
ridiculousfish
cc1e4b998a Remove some dead bridge code
This was obviated after the AST was ported to Rust.
2023-08-19 16:31:42 -07:00
ysthakur
0f19d7118b Replace more escapes with quotes in man parser (#9961)
* Replace \(aq with "'" in man parser

* Also replace oq, dq, lq, and rq
2023-08-19 17:10:22 +02:00
Roland Fredenhagen
556bee6893 completions/iwctl: Show network details in completion (#9960)
* completions/iwctl: Show network details in completion

* apply review comments
2023-08-19 17:08:54 +02:00
Fabian Boehm
53a5ce52c5 Implement FLOGF formatting
Note: This *requires* an argument after the format string:

```rust
FLOGF!(debug, "foo");
```

won't compile. I think that's okay, because in that case you should
just use FLOG.

An alternative is to make it skip the sprintf.
2023-08-19 16:56:59 +02:00
Fabian Boehm
798d7427f7 Switch broken uses of FLOGF to FLOG
"FLOGF!" is supposed to treat its first argument as a format
string (but doesn't because that part isn't implemented currently).

That means running something like

```rust
FLOGF!(term_support, "curses var", var_name, "=", value);
```

That would rightly just print "curses var", ignoring the other
arguments.

By contrast, FLOG! is the literal "just join these as a string"
version.
2023-08-19 16:56:59 +02:00
Henrik Hørlück Berg
bc29b4aee1 Move edition and MSRV to workspace 2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
cf5b9d1c7e Specify default-members as fish-rust
We generally only want to operate on the fish crate itself (for now), so this
makes the most sense.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
c23f419af1 Use the workspace from CMake
- Make CMake use the correct target-path
- Make build.rs use the correct target dir

Workspaces place it in the project root by default, the alternative to making
this change is to add a `.cargo/config.toml` file with

```toml
[build]
target-dir = "fish-rust/target"
```

Which I think is unnecessary, as we likely want to use the new location anyways.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
824e76ebe4 Make CI use the workspace, so we format/check all 2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
87df7b9adf Use a cargo workspace
- This allows running `cargo fmt/clippy/test/etc` from root
- Ideally the root should be the fish-rust package instead of being virtual, but
  that requires changed to CMake/Corrosion. This change should instead be
  completely compatible with our existing setup.
- This also means we will only have on `Cargo.lock` for all current and future
  crates.
2023-08-19 15:18:38 +02:00
Henrik Hørlück Berg
1fa56972b5 Fix clippy lint in widestring-suffix 2023-08-19 15:18:38 +02:00
Fabian Boehm
2f86b31bd3 docs: More on scopes
Let's start with an example to motivate the rest
2023-08-19 12:26:27 +02:00
Fabian Boehm
566123edc6 Port builtin count to rust (#9963)
* Port builtin count to rust

* Explicitly use wstring
2023-08-18 23:18:52 +02:00
Fabian Boehm
a29aa44183 functions: Fix command name
This was "function", needs to be "function*s*".

It was only an issue in the option parsing because we set cmd there
again instead of passing it. Maybe these should just be file-level constants?
2023-08-18 17:16:44 +02:00
Axlefublr
fd68aca6ea fix __fish_list_current_token not recognizing ~ as $HOME (#9954)
* fix __fish_list_current_token not recognizing ~ as $HOME

* right. it was supposed to be $HOME. lol.
2023-08-16 22:05:59 +02:00
Fabian Boehm
1166424eeb Replace some uses of __fish_complete_list 2023-08-16 21:58:07 +02:00
Fabian Boehm
ec42c2ecec completions/exif: Remove use of eval 2023-08-16 21:58:07 +02:00
Henrik Hørlück Berg
88da7121af Adopt appendln 2023-08-16 18:37:27 +02:00
Henrik Hørlück Berg
dceefcdaba Add an appenln method to output_stream_t
This is an alternative to the very common pattern of

```rust
streams.err.append(output);
streams.err.append1('\n');
```

Which has negative performance implications, see https://github.com/fish-shell/fish-shell/pull/9229

It takes `Into<WString>` to hopefully avoid allocating anew when the argument is
a WString with leftover capacity
2023-08-16 18:37:27 +02:00
Fabian Boehm
0874dd6a96 pexpects: Fix spurious failure in generic.py
This used expect_re with a regex ending in `.*`, followed by an
`expect_prompt`.

This meant that, depending on the timing, the regex could swallow the
prompt marker, which caused extremely confusing output like

>Testing file pexpects/generic.py:Failed to match pattern: prompt 14
> ...
> OUTPUT      +1.33 ms (Line 70): \rprompt 13>functions\r\nN_, abbr,
> alias, bg, cd, [SNIP], up-or-search, vared, wait\r\n⏎
> \r⏎ \r\rprompt 14>

Yeah - it shows that "prompt 14" was in the output and it can't find
"prompt 14".

I could reproduce the failure locally when running the tests
repeatedly. I got one after 17 attempts and so far haven't been able
to reproduce it with this change applied.
2023-08-15 19:14:33 +02:00
Fabian Boehm
c07136e8d3 docs: Mention fish_cursor_replace
Fixes #9956
2023-08-15 19:11:03 +02:00
Fabian Boehm
1dc65a694d completions/read: Remove long-removed "--mode-name" flag
Disabled in c6093ad782 (in 2.7.0)
2023-08-15 18:34:41 +02:00
Gregory Anders
69ef51f417 Enable PWD reporting for iTerm2 2023-08-14 18:09:12 +02:00
ridiculousfish
d47b2a7e0b Refactor the killring to make it instanced
This improves test isolation.

Also standardize on the name "killring" instead of "kill list" and remove some
dead code.
2023-08-13 13:06:06 -07:00
ridiculousfish
2b25cd1654 Complete the transition of the kill ring and remove kill.cpp
This finishes off the transition of the kill ring from C++ to Rust, and removes
the C++ bits.
2023-08-13 13:06:06 -07:00
Fabian Boehm
995f12219b Use out_is_terminal
This removes some spurious unsafe and some imports.

Note: We don't use it in `test`, because that can be asked to check
arbitrary file descriptors, while this only checks stdout specifically.
2023-08-13 14:17:52 +02:00
Fabian Boehm
5f0df359b8 Remove C++ version of builtin functions
And the C++ reformat_for_screen and event_filter_names as there are no more users.
2023-08-13 14:17:44 +02:00
Fabian Boehm
6489ef5ac0 Rewrite builtin functions in rust 2023-08-13 14:17:44 +02:00
Fabian Boehm
5e78cf8c41 Add io_streams_t::out_is_terminal()
This encapsulates a "is our output going to the terminal" check we do
in a few places - functions, type, set_color, possibly test
2023-08-13 14:17:44 +02:00
Fabian Boehm
b75f901376 Fix reformat_for_screen
This had an infinite loop because it had two checks broken
2023-08-13 14:17:44 +02:00
Fabian Boehm
ee8e790aa7 Fix event::print's header printing
Turns out doing `==` on Enums with values will do a deep comparison,
including the values.

So EventDescription::Signal(SIGTERM) is !=
EventDescription::Signal(SIGWINCH).

That's not what we want here, so this does a bit of a roundabout thing.
2023-08-13 14:17:44 +02:00
Fabian Boehm
4f86f303f5 Make functions for builtin functions public
event filter names, function::set_desc, common::reformat_for_screen

This is the first use for each
2023-08-13 14:17:44 +02:00
99jte
5b136d450f Include the target of bad redirects in the error (#9947)
Fixes #8877
2023-08-13 14:01:32 +02:00
ridiculousfish
b2ff4d6bc0 Adopt Rust PosixSpawner
This removes the C++ posix_spawner_t, adopting the Rust implementation.
2023-08-12 17:15:21 -07:00
ridiculousfish
245f7db5b3 Port PosixSpawner to Rust
PosixSpawner is our wrapper around posix_spawn.
2023-08-12 16:59:38 -07:00
Roland Fredenhagen
408ab86090 Add iwctl completions (#9932)
* Add iwctl completions

* review-comments

* options
2023-08-10 19:35:27 +02:00
Emily Grace Seville
f9d21cc21d Add horcrux completion (#9922)
* feat(completions): horcrux

* feat(changelog): mention completion

* fix(completion): condition for -n
2023-08-09 17:30:34 +02:00
Gabriel Górski
21ddfabb8d Simplify and fix __fish_is_zfs_feature_enabled (#9939)
* Simplify and fix `__fish_is_zfs_feature_enabled`

Previously `__fish_is_zfs_feature_enabled` was doing
`<whitespace>$queried_feature<whitespace>` pattern matching which
was skipping the state part expected in the follow-up checking code.

Passing the dataset/snapshot in a `target` argument is pointless. As
none of the existing code attempts to do this plus it is also a
private function (`__` prefix), rename of the argument and removal
of extra text replacement should not be considered a breaking change.

* Changed the `&& \` into `|| return`

* Run `fish_indent`
2023-08-09 17:28:01 +02:00
Fabian Boehm
27a11ef7fe builtin builtin: Print help if run without an action to do
Fixes #9942
2023-08-09 17:26:07 +02:00
Henrik Hørlück Berg
0844247b43 Prefer os-unix prelude over importing everything separately 2023-08-09 15:00:58 +02:00
Henrik Hørlück Berg
131e249b0c Adopt the builtin prelude 2023-08-09 15:00:58 +02:00
Henrik Hørlück Berg
773bafb7c7 Add a builtin prelude
- Most builtins share a lot of similar imports
2023-08-09 15:00:58 +02:00
Henrik Hørlück Berg
1b018c8bfb Add note to rust devel about the wchar builtin 2023-08-09 15:00:58 +02:00
Henrik Hørlück Berg
fae090ea67 Adopt the wchar prelude 2023-08-09 15:00:58 +02:00
Henrik Hørlück Berg
5d58652394 Add a wchar prelude
- This will hopefully make it easier to always include WExt and ToWString, and
  make using WStr/WString more natural
2023-08-09 15:00:58 +02:00
Johannes Altmanninger
b7f7dcf788 Copy history pager search field to command line on Enter if no match
Closes #9934
2023-08-08 21:53:42 +02:00
Henrik Hørlück Berg
3a484480bf Remove premature optimization
The `impl<T> Hash for &T` hashes the string itself[^1].
It is unclear if that is actually faster than just calling `keyfunc` multiple times (they should all be linear).
For context, Rust by default uses SipHash 1-3 db1b1919ba
An alternative would be to store it as raw pointers aka `*const T`, which have a cheaper hash impl.
That has a more complicated implementation + removes lifetimes.

This commit rather removes the premature optimization.

[^1]: Source: https://doc.rust-lang.org/std/ptr/fn.hash.html
2023-08-07 21:01:11 -07:00
Henrik Hørlück Berg
4a4171c34a Forward some error messages and fix a bug
- The Err-variants will be used by e.g. wildcard, so might as well change it
  now.
- `create_directory` should now not infinitely loop until  it fails with an
  error message that isn't `EAGAIN`
2023-08-07 21:01:11 -07:00
Henrik Hørlück Berg
f4a5de1fbf Port builtins/path to Rust 2023-08-07 21:01:11 -07:00
ridiculousfish
6d4916a77c Stop using path sort in some path tests
Globs are already sorted, so this should be unnecessary. Remove these and add a
test that we are sorted already.
2023-08-07 19:56:27 -07:00
Fabian Boehm
73d30ac4f8 parse_execution: Remove some useless no_exec checks
These are both clearly behind early returns, there is no need to check it again.

This isn't a case where we're doing logic gymnastics to see that it
can't be run without no_exec() being handled, this is

```c++
if (no_exec()) return;
// ..
// ..
// ..

if (no_exec()) foo;
```
2023-08-07 17:42:47 +02:00
Fabian Boehm
ab6abaa114 Fix path tests on FreeBSD 2023-08-07 17:22:19 +02:00
ridiculousfish
f4132af114 Further improve builtin path tests 2023-08-06 18:51:11 -07:00
ridiculousfish
62ad661a5c Add some more builtin path tests
This plugs some holes in our tests.
2023-08-06 18:16:07 -07:00
ridiculousfish
2d779fb194 Fix additional clippy lint errors
These lint errors appear new with clippy 0.1.72.
2023-08-05 17:29:53 -07:00
ridiculousfish
8771d8f903 Remove some pub(self)s
This fixes a clippy 0.1.72 lint
2023-08-05 15:50:07 -07:00
ridiculousfish
0d3f943f30 Add some additional tests for builtin math
This fills some gaps in our error message test coverage.
2023-08-05 11:54:39 -07:00
David Adam
09ed315159 README: remove Xcode, minor linting
Closes #9924.
2023-08-04 22:28:11 +08:00
Henrik Hørlück Berg
900a048744 Don't segfault if user has an invalid locale
Fixes #9928
2023-08-03 19:55:05 +02:00
Fabian Boehm
ee75b45687 Remove a waccess call when completing executables
We have already run waccess with X_OK. We already *know* the file is
executable.

There is no reason to check again.

Restores some of the speedup from the fast_waccess hack that was
removed to fix #9699.
2023-08-03 19:53:07 +02:00
Fabian Boehm
5de19d2e84 Remove broken &
Fixes the build
2023-08-02 21:21:46 +02:00
Henrik Hørlück Berg
4728eaf642 Don't specify a min macOS version when not needed
Corrosion does not forward the `CMAKE_OSX_DEPLOYMENT_TARGET` to cargo.
As a result we end up building the Rust-libraries for the default target,
which is usually current macOS-version. But CMake links using the set
target, so we link for a version older than we built for.

To properly build for older macOS versions, the env variable
`MACOSX_DEPLOYMENT_TARGET` should instead be set, which cargo,
cmake and friends read by default. This can then lead to
warnings if you have libraries (e.g. PCRE2) built for newer
than our minimum version. Therefore we do not set a min-target
by default.
2023-08-02 22:42:52 +08:00
Henrik Hørlück Berg
55b6d7cd74 Revert "Fix built for newer than linked macOS warning"
This reverts commit 69ed2d1ca7. It was never meant
to be merged.
2023-08-02 22:42:52 +08:00
David Adam
35aa7636eb fds: add make_fd_{,non}blocking implementations in Rust 2023-08-01 22:56:25 +08:00
David Adam
0b291355b2 wutil: add perror implementation that takes an io::Error 2023-08-01 22:56:25 +08:00
Roland Fredenhagen
3d0b66c825 In .editorconfig replace max_line_length: none with off.
According to
https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#max_line_length
that is the correct value to disable this property.
2023-07-31 09:18:46 +02:00
AsukaMinato
9a9e133b18 add gcc completion lm lz lrt (#9919)
add some gcc completion options
2023-07-29 10:52:23 +08:00
Henrik Hørlück Berg
2ec36338f2 Very minor leftover codereview var-renaming 2023-07-27 22:00:03 -07:00
Henrik Hørlück Berg
cdc08dbb71 Add back well-backed comment
- The dermination is from commit 7988cff6bd
- See PR https://github.com/fish-shell/fish-shell/pull/9139
2023-07-27 22:00:03 -07:00
Henrik Hørlück Berg
6dd2cd2b20 Fix behaviour in the presence of non-visible width
Padding with an unprintable character is now disallowed, like it was for other
zero-length characters.

`string shorten` now ignores escape sequences and non-printable characters
when calculating the visible width of the ellipsis used (except for `\b`,
which is treated as a width of -1).
Previously `fish_wcswidth` returned a length of -1 when the ellipsis-str
contained any non-printable character, causing the command to poentially
print a larger width than expected.

This also fixes an integer overflows in `string shorten`'s
`max` and `max2`, when the cumulative sum of character widths turned negative
(e.g. with any non-printable characters, or `\b` after the changes above).
The overflow potentially caused strings containing non-printable characters
to be truncated.

This adds test that verify the fixed behaviour.
2023-07-27 22:00:03 -07:00
Henrik Hørlück Berg
20be990fd9 Port builtins/string to Rust
- Add test to verify piped string replace exit code

Ensure fields parsing error messages are the same.

Note: C++ relied upon the value of the parsed value even when `errno` was set,
that is defined behaviour we should not rely on, and cannot easilt be replicated from Rust.
Therefore the Rust version will change the following error behaviour from:

```shell
> string split --fields=a "" abc
string split: Invalid fields value 'a'
> string split --fields=1a "" abc
string split: 1a: invalid integer
```

To:

```shell
> string split --fields=a "" abc
string split: a: invalid integer
> string split --fields=1a "" abc
string split: 1a: invalid integer
```
2023-07-27 22:00:03 -07:00
AsukaMinato
2110b36426 more gcc -O completion
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
2023-07-27 17:44:41 +02:00
Emily Grace Seville
6ce2ffbbb0 Add Krita completions (#9903)
* feat(completions): support Krita

* feat(completions): support summary options for Krita

* feat(completions): support remaining options for Krita

* feat(completions): remove debug instructions

* feat(completions): hide completions for sizes for Krita

* feat(completions): fix Krita

* feat(changelog): mention new completion

* fix(completions): refactor Krita

* fix(completion): reformat

* feat(completion): dynamically generate workspace list

* fix(completion): refactor

* fix(completion): krita

* fix(completions): use printf
2023-07-27 17:43:51 +02:00
Emily Grace Seville
8d3885b9cb Add Blender completions (#9905) 2023-07-27 17:42:55 +02:00
Pavel savchenko
c56f9e1981 Docs: correct small grammatical error in read.rst 2023-07-26 09:20:49 +02:00
Fabian Boehm
ed881bcdd8 Make default theme use named colors only
This gives us the biggest chance that these are *visible* in the
terminal, which allows people to choose something nicer.

It changes two colors - the autosuggestion and the pager
description (i.e. the completion descriptions in the pager).

In a bunch of terminals I've tested these are pretty similar - for the
most part brblack for the suggestions is a bit brighter than 555, and
yellow for the descriptions is less blue
than the original.

We could also make the descriptions brblack, but that's for later.

Technically we are a bit naughty in having a few foreground and
background pairs that might not be visible,
but there's nothing we can do if someone makes white invisible on brblack.

Fixes #9913
Fixes #3443
2023-07-25 16:42:24 +02:00
ridiculousfish
ade6650599 Remove FunctionPropertiesRef type alias
Per code review, this type alias was confusing.
2023-07-23 17:18:36 -07:00
ridiculousfish
e24a16bd31 function: make inherit_vars a boxed slice instead of a hash map
Empty hash maps muck around with TLS. Per code review, use a boxed slice
of a tuple instead. This has the nice benefit of printing inherited vars
in sorted order.
2023-07-23 17:18:36 -07:00
ridiculousfish
a672edc0d5 Adopt the new function store and rewrite builtin_function
This adopts the new function store, replacing the C++ version.

It also reimplements builtin_function in Rust, as these was too coupled to
the function store to handle in a separate commit.
2023-07-23 17:18:36 -07:00
ridiculousfish
076f317c31 Implement (but do not yet adopt) fish function store in Rust
This reimplements the function module in Rust. The function module stores the
global set of fish functions, and provides information about them.
2023-07-23 17:18:36 -07:00
EmilySeville7cfg
3fde15fd9a feat(changelog): explain changes 2023-07-23 15:09:35 -07:00
EmilySeville7cfg
2bc605625e feat(completions): gimp support 2023-07-23 15:09:35 -07:00
Fabian Boehm
5f26c56ed5 completions/pactl: Fix matching objects
This didn't work for something like `pactl set-card-profile foo
<TAB>`,
because it didn't allow for the card name, as it would just print the
index again and again.
2023-07-19 18:13:40 +02:00
Fabian Boehm
2a16e3513e Issue template: Unset XDG_CONFIG_HOME
Fixes #9898
2023-07-17 18:55:06 +02:00
Henrik Hørlück Berg
6325b3662d Fix #9899 integer overflow in string repeat
We could end up overflowing if we print out something that's a multiple of the
chunk size, which would then finish printing in the chunk-printing, but not
break out early.
2023-07-17 15:41:08 +02:00
ridiculousfish
2a13a30807 Clean up DirIter
DirIter had a serious bug where it would crash on an invalid path. Make it more
robust and rationalize its error handling. Move it into its own module and add
tests.
2023-07-16 12:05:29 -07:00
ridiculousfish
f5e5896c70 Remove the EventDescription wrapper type
Prior to this change, we had a silly wrapper type EventDescription which wrapped
EventType, which actually described the event.

Remove this wrapper and rename EventType to EventDescription (since it describes
more than just the type of event).
2023-07-15 11:59:08 -07:00
ridiculousfish
ecfabf4db8 argparse: Use a named constant for RETURN_IN_ORDER returns
The RETURN_IN_ORDER argparse mode (enabled via leading '-') causes non-options
(i.e. positionals) to be returned intermixed with options in the original order,
instead of being permuted to the end. Such positionals are identified via the
option sentinel of char code 1. Use a real named constant for this return,
rather than weird stuff like '\u{1}'
2023-07-15 11:35:13 -07:00
Fabian Boehm
bfd97adbda completions/rclone: Add version parsing
This had a weird, unnecessary and terrible backwards-incompatibility
in how you get the completions out.

I do not like it but I am in a good enough mood to work around it.

See #9878.
2023-07-15 14:25:41 +02:00
Fabian Boehm
3d7ad4d3f1 README: Update dependencies for riir
Fixes #9893
2023-07-15 10:56:28 +02:00
Fabian Boehm
54fa1ad6ec Revert "Try to move rust CI back to 1.70"
Should *hopefully* be fixed by deleting the cache at https://github.com/fish-shell/fish-shell/actions/caches.

This reverts commit 5c29ff52fb.
2023-07-14 21:36:43 +02:00
Fabian Boehm
5c29ff52fb Try to move rust CI back to 1.70
1.71 seems to have weird issues on Github Actions and that makes the
tests fail for no good reason

(gosh dangit YAML)
2023-07-14 21:11:15 +02:00
Fabian Boehm
6823f5e337 wildcard: Remove useless access() call for trailing slash
This confirmed that a file existed via access(file, F_OK).

But we already *know* that it does because this is the expansion for
the "trailing slash" - by definition all wildcard components up to
here have already been checked.

And it's not checking for directoryness either because it does F_OK.

This will remove one `access()` per result, which will cut the number
of syscalls needed for a glob that ends in a "/" in half.

This brings us on-par with e.g. `ls` (which uses statx while we use
newfstatat, but that should have about the same results)

Fixes #9891.
2023-07-14 20:20:34 +02:00
David Adam
861da91bf1 drop unused functions and configure checks
Remove the following C++ functions/methods, which have no callers:

fallback.cpp:
- wcstod_l

proc.cpp:
- job_t::get_processes

wutil.cpp:
- fish_wcstoll
- fish_wcstoull

Also drop unused configure checks/defines:
- HAVE_WCSTOD_L
- HAVE_USELOCALE
2023-07-14 20:48:56 +08:00
David Adam
44cf0e5043 add comment regarding importance of unused describe_char function 2023-07-14 20:48:56 +08:00
David Adam
0037e6e98d drop ported C++ functions
Remove the following C++ functions/methods, which have all been ported to Rust and no longer have any callers in C++:
common.cpp:
- assert_is_locked/ASSERT_IS_LOCKED

path.cpp:
- path_make_canonical

wutil.cpp:
- wreadlink
- fish_iswgraph
- file_id_t::older_than
2023-07-14 20:48:56 +08:00
Fabian Boehm
493cbeb84c completions/git: Trim with the regex
This gives us another few percent.

It's not *technically* the same because `trim` would remove a run of
quotes, but that would be wrong anyway.
2023-07-13 18:05:55 +02:00
Fabian Boehm
dd26611c0f completions/git: Move some variables to the v1 path
No longer used elsewhere
2023-07-13 16:51:16 +02:00
Fabian Boehm
7f76f75966 completions/git: Add fast path for untracked files
It's super easy to get a lot of these and they'll otherwise slow down
the completions a lot.

This makes `git add <TAB>` ~5-6x faster with about 4000 untracked
files (a copy of the fish build directory). It goes from 1.5 seconds to
250ms.

This is just for the git >= 2.11 path, but the other one would require
more checking and since git 2.11 is almost 7 years old now that's not
worth it.
2023-07-13 16:46:22 +02:00
Fabian Boehm
1f1975689e completions/git: Don't check commandline so much
This just caches some checks, speeding up `git add ` completions by
~33% with 4000 matching files.
2023-07-13 16:31:33 +02:00
Fabian Boehm
a6c36a014c Return a falsey status if the last -c command has a parse error
This makes `fish -c begin` fail with a status of 127 - it already
printed a syntax error so that was weird. (127 was the status for
syntax errors when piping to fish, so we stay consistent with that)

We allow multiple `-c` commands, and this will return the regular
status if the last `-c` succeeded.

This is fundamentally an extremely weird situation but this is the
simple targeted fix - we did nothing, unsuccessfully, so we should
fail.

Things to consider in future:

1. Return something better than 127 - that's the status for "unknown
command"!
2. Fail after a `-c` failed, potentially even checking all of them
before executing the first?

Fixes #9888
2023-07-12 18:06:34 +02:00
Henrik Hørlück Berg
63b23713f2 Support thread-safe feature-flag-dependant tests
This also allows scoped feature tests that makes testing feature flags thread-safe.
As in you can guarantee that the test actually has the correct feature flag
value, regardless of which other tests are running in parallell.
2023-07-11 12:05:38 -07:00
Henrik Hørlück Berg
f1cd43d58b Disallow using set outside of tests, minor fixes 2023-07-11 12:05:38 -07:00
Henrik Hørlück Berg
726819e8ee Clean up feature flags API
This also cleans up and removes unnecessary usage of FFI-oriented `feature_metadata_t`,
which is only used from Rust code after `builtins/status` was ported.
2023-07-11 12:05:38 -07:00
Fabian Boehm
2b0e3ba3b8 __fish_print_hostnames: Fix regex
This used `]` when it should have been `}`, which made the regex nonsensical

Broken since 94c12d84e2 in 2016
2023-07-11 20:50:56 +02:00
Fabian Boehm
1a11cee559 functions/cd: Optimize check for too many args
This ran two `test`s a `count` and one `echo`, which is a bit wasteful.

So instead, for the common case where you pass one argument, this will
run one `set -q`.

This can save off ~160 microseconds for each ordinary `cd`, which
speeds it up by a factor of ~2 (so 1000 runs of cd might take 260ms
instead of 550ms).

Ideally the cd function would just be incorporated into the builtin,
but that's a bigger change.
2023-07-11 18:01:29 +02:00
elyashiv
3fbff14e9b [tests] added test for escaped job summary 2023-07-10 18:38:26 +02:00
elyashiv
4a2c7e38d0 [jobs.cpp] added const to escaped cmd string 2023-07-10 18:38:26 +02:00
elyashiv
0dfef25b4c [CHANGELOG.rst] added line about escaping jobs 2023-07-10 18:38:26 +02:00
elyashiv
4ea867bc55 [jobs.cpp] add escaping for job comamnd 2023-07-10 18:38:26 +02:00
Adam J. Stewart
72de1dc201 Docs: fix code block 2023-07-10 18:31:46 +02:00
ridiculousfish
57afaf7fb2 Restore the behavior of remembering the CWD fd in the parser
This will be important for concurrent execution, because different parsers will
have different working directories.
2023-07-10 21:30:37 +08:00
David Adam
289fbecaa9 Rewrite cd builtin in Rust
Note this is slightly incomplete - the FD is not moved into the parser, and so
will be freed at the end of each directory change. The FD saved in the parser is
never actually used in existing code, so this doesn't break anything, but will
need to be corrected once the parser is ported.
2023-07-10 21:30:37 +08:00
Adam J. Stewart
e31c0ebb05 Fix grammar in completion docs 2023-07-09 14:11:01 +08:00
ridiculousfish
c1e1efd747 Pull an allocation out of the string escape test inner loop 2023-07-08 11:26:32 -07:00
ridiculousfish
98d88e06ff Use setlocale() in the test_convert test
This "fixes" (or at least hides) the intermittent test_convert failures,
as we no longer race with other setlocale calls.
2023-07-08 11:22:47 -07:00
ridiculousfish
a99fa201b6 Make escape_test an ordinary function
This did not need to be a macro.
2023-07-08 11:19:44 -07:00
Henrik Hørlück Berg
7b0f9fd5f8 Double the speed of cargo test, actually run test
- Parallelize the slow tests if possible.
- `test_convert_ascii` was missing a `#[test]` annotation
2023-07-08 11:05:55 -07:00
Henrik Hørlück Berg
47f1dbe56c Make test_convert seedable, but generate the seed 2023-07-08 11:05:55 -07:00
pd
ac2810e9ef Fix rclone autocompletion script sourcing issue in fish shell 2023-07-07 21:34:12 +02:00
Fabian Boehm
1a52f79c24 docs/test: More on THE PROBLEM 2023-07-06 18:39:42 +02:00
may
e3e7ab77ad add stash completions to git show and git diff 2023-07-05 10:53:17 +08:00
David Adam
87307775fc fds: add comment on O_CLOEXEC fallback being dropped 2023-07-05 10:30:27 +08:00
ridiculousfish
bee422fea2 Use a faster, deterministic RNG in the string escape tests
This shaves about 9 seconds off of the runtime, and makes the test
deterministic.

We do not touch the test_convert test because there is a known failure and we
need to track it down before making it deterministic.
2023-07-04 13:27:53 -07:00
ridiculousfish
0bfe83ce88 Replace write! calls with explicit hex formatting
Rather than relying Rust's formatting, just compute the hex chars directly.

This shaves about 6 seconds off of the test runtime.
2023-07-04 13:27:53 -07:00
ridiculousfish
c48c0bb226 Replace sprintf call with write!
This reduces the time for the Rust tests from a few minutes to ~40 seconds.

Also fix some bogus comments which were ported from C++.
2023-07-04 13:27:53 -07:00
ridiculousfish
b16f617fb3 Migrate string and lock tests into their own files
Get some stuff out of the common module, which is growing large.

Also migrate the tests into "native" Rust tests so they will run in parallel.
We have to use an explicit setlocale() call to get a multibyte locale, for the
"crazy" tests.
2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
69ed2d1ca7 Fix built for newer than linked macOS warning 2023-07-04 13:27:53 -07:00
ridiculousfish
eaf8e73c42 Make escape/unescape string_var hew more closely to the C++ 2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
970ed610df Avoid string copying to speed up asan 2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
595d593732 Fully migrate to Rust escape string tests and code
Co-Authored-By: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-07-04 13:27:53 -07:00
Henrik Hørlück Berg
0a4bcf7430 Port (un)escape-tests, fix a couple bugs 2023-07-04 13:27:53 -07:00
ridiculousfish
ec28a30bd6 Fix a clippy lint warning 2023-07-04 13:26:19 -07:00
ridiculousfish
35f8f421fe topic_monitor to migrate from wperror to perror
This avoids needing to use the ffi
2023-07-04 13:26:19 -07:00
ridiculousfish
15361f62ed signal.rs to stop using wperror
This needed to cross the ffi which is annoying in tests. Use the Rust perror()
instead.
2023-07-04 13:26:19 -07:00
ridiculousfish
1076642770 Remove future_feature_flags_init
Make Features just a global. After the Rust port we can make it use atomics and
no longer be mut.

This allows feature flags to be used in Rust tests.
2023-07-04 13:26:19 -07:00
ridiculousfish
37fed01642 FLOG to stop depending on the ffi
Prior to this commit, FLOG used the ffi bridge to get the output fd. Invert
this: have fish set the output fd within main. This allows FLOG to be used in
pure Rust tests.
2023-07-04 13:26:19 -07:00
Johannes Altmanninger
052823c120 history pager: delete selected history entry with Shift-Delete
After accidentally running a command that includes a pasted password, I want
to delete command from history. Today we need to recall or type (part of)
that command and type "history delete".  Let's maybe add a shortcut to do
this from the history pager.

The current shortcut is Shift+Delete. I don't think that's very discoverable,
maybe we should use Delete instead (but only if the cursor is at the end of
the commandline, otherwise delete a char).

Closes #9454
2023-07-04 18:42:11 +02:00
Johannes Altmanninger
857612d243 Simplify logic for special input functions "and" & "or"
No functional change.
2023-07-04 18:42:11 +02:00
Johannes Altmanninger
5678602af4 Stop special input functions "and" & "or" from tearing up multi-char binding
The tentative binding for the upcoming "history-pager-delete" is

    bind -k sdc history-pager-delete or backward-delete-char

When Shift+Delete is pressed while the history pager is active,
"history-pager-delete" succeeds. In this case, the "or" needs to kick the
"backward-delete-char" out of the input queue.
After doing so, it continues reading, but interprets the input as
single-char binding. This breaks when the next key emits a multi-char sequence,
like the arrow keys.

Fix this by reading a full sequence, which means we need to run "read_char()"
instead of "read_ch()" (confusing, right?).

I'm still working on writing a test. Somehow this only reproduces in the
history pager where Shift+Delete followed by down arrow emits "[B" (since
we swallowed the leading escape char).  Confusingly, it doesn't do that in
the commandline or the completion search field.
2023-07-04 18:42:11 +02:00
Fabian Boehm
92551e1818 docs/abbr: Explain saving abbrs 2023-07-04 18:30:28 +02:00
David Adam
472d7efe34 completions/status: add basename and dirname 2023-07-04 23:32:39 +08:00
ridiculousfish
2ec482e94a Move the Option out of ParsedSourceRef, and use Arc instead of Rc
Two small fixes:

1. ParsedSourceRef, if present, should not be None; express that in the type.
2. ParsedSourceRef is intended to be shareable across threads; make it so.
2023-07-02 17:46:04 -07:00
Fabian Boehm
a996c8c7dd Fix clippy
As always: Some petty complaints of no actual use
2023-07-02 10:10:29 +02:00
ridiculousfish
12dfbc14d7 Make builtin status long options const
By using an explicit match instead of unwrap(), we can avoid the use of Lazy.
2023-07-01 16:05:10 -07:00
ridiculousfish
1c5c1993dd Make wdirname and wbasename go &wstr -> &wstr
There is no reason for either of these functions to allocate, so have
them not do it.
2023-07-01 15:41:46 -07:00
ridiculousfish
d26d4f36b0 Minor fixes to builtin status
Use as_wstr() instead of from_ffi() in a few places to avoid an allocation,
and make job_control_t work in &wstr instead of &str to reduce complexity at
the call sites.
2023-07-01 15:33:11 -07:00
Henrik Hørlück Berg
4061c7250c Replace status_cmd with an option
- Using an option makes it much clearer that the check for empty args is
  redundant.
- Also prefer implementing TryFrom only for &str, to not hide the string
  conversion and allocation happening.
2023-07-01 15:33:01 -07:00
Henrik Hørlück Berg
cee2b7c4a2 Remove C++ code 2023-07-01 15:33:01 -07:00
Henrik Hørlück Berg
7b3637cd1f Port builtins/status to fish
- Also port tests of wdirname and wbasename, as they were bugged
2023-07-01 15:33:01 -07:00
ridiculousfish
37337683cb Revert "Fix Rust wdirname and wbasename and port the C++ tests"
This reverts commit 6b1c2e169c.

We're about to rework these in the builtin status changes.
2023-07-01 13:38:38 -07:00
ridiculousfish
6b1c2e169c Fix Rust wdirname and wbasename and port the C++ tests
These functions were rather buggy; add tests and fix the test failures.
2023-07-01 12:45:11 -07:00
ridiculousfish
b4570623e9 Changelog fix for #9863 2023-07-01 11:08:53 -07:00
Francois Laithier
a7ac92f62f Use __fish_complete_directories to help complete dirs only 2023-07-01 11:01:36 -07:00
Francois Laithier
911a5a97a8 Add completion option for curl
Add missing completion for curl's `--output-dir` option
2023-07-01 11:01:36 -07:00
David Adam
ce9f95128a type/command: implement optimisation for --all
This was present in the C++ version for command, though never for type.

Checking over all elements of PATH can be slow on some platforms eg
WSL2, so only do that when used with `--all`.

Based on discussion in
https://github.com/fish-shell/fish-shell/pull/9856
2023-06-30 10:05:01 +08:00
David Adam
14cfd268d8 path: drop path_get_paths_ffi
f77dc24 provides the pieces to call path_get_paths directly from Rust
code. Drop the C++ implementation and its FFI.
2023-06-30 10:05:01 +08:00
Henrik Hørlück Berg
1f67bcbb39 Update dependencies for asan to work
Rust nightly changed the name of a preview feature, which broke proc-macro2,
see https://github.com/rust-lang/rust/issues/113152
2023-06-29 20:02:43 -05:00
Fabian Boehm
9bcb4dcf70 docs: Remove some needless margins for nested lists
This double-indented a nested list *and* added some gaps at the
bottom.

Other lists are unaffected
2023-06-28 16:32:55 +02:00
Fabian Boehm
b043a1c35f completions/help: Add custom-prompt 2023-06-28 16:13:20 +02:00
Fabian Boehm
22f2926185 docs/prompt: Fix nested list formatting
Sphinx needs three spaces here at least
2023-06-28 16:13:00 +02:00
Fabian Boehm
c7b43b3abf Truncate builtin arguments on NUL
This restores the status quo where builtins are like external commands
in that they can't see anything after a 0x00, because that's the c-style
string terminator.
2023-06-24 21:26:44 +02:00
Fabian Boehm
41568eb2a8 Move NUL-handling tests to their own file 2023-06-24 21:26:44 +02:00
David Adam
78940a6026 print_help: make function public 2023-06-24 18:21:21 +08:00
Fabian Boehm
11c8d9684e Make NULs work for builtins (#9859)
* Make NULs work for builtins

This switches from passing a c-string to output_stream_t::append to
passing a proper string.

That means a builtin that prints a NUL no longer crashes with "thread '' panicked
at 'String contained intermediate NUL character: ".

Instead, it will actually handle the NUL, even as an argument.

That means something like

`echo foo\x00bar` will now actually print a NUL instead of truncating
after the `foo` because we passed c-strings around everywhere.

The former is *necessary* for e.g. `string`, the latter is a change
that on the whole makes dealing with NULs easier, but it is a
behavioral change.

To restore the c-string behavior we would have to truncate arguments
at NUL.

See #9739.

* Use AsRef instead of trait bound
2023-06-22 20:50:22 +02:00
David Adam
a75de42f4b docs: use consistent spelling of color
i miss u
2023-06-21 21:13:03 +08:00
David Adam
229f19a6e9 docs: slight update to writing your own prompt doc 2023-06-21 21:12:12 +08:00
Fabian Boehm
c385027eca docs: Add "Writing your own prompt" doc (#9841)
* docs: Add "Writing your own prompt" doc

* Remove a space from the "output"

* some teensy adjustments

* Address feedback

* envvar one more PWD

* More html warning
2023-06-20 19:43:09 +02:00
ridiculousfish
f77dc2451e Expose Rust EnvStack from parser_t
Prior to this change, parser_t exposed an environment_t, and Rust had to go
through that. But because we have implemented Environment in Rust, it is
better to just expose the native Environment from parser_t. Make that
change and update call sites.
2023-06-19 13:45:54 -07:00
ridiculousfish
6936c944c1 Add some fixes atop argparse
This switches to using the WExt functions, which deal directly in chars
and char indices.
2023-06-19 13:45:54 -07:00
Henrik Hørlück Berg
292f7b2be1 Port builtins/argparse to Rust 2023-06-19 13:45:54 -07:00
David Adam
6229f08200 rust/print_help: simplify use of OsStrings
See discussion in https://github.com/fish-shell/fish-shell/pull/9818#discussion_r1210829722
2023-06-19 21:57:53 +08:00
Fabian Boehm
0cfdc90551 completions/unzip: Dangit FreeBSD
No "--help" and the man page doesn't mention "-h".
2023-06-18 21:27:29 +02:00
AsukaMinato
bab8fb9517 Add i o for unzip (#9850)
* add -I -O for unzip

* for different distroes.

* avoid grep
2023-06-18 21:04:43 +02:00
ridiculousfish
99c2e476ac Bravely remove writembs macro
The writembs macro was ported from C++, which attempted to detect when a NULL
termcap was used. However we have never gotten a bug report from this. Bravely
remove it.
2023-06-17 16:04:34 -07:00
ridiculousfish
21f08ee9fd Simplify some curses stuff and enforce that caps are nonempty
The outputter code has a lot of checks that string capabilities are non-empty;
just enforce that at the curses layer so we can remove those checks.

Also remove some types and traits, replacing them with simple functions.
2023-06-17 13:52:53 -07:00
ridiculousfish
dec5a64232 Outputter to implement Write
By implementing Write directly, we can remove some local buffers and uses of
Cursor. This both simplifies and optimizes the code.
2023-06-17 12:14:42 -07:00
ridiculousfish
64a40d2410 write_color_escape to stop returning bool
This bool return was always true, so we don't need it.
2023-06-17 12:14:42 -07:00
ridiculousfish
51a971bf16 Remove tparm0
Per code review, we think that tparm does nothing when there are no parameters,
and it is safe to remove it, even though this is a break from C++. This
simplifies some code.
2023-06-17 12:14:42 -07:00
ridiculousfish
a09947cd99 Implement builtin set_color in Rust
This rewrites the set_color builtin in Rust, restoring italics support in
iTerm2.
2023-06-17 12:14:42 -07:00
ridiculousfish
84b24d5615 Adopt the new output.rs
This switches output.cpp from C++ to Rust.
2023-06-17 12:14:42 -07:00
ridiculousfish
8f38e175ce Add from_ffi() to rgb_color_t
This allows converting a C++ rgb_color_t to a Rust RgbColor.
2023-06-17 12:14:42 -07:00
ridiculousfish
8604be9a4f Port (but do not yet adopt) output.cpp to Rust 2023-06-17 12:14:42 -07:00
ridiculousfish
76205e5b55 Port debug_thread_error() to Rust 2023-06-17 12:14:42 -07:00
Fabian Boehm
38ac21ba5e alias: Escape the function name when replacing
Fixes #8720
2023-06-17 07:46:07 +02:00
Fabian Boehm
f980125fb9 docs: More on profiling 2023-06-16 16:22:58 +02:00
Fabian Boehm
bc190ee818 docs: Turn off highlighting correctly in fish_config 2023-06-16 16:17:58 +02:00
Fabian Boehm
4e3b3b3b0a share/config.fish: Quit if job expansion hack errors
This prevents something like `fg %5` to foreground the first job if
there is no fifth.

Fixes #9835
2023-06-10 15:36:36 +02:00
Fabian Boehm
65769bf8c8 history: Allow deleting ranges
This allows giving a range like "5..7".

It works in combination with more (including overlapping) ranges or
single indices.

Fixes #9736
2023-06-10 15:35:40 +02:00
Andre Eckardt
cbf9a3bbbd improved print CSS for fish_config
This commit introduces a fishconfig_print.css that contains special CSS styles that only apply when printing the fishconfig page. This is especially useful when the user wants to print out the key bindings.
2023-06-10 09:47:01 +02:00
Fabian Boehm
516b8da302 Allow disabling focus reporting 2023-06-10 07:25:20 +02:00
Fabian Boehm
ffd43c950a docs/fish_config: Document theme files 2023-06-09 16:59:02 +02:00
Amy Grace
4c9fa511e8 Force use of macOS's builtin manpath
Prevent a useless warning msg if Homebrew's `man-db` is installed and configured
2023-06-06 13:12:30 -05:00
Fabian Boehm
3cd527a62e docs: Improve bg docs
Show an actual session here, to explain what you would actually do
with it.
2023-06-05 18:26:13 +02:00
ridiculousfish
908e234bf6 Changelog fix for #9833
Also relevant is #9812
2023-06-04 13:44:36 -07:00
Simon Börjesson
71c320ca32 Redraw pager on new selection when nothing was selected previously 2023-06-04 13:40:30 -07:00
Clemens Wasser
c2f58cd312 Port killring 2023-06-04 12:18:19 -07:00
ridiculousfish
cfdcaf880f Simplify scoped_push and ScopedGuard
This makes some simplifications to scoped_push and ScopeGuard:

1. ScopeGuard no longer uses ManuallyDrop; the memory management is now
   trivial and no longer requires `unsafe`.

2. The functions `cancel` and `rollback` have been removed, as
   these were unused. They can be added back later if needed.

3. `scoped_push` has been simplified in both signature and implementation.

4. `Projection` is no longer required and has been removed.

Also add some tests.
2023-06-04 12:14:53 -07:00
ridiculousfish
777ba6f9d8 Use consistent formatting in the parse_rgb test 2023-06-03 12:15:45 -07:00
ridiculousfish
1bbd60c597 Fix a bug in the color.rs port
This was incorrectly parsing FFF as 0x0F0F0F instead of 0xFFFFFF.
2023-06-03 12:13:57 -07:00
Zehka
a0a2475ccb fixed a few smaller things in my translations 2023-06-03 14:03:58 +02:00
Zehka
6c6d281938 another commit to rectify the chaos i created 2023-06-03 14:03:58 +02:00
Zehka
b5fae430c0 added some german translations 2023-06-03 14:03:58 +02:00
Fabian Boehm
e54795a924 CONTRIBUTING: Improve translation section
This should include the important info from the wiki.

We should try to find some recommendation for tools, or even an online
platform where people can submit translations without having to go
through all this setup
2023-06-02 17:38:00 +02:00
Fabian Boehm
756cb15f81 CONTRIBUTING: Rationalize sections
Mostly this tries to give logical header levels, so the "Fish Style
Guide" section is in the "Code Style" section

Also remove a few unimportant C++-centric sections - I'm not sure iwyu
even runs anymore, and cppcheck isn't great in my experience.
2023-06-02 17:38:00 +02:00
Jo
272d123431 Fix a typo in language.rst 2023-06-02 13:13:49 +02:00
Fabian Boehm
946ecf235c Restyle fishscript and python 2023-06-01 18:20:19 +02:00
Fabian Boehm
81d91f1038 create_manpage_completions: Really ignore bundle/cargo 2023-06-01 18:17:47 +02:00
Fabian Boehm
a913702b63 Add more benchmarks 2023-06-01 18:15:42 +02:00
Fabian Boehm
77337fdc8a style.fish: Add rustfmt support 2023-06-01 18:14:12 +02:00
Fabian Boehm
4ed74ed6c1 Improve CONTRIBUTING and add it to the docs 2023-06-01 18:09:02 +02:00
David Adam
688a28c1d2 Rewrite and adopt print_help in Rust 2023-06-01 23:17:13 +08:00
may
d19a08cd8c update npm completions (#9800)
* update npm install completions

* update npm uninstall

* init npm dep rewrite

+ init npm

* npm uninstall complete global packages

* add npm pack completions

* add npm publish completions

* add npm init completions

* add missing commands, remove outdated, add missing aliases

* add npm audit completions

* implement requested changes

* rename __yarn_ to __npm_

* add missing commands / aliases

* slightly less verbose options, reword dry-run description (meh)

* more commands and options

* add and update completions for several commands

* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view

* more commands, fixes

* fish_indent

* remove most aliases from command suggestions

* add most other commands

* npm help, --help

* minor fixes

* remove npm builtin completion, new install option, fish_indent

* add completions for npm set, npm get
2023-05-30 11:22:18 +02:00
may
6b1e6dd179 add completions for git update-index (#9759)
* add git update-index completions

* remove todo

* fix leftover from copying lines

* improve and shorten
2023-05-30 11:21:00 +02:00
ridiculousfish
3d447dec3a Fix a multiplicative overflow in color.rs
Also add a test.
2023-05-29 13:22:46 -07:00
David Adam
3b55563769 print_help: simplify function to always use stdout
It's only called in two places and always uses stdout.
2023-05-28 12:55:40 +08:00
Kevin F. Konrad
ffb6168221 implement completion for age and age-keygen 2023-05-27 11:15:37 -07:00
Mahmoud Al-Qudsi
5ecd584063 Merge VarDispatchTable tables
There was only one entry in the named table, so the previous layout was quite
wasteful. This should speed up lookups and reduce memory overhead.
2023-05-26 22:59:55 -05:00
David Adam
30d9d48bc1 env_dispatch: drop C++ implementation 2023-05-27 11:32:14 +08:00
Mahmoud Al-Qudsi
5ce1716451 Merge pull request #9786 from mqudsi/riir_env_dispatch
Riir env_dispatch
2023-05-26 12:45:08 -05:00
Fabian Boehm
2eba6845c2 create_manpage_completions: Use raw strings for backslashes
python 3.12 emits a SyntaxWarning for invalid escape sequences.

Fixes #9814
2023-05-26 14:01:52 +02:00
Mahmoud Al-Qudsi
6638c78b30 Port env_dispatch to Rust and integrate with C++ code 2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
cce78eeb43 Update env_var_to_ffi() to take an Option<EnvVar>
It wasn't possible to handle cases where vars.get() returned `None` then forward
that to C++, but now we can.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
32912b6525 Expose env_dyn_t in env.h
So that we may use it from files other than `src/env.cpp` to accept a
`&dyn Environment` out of rust.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
6bb2725f67 Make sure rust's fish_setlocale() inits global C++ variables
We can't just call the Rust version of `fish_setlocale()` without also either
calling the C++ version of `fish_setlocale()` or removing all `src/complete.cpp`
variables that are initialized and aliasing them to their new rust counterparts.

Since we're not interested in keeping the C++ code around, just call the C++
version of the function via ffi until we don't have *any* C++ code referencing
`src/common.h` at all.

Note that *not* doing this and then calling the rust version of
`fish_setlocale()` instead of the C++ version will cause errant behavior and
random segfaults as the C++ code will try to read and use uninitialized values
(including uninitialized pointers) that have only had their rust counterparts
init.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
c71342b933 Add safe Rust wrapper around system curses library
This is not yet used but will take eventually take the place of all (n)curses
access. The curses C library does a lot of header file magic with macro voodoo
to make it easier to perform certain tasks (such as access or override string
capabilities) but this functionality isn't actually directly exposed by the
library's ABI.

The rust wrapper eschews all of that for a more straight-forward implementation,
directly wrapping only the basic curses library calls that are required to
perform the tasks we care about. This should let us avoid the subtle
cross-platform differences between the various curses implementations that
plagued the previous C++ implementation.

All functionality in this module that requires an initialized curses TERMINAL
pointer (`cur_term`, traditionally) has been subsumed by the `Term` instance,
which once initialized with `curses::setup()` can be obtained at any time with
`curses::Term()` (which returns an Option that evaluates to `None` if `cur_term`
hasn't yet been initialized).
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
c409b1a89c Port env_dispatch dependencies to rust
Either add rust wrappers for C++ functions called via ffi or port some pure code
from C++ to rust to provide support for the upcoming `env_dispatch` rewrite.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
8a549cbb15 Port/move some code from src/environment.cpp to src/env/mod.rs
The global variables are moved (not copied) from C++ to rust and exported as
extern C integers. On the rust side they are accessed only with atomic semantics
but regular int access is preserved from the C++ side (until that code is also
ported).
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
3ab8b34b1e Use Rust version of global fallback variables 2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
3ee71772f1 Revert rename of wcwidth() to system_wcwidth()
It's not clear whether or not `system_wcwidth()` was picked solely because of
the namespace conflict (which is easily remedied) but using the most obvious
name for this function should be the way to go.

We already have our own overload of `wcwidth()` (`fish_wcwidth()`) so it should
be more obvious which is the bare system call and which isn't.

(I do want to move this w/ some of the other standalone extern C wrappers to the
unix module later.)
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
1a88c55b71 Clean up FISH_EMOJI_WIDTH and FISH_AMBIGUOUS_WIDTH defines
Pull in the correct descriptions merged from across the various C++ header and
source files and get rid of the getter function that's only used in one place
but causes us to split the documentation for FISH_EMOJI_WIDTH across multiple
declarations.
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
e154391f32 Add WCharExt::find() method to perform substring search 2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
77dda2cdef Add ToCString trait
This can be used for functions that accept non-Unicode content (i.e. &CStr or
CString) but are often used in our code base with a UTF-8 or UTF-32 string
on-hand.

When such a function is passed a CString, it's passed through as-is and
allocation-free. But when, as is often the case, we have a static string we can
now pass it in directly with all the nice ergonomics thereof instead of having
to manually create and unwrap a CString at the call location.

There's an upstream request to add this functionality to the standard library:
https://github.com/rust-lang/rust/issues/71448
2023-05-25 16:54:07 -05:00
Mahmoud Al-Qudsi
b17124d8d2 Add rsconf build system and check for gettext symbols
This is more complicated than it needs to be thanks to the presence of CMake and
the C++ ffi in the picture. rsconf can correctly detect the required libraries
and instruct rustc to link against them, but since we generate a static rust
library and have CMake link it against the C++ binaries, we are still at the
mercy of CMake picking up the symbols we want.

Unfortunately, we could detect the gettext symbols but discover at runtime that
they weren't linked in because CMake was compiled with `-DWITH_GETTEXT=0` or
similar (as the macOS CI runner does). This means we also need to pass state
between CMake and our build script to communicate which CMake options were
enabled.
2023-05-25 16:54:03 -05:00
Mahmoud Al-Qudsi
6fc8940097 Simplify ScopeGuard and scoped_push() with Projection<T>
Delegate the `view` and `view_mut` to the newly added `Projection<T>`, which
makes everything oh so much clearer and cleaner. Add comments to clarify what is
happening.
2023-05-25 16:47:59 -05:00
Mahmoud Al-Qudsi
d32fee74f9 Add Projection type
This can be used when you primarily want to return a reference but in order for
that reference to live long enough it must be returned with an object.

i.e. given `Mutex<Foo { bar }>` you want a function to lock the mutex and return
a reference to `bar` but you can't return that reference since it has a lifetime
dependency on `MutexGuard` (which only derefs to all of `Foo` and not just
`bar`). You can return a `Projection` owning the `MutexGuard<Foo>` and set it up
to deref to `&bar`.
2023-05-25 16:47:59 -05:00
Fabian Boehm
bec8e8df05 docs/faq: Remove external tools
This was always extremely weasel-wordy and I have no idea which one
here is a good choice.

OMF is basically inactive at this point, so we might be doing people a
disservice by linking to it.
2023-05-25 17:46:25 +02:00
Fabian Boehm
2fa2b802c9 docs/interactive: Some small adjustments
Wording improvements and move private mode down, to the history section.
2023-05-25 17:46:25 +02:00
Fabian Boehm
90713dd221 build.rs: Remove miette dependency
This wasn't providing a lot of value, and the license compatibility is iffy.

There's a bit of weirdness in that this now uses a `Box<dyn Error>`,
but since currently nothing actually errors out let's punt that for
later.
2023-05-25 17:46:03 +02:00
David Adam
2cb608358d fish.spec/Debian packaging: update licensing details 2023-05-25 22:23:18 +08:00
David Adam
4e13b1b5d5 Licensing: note MIT licensing status of Dracula theme 2023-05-25 21:30:30 +08:00
David Adam
2fbee01e17 Licensing: update the OpenBSD license details
The strlcpy/wcslcpy function is long gone.
2023-05-25 21:06:48 +08:00
David Adam
7c059b1112 Licensing: drop the LGPL reference and text
The wcstok function is long gone.
2023-05-25 20:50:36 +08:00
Mahmoud Al-Qudsi
047da71e2e Update Cirrus CI FreeBSD runner to 13.2-RELEASE 2023-05-23 12:17:25 -05:00
Fabian Boehm
ce34afa11c cirrus: Turn off FreeBSD 12.3
These are often queueueueueueueued and we don't test older versions
for other OSen either.
2023-05-23 17:45:27 +02:00
Fabian Boehm
9897f4f18d fileid: Just use unix::fs::metadataext
These should be the same, except without the "st_" prefix
2023-05-23 17:43:23 +02:00
Fabian Boehm
f2e5f02a8a fileid: Use freebsd metadata
This is a terrible way of going about things,
and means we're currently broken on any unix that isn't specifically listed.

But at least it'll build and allow us to keep the FreeBSD CI running.
2023-05-23 17:37:48 +02:00
Fabian Boehm
8282ddcff2 faq: Update
Remove two that really aren't frequently asked and simplify the
history substitution thing, plus abbrs.
2023-05-23 16:57:53 +02:00
Fabian Boehm
80324c9d7f docs: Fix link 2023-05-23 16:48:28 +02:00
Fabian Boehm
b1c06bbd2c Put back extra licenses
This was erroneously removed in commit 03a6fb4a69.
2023-05-23 16:47:32 +02:00
Wenhao Ho
201610151f feat: sync the dracula official theme
Signed-off-by: Wenhao Ho <wh.ho@outlook.com>
2023-05-23 20:47:01 +08:00
ridiculousfish
21e31c9b59 Remove C++ builtin test implementation
Now that builtin test is in Rust, remove the C++ bits.
2023-05-21 11:50:24 -07:00
ridiculousfish
d0aba9d42c Port builtin_test tests to Rust
fish_tests has a bunch of tests for the 'test' builtin. Port these to Rust.
2023-05-21 11:50:24 -07:00
ridiculousfish
cdb77a6176 Adopt the Rust test builtin
This switches the builtin test implementation from C++ to Rust
2023-05-21 11:50:24 -07:00
ridiculousfish
10a7de03e2 Implement builtin test in Rust
This implements (but does not yet adopt) builtin test in Rust.
2023-05-21 11:50:24 -07:00
ridiculousfish
a20985c738 Implement FileID in Rust
FileID tracks a File's identity, including its inode, device, and creation and
modification times.
2023-05-21 11:50:24 -07:00
Fabian Boehm
b435fc4539 docs: Add something on variables-as-commands
Specifically point towards the necessary splitting (as always,
separate ahead of time) and the keyword thing.

Fixes #9797
2023-05-21 10:13:54 +02:00
Fabian Boehm
aac30367bf completions/systemctl: Add some missing commands
Fixes #9804
2023-05-21 10:02:26 +02:00
Fabian Boehm
8a9f57112c Fix typo
See https://github.com/fish-shell/fish-site/pull/112
2023-05-18 17:52:51 +02:00
Fabian Boehm
a8d7d9689d docs: Another pass over bind 2023-05-18 10:11:17 +02:00
Fabian Boehm
0c900f74d0 docs: Explain bind --mode in custom bindings 2023-05-18 09:40:03 +02:00
Thomas Klausner
67d1d80f94 When using curses, look for libterminfo as well. (#9794)
Supports NetBSD, where libtinfo isn't available but libterminfo is.
2023-05-16 15:02:11 -05:00
ridiculousfish
dec3976a1f wcstoi: remove the consume_all / consumed_all machinery
Nothing sets these, so they can be removed. Also remove CharsLeft
for the same reason.
2023-05-14 18:38:24 -07:00
ridiculousfish
60d439ab22 Rationalize fish_wcstoi/d and friends
Historically fish has used the functions `fish_wcstol`, `fish_wcstoi`, and
`fish_wcstoul` (and some long long variants) for most integer conversions.
These have semantics that are deliberately different from the libc
functions, such as consuming trailing whitespace, and disallowing `-` in
unsigned versions.

fish has started to drift away from these semantics; some divergence from
C++ has crept in.

Rename the existing `fish_wcs*` functions in Rust to remove the fish
prefix, to express that they attempt to mirror libc semantics; then
introduce `fish_` wrappers which are ported from C++. Also fix some
miscellaneous bugs which have crept in, such as missing range checks.
2023-05-14 18:03:52 -07:00
Fabian Boehm
364f8223b2 pexpects: Skip eval-stack-overflow under ASAN CI 2023-05-12 19:26:10 +02:00
Fabian Boehm
9c5571f14f docs: Reword Combining lists section
This was quite hard to read, and the term "cartesian product" honestly
doesn't help
2023-05-12 18:53:53 +02:00
Fabian Boehm
1ed31579f2 create_manpage_completions: Remove one more groff thing
This came up in the irb man page:

```
.Pp
.It Fl W
Same as `ruby -W' .
.Pp
```
2023-05-12 18:32:08 +02:00
Fabian Boehm
e09f7e4e4d create_manpage_completions: Skip more prefixes
This also skips the 192 git- and 64 npm- pages that

1. have better completions already (for the most part)
2. don't have the same name as a command typically in $PATH

In doing so it reduces the runtime on my system from 9s to 7s. Granted
I have all of these, so that's the best case.
2023-05-12 17:57:29 +02:00
Fabian Boehm
5f672ece84 create_manpage_completions: Also clear already_output_completions
Prevents issues if we try to read a manpage twice - in which case we
could fall back to another parser, creating different results.

Fixes #9787
2023-05-12 16:35:05 +02:00
Fabian Boehm
56743ae770 tests: More slack for ASAN
Disable one and add a sleep to another
2023-05-11 22:14:12 +02:00
Fabian Boehm
8d5a223b39 tests/pexpect: Disable wait.py under SAN CI 2023-05-11 21:42:19 +02:00
Fabian Boehm
055e40467f github actions: Disable pexpect for ASAN for now
This fails basically every commit, just by blowing the time budget.
2023-05-08 19:05:44 +02:00
Fabian Boehm
d855725965 completions/dnf: Use lowercase queryformat
See de9c5c5b59

Fixes #9783
2023-05-08 18:34:02 +02:00
ridiculousfish
e71b75e0e4 Reimplement environment and the environment stack in Rust
This reimplements the environment stack in Rust.
2023-05-07 15:15:56 -07:00
ridiculousfish
8ec1467dda Implement (but do not yet adopt) Environment in Rust
This implements the primary environment stack, and other environments such
as the null and snapshot environments, in Rust. These are used to implement
the push and pop from block scoped commands such as `for` and `begin`, and
also function calls.
2023-05-07 15:15:56 -07:00
ridiculousfish
0681b6b53a Make C++ env_var_t wrap Rust EnvVar
This reimplements C++'s env_var_t to reference a Rust EnvVar.
The C++ env_var_t is now just a thin wrapper.
2023-05-07 15:15:56 -07:00
ridiculousfish
10ee87eb28 Reimplement owning_null_terminated_array in Rust
owning_null_terminated_array is used for environment variables, where we need to
provide envp for child processes. This switches the implementation from C++ to
Rust.

We retain the C++ owning_null_terminated_array_t; it simply wraps the Rust
version now.
2023-05-07 15:15:56 -07:00
ridiculousfish
d4c3c77318 Changelog fix in #9776 2023-05-07 14:34:19 -07:00
Rocka
c21e13e62e completions: fix qdbus Q_NOREPLY method completion 2023-05-07 14:34:03 -07:00
AsukaMinato
e2fdc63cdb simplify some logic (#9777)
* simplify some logic

* simplify a &*
2023-05-07 08:39:34 -05:00
Mahmoud Al-Qudsi
6a301381c8 Fix compilation on 32-bit non-Linux platforms
The `u64::from(buf.f_flag)` was needed in two places. The existing handled macOS
which always has a 32-bit statfs::f_flag, but statvfs::f_flag is an `unsigned
long` which means it needs to be coerced to 64-bits on 32-bit targets.
2023-05-05 19:35:17 -05:00
Mahmoud Al-Qudsi
7d617d7d58 Support cross-compilation w/ detect_bsd() check
Also assert that the code works as expected by asserting the result under known
BSD systems.
2023-05-05 19:03:23 -05:00
Mahmoud Al-Qudsi
220ffaeb65 Add completions for builtin disown
It completes identical to `fg` and `bg` w/ this change. I'm not aware of any
reason why it shouldn't, but feel free to enlighten me if I've missed something.

[ci skip]
2023-05-05 16:08:58 -05:00
Mahmoud Al-Qudsi
d55b65a8d2 Merge pull request #9771 from mqudsi/asan_take5
Rework ASAN integration
2023-05-04 19:43:37 -05:00
Mahmoud Al-Qudsi
4f5cef446a apt.fish: Fix compatibility with newer versions of Debian/Ubuntu
Why drop support for `awk -e`? Linux sees so much needless churn!
2023-05-03 21:27:46 -05:00
Mahmoud Al-Qudsi
8bd5183944 Remove unnecessary UTF-8 decode in is_wsl() 2023-05-02 14:58:44 -05:00
Mahmoud Al-Qudsi
d3abd5d600 Fix inverted is_console_session() logic
The $TERM matching logic was inverted.
2023-05-02 14:55:04 -05:00
Mahmoud Al-Qudsi
c94fce75e5 Add multi-byte test for wcscasecmp()
The lowercase of İ is two bytes, making it a good test candidate.
2023-05-02 14:18:43 -05:00
Mahmoud Al-Qudsi
8668ce336c Fix common::wcscasecmp() for multi-byte lowercase strings 2023-05-02 14:10:12 -05:00
Mahmoud Al-Qudsi
6c8409fd45 Remove unnecessary use of static mut.
Atomic don't need to be `mut` to change since they use interior mutability.
2023-05-02 13:22:39 -05:00
Mahmoud Al-Qudsi
f71a75f3bb Avoid unnecessary vector shift in re::regex_make_anchored()
There's no reason to inject prefix into our newly allocated str after storing
pattern in there. Just allocate with the needed capacity up front and then
insert in the correct order.
2023-05-02 13:15:02 -05:00
Mahmoud Al-Qudsi
40be27c002 Avoid unnecessary vector shift in re::regex_make_anchored()
There's no reason to inject prefix into our newly allocated str after storing
pattern in there. Just allocate with the needed capacity up front and then
insert in the correct order.
2023-05-02 13:13:11 -05:00
Xiretza
1dafb77cda Use bitflags for ParseTreeFlags + ParserTestErrorBits
For consistency with simlar code.
2023-05-02 19:03:51 +02:00
Mahmoud Al-Qudsi
7b0cc33f2e Add LSAN suppressions file
Suppress TLS variable leaks caused by outstanding background threads by
suppressing the ASAN interposer functions. This is possible because because
we're now using use_tls=1.

-----------------------

Direct leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x5627a1f0cc86 in __interceptor_realloc (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xb9fc86) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #1 0x7f04d8800f79 in pthread_getattr_np (/lib/x86_64-linux-gnu/libc.so.6+0x95f79) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #2 0x5627a1f2f664 in __sanitizer::GetThreadStackTopAndBottom(bool, unsigned long*, unsigned long*) (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xbc2664) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #3 0x5627a1f2fb83 in __sanitizer::GetThreadStackAndTls(bool, unsigned long*, unsigned long*, unsigned long*, unsigned long*) (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xbc2b83) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #4 0x5627a1f19a0d in __asan::AsanThread::SetThreadStackAndTls(__asan::AsanThread::InitOptions const*) (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xbaca0d) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #5 0x5627a1f19615 in __asan::AsanThread::Init(__asan::AsanThread::InitOptions const*) (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xbac615) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #6 0x5627a1f19b01 in __asan::AsanThread::ThreadStart(unsigned long long) (/home/runner/work/fish-shell/fish-shell/build/fish_tests+0xbacb01) (BuildId: da87d16730727369ad5fa46052d10337d6941fa9)
    #7 0x7f04d87ffb42  (/lib/x86_64-linux-gnu/libc.so.6+0x94b42) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x7f04d88919ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
2023-05-02 11:52:42 -05:00
Mahmoud Al-Qudsi
91485c90ca Also free ncurses terminal state when exiting under ASAN 2023-05-02 11:52:42 -05:00
Mahmoud Al-Qudsi
73983bada5 Fix ncurses memory leak in init_curses()
init_curses() is/can be called more than once, in which case the previous
ncurses terminal state is leaked and a new one is allocated.

`del_curterm(cur_term)` is supposed to be called prior to calling `setupterm()`
if `setupterm()` is being used to reinit the default `TERMINAL *cur_term`.
2023-05-02 11:52:42 -05:00
Mahmoud Al-Qudsi
905430629d Use ASAN_OPTIONS fast_unwind_on_malloc=0
This is much slower but gives proper stack traces for calls emanating from code
that wasn't compiled with -fno-omit-frame-pointer.
2023-05-02 11:52:42 -05:00
Mahmoud Al-Qudsi
3651e0e9d8 Actually report ASAN memory leaks
The new asan exit handlers are called to get proper ASAN leak reports (as
calling _exit(0) skips the LSAN reporting stage and exits with success every
time).

They are no-ops when not compiled for ASAN.
2023-05-02 11:52:41 -05:00
Mahmoud Al-Qudsi
c43e040c7c Fix spurious ASAN __cxa_thread_atexit_impl() leaks
Set use_tls back to its default of 1.

This is required to work around an ASAN/LSAN virtualization bug but seems to be
behind the random __cxa_thread_atexit_impl() leaks?
2023-05-02 11:52:41 -05:00
Mahmoud Al-Qudsi
cb368f70ee Fix rust formatting for BSD signal tests 2023-05-02 11:51:56 -05:00
Mahmoud Al-Qudsi
6a3ece6766 Rename Sigchecker to SigChecker to be more idiomatic
Idiomatic rust naming for types is "PascalCase" and this was more "Pascalcase".
2023-05-02 11:29:18 -05:00
Mahmoud Al-Qudsi
55c3df7f41 Fix BSD test failure regression
Nothing major. Introduced in 1ecf9d013d.
2023-05-02 11:23:11 -05:00
Xiretza
afe2e9d8db builtins/printf: avoid string copies by formatting directly to buffer
Closes #9765.
2023-05-01 13:32:44 -05:00
ridiculousfish
4771f25102 Adopt the new Rust signal implementation
This switches the signals implementation from C++ to Rust.
2023-04-30 16:22:57 -07:00
ridiculousfish
1ecf9d013d Port (but do not adopt) signal handling bits in Rust
This ports some signal setup and handling bits to Rust.

The signal handling machinery requires walking over the list of known signals;
that's not supported by the Signal type. Rather than duplicate the list of
signals yet again, switch back to a table, as we had in C++.

This also adds two further pieces which were neglected by the Signal struct:

1. Localize signal descriptions
2. Support for integers as the signal name
2023-04-30 16:22:55 -07:00
ridiculousfish
603a2d6973 Rename sigchecker_t to Sigchecker
This matches Rust naming conventions
2023-04-30 11:32:18 -07:00
ridiculousfish
2848be6b73 Add an empty test case to the join_strings tests 2023-04-29 17:02:18 -07:00
Fabian Boehm
a9708367db doc: Link path in commands 2023-04-29 19:58:41 +02:00
Xiretza
81cdd51597 Update printf-compat 2023-04-29 19:57:33 +02:00
Mahmoud Al-Qudsi
544bd183da Add and use ASAN blacklist
Blacklist an apparently false positive in the underlying runtime.
2023-04-29 11:02:59 -05:00
Mahmoud Al-Qudsi
ecf1676601 Add and use type-erased RAII callback wrapper for ffi
This allows the rust code to free up C++ resources allocated for a callback even
when the callback isn't executed (as opposed to requiring the callback to run
and at the end of the callback cleaning up all allocated resources).

Also add type-erased destructor registration to callback_t. This allows for
freeing variables allocated by the callback for debounce_t's
perform_with_callback() that don't end up having their completion called due to
a timeout.
2023-04-29 11:02:59 -05:00
Mahmoud Al-Qudsi
6cd2d0ffed Integrate threads.rs w/ legacy C++ code
Largely routine but for the trampolines in iothread.h and iothread.cpp which
were a real PITA to get correct w/ all their variants.

Integration is complete with all old code ripped out and the tests using the
rust version of the code.
2023-04-29 11:02:59 -05:00
Mahmoud Al-Qudsi
7f9a942f1d Port remainder of iothreads from C++ 2023-04-29 11:02:59 -05:00
Fabian Boehm
0963e6769e completions/wvdial: Use path 2023-04-29 16:15:13 +02:00
Fabian Boehm
2f997ba8a2 Remove a useless sort 2023-04-29 16:15:07 +02:00
Fabian Boehm
32715ee504 completions/sv: Use path 2023-04-29 15:58:52 +02:00
Fabian Boehm
05e7732cb8 tests: Disable one commandline test
Keeps failing under ASAN on Github Actions
2023-04-28 17:41:29 +02:00
Fabian Boehm
483478f4cf docs: Improve prompt section and move title after it 2023-04-28 17:19:00 +02:00
Fabian Boehm
f826d59e5c docs: Some on the tutorial
Try to clarify and simplify some wording and move the wildcards/redirection section behind variables because they are more important
2023-04-28 17:11:23 +02:00
Mahmoud Al-Qudsi
85d8f2b27f Fix HAS_WORKING_TTY_TIMESTAMPS in rust
Like the WSL check, this was incorrectly assuming WSL implies
cfg(windows) when it's actually picked up as Linux.

Also, improve over the C++ code by not relying on the build-time WSL
status to determine if we are running on WSL at runtime since it's often
the case that the fish binaries are built on a non-WSL host (for
packaging) then executed on a WSL only at runtime.

(But it's ok to assume if fish has been built for Windows or not Linux
that it will either be run or not run on top of a Win32 character device
system.)

Also, port of the comment and relevant WSL and fish issue links over
from the CPP codebase for posterity.
2023-04-26 16:05:24 -05:00
Mahmoud Al-Qudsi
67124dfb11 Slightly refactor unescape_string_xxx() functions
* Since we already have an allocation of length wstr.len(), it's
  probably better to allocate the result (which is strictly less than or
  equal to the input length) up-front rather than risk thrashing the Vec
  allocation,
* There's no need to compare c2 against '\0' since that will just cause
  to_digit(16) to return None anyway,
* Our convert_hex() specialization of to_digit(16) that only checks
  capital letters A-F without also checking lowercase a-f isn't
  significantly faster than just use to_digit(16), and we already assert
  that the input *wasn't* a lowercase a-f before making the call, so
  there's no point in using a special function to handle that.
2023-04-26 15:18:27 -05:00
Fabian Boehm
c55ec59e22 docs: A tad more on shared bindings
alt+enter, some consistency fixes
2023-04-26 21:22:34 +02:00
Fabian Boehm
93cd70edfe docs: Remove weird "float: left"
This breaks the docs on extremely narrow screens and I cannot find a
reason for it.

Fixes https://github.com/fish-shell/fish-site/issues/110
2023-04-26 19:38:10 +02:00
Fabian Boehm
d2165ca7e9 Use path basename 2023-04-26 19:38:10 +02:00
Xiretza
b76e6c5637 complete: fix condition to suppress variable autocompletion 2023-04-25 21:47:11 -07:00
Kid
93dc8485dd Remove kitty completion in favor of official integration 2023-04-25 19:28:55 +08:00
ridiculousfish
d0c902a548 Adopt wstr::split in more places
This simplifies some code that was written before wstr::split existed.
2023-04-23 19:34:52 -07:00
ridiculousfish
fa39113bc6 Tweak the behavior of wstr::split to better match C++
Prior to this change, wstr::split had two weird behaviors:

1. Splitting an empty string would yield nothing, rather than an empty
   string.
2. Splitting a string with the separator character as last character
   would not yield an empty string.

For example L!("x:y:").split(':') would return ["x", "y"] instead of
what it does in C++, which is ["x", "y", ""].

Fix these.
2023-04-23 19:33:10 -07:00
ridiculousfish
de8288634a Remove Arc from the global abbreviation set
This wasn't needed.
2023-04-23 15:35:05 -07:00
ridiculousfish
705874f2e4 Revert "Warn about unescape_string_xxx() behavior (and tweak slightly)"
This reverts commit 76dc849fca.

The warning added in that commit is incorrect. The functions
unescape_string_url and unescape_string_var will not panic, because
char_at() return 0 if the index is equal to its length.
2023-04-23 15:28:46 -07:00
ridiculousfish
009650b7b5 Revert "Remove unsafe from exit_without_destructors()"
This reverts commit f9c92753c4.

This commit attempted to replace exit_without_destructors() with
std::process::exit; however this is wrong for two reasons:

1. std::process::exit() runs Rust runtime cleanup stuff we don't want
2. std::process::exit() invokes destructors, meaning atexit handlers,
   which we don't want.
2023-04-23 15:23:12 -07:00
Mahmoud Al-Qudsi
76dc849fca Warn about unescape_string_xxx() behavior (and tweak slightly)
The type system no longer guarantees that the input string is nul-terminated,
meaning accessing beyond the range-checked `i` a char-at-a-time is no longer
safe. (In C++, we would either be using a plain C string which is always
nul-terminated or we would be using (w)string::cstr() which similarly grants
access to its nul-terminated buffer.)

Aside from that, there's no need to explicitly check `if c2 == '\0'` because
'\0' is not a valid hex digit so the `?` tacked on to `convert_hex_digit(c2)?`
will abort and return `None` anyway.

convert_hex_digit() is not appreciably faster than char::to_digit(16) and makes
the code less maintainable since it encodes certain assumptions; since it's also
not used consistently just drop it in favor of the std fn.

Since the output string (per the decode logic) is always shorter than or equal
to the input string, just reserve the input string size upfront to prevent vec
reallocations.
2023-04-23 15:04:37 -05:00
Mahmoud Al-Qudsi
f9c92753c4 Remove unsafe from exit_without_destructors()
std::process::exit() already does what we need and and it is safe to call (since
it is not unsafe for destructors not to be called).
2023-04-23 13:05:56 -05:00
Yuntao Zhao
20b500dce8 Add rpm-ostree completion (#9669)
* Add rpm-ostree completion

Add basic command completion for rpm-ostree. This should improve the
user experience for fish users using rpm-ostree.

* Shorten rpm-ostree descriptions

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-04-23 12:55:00 -05:00
Jannik Vieten
480133bcc8 Improve jq completions and add gojq completions
* completions: updated jq completions

* completions: added completions for gojq

* Shorten jq completion descriptions

* Update gojq.fish

Capitalize first letter of descriptions to match other completions.

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-04-23 12:35:41 -05:00
Mahmoud Al-Qudsi
3a2033b992 Fix rust version of is_wsl() check (#9746)
Somewhat counter-intuitively, this code is active when compiling under *Linux*
and is always false when compiling under Windows. The logic was incorrectly
reversed before (it's easier to reason about when you realize that fish doesn't
even compile under Windows because it uses tons of libc functions).

As the code was actually never compiled, it wasn't actually tested for validity
either and there were some issues that prevented it from compiling that have
since been fixed. The logic has also been adjusted a bit to make it possible to
use the rust-native int parsing instead of `libc::strtod()`.

The code has been changed to use `once_cell::race::OnceBool` instead of
`once_cell::sync::Lazy<T>` which imposes a greater runtime burden with locking
and other overhead. We don't care if the code runs more than once on init (if
calls were to race, though they probably don't) - just that the code isn't
subsequently executed on each call. The `once_cell::race` module is a better fit
here, though it doesn't expose the ergonomic `Lazy<T>` façade around its types.
2023-04-23 12:28:23 -05:00
Mahmoud Al-Qudsi
ff28f29e8f Move thread stuff out of common.rs (#9745)
is_main_thread() and co were previously ported to threads.rs, so remove the
duplicate code and move everything else related to threads there as well. No
need for common.rs to be as long as our old common.cpp!

I left #[deprecated] stubs in common.rs to help redirect anyone porting code
over that we can remove after the port has finished.

Additionally, the fork guards had previously been left as a todo!() item but I
ported that over. They're all called from the now-central threads::init()
function so there isn't a need to call each individual thread-management-fn
manually.

The decision was made a while back to try and embrace/use the native rust thread
functionality and utilities so the manual thread management code has been ripped
out and was replaced with code that marshals the native rust values instead. The
values won't line up with what the C++ code sees, but it never lined up anyway
since each was using a separate counter to keep track of the values.
2023-04-23 12:26:10 -05:00
exploide
30ae715183 completions: added ip neigh completions 2023-04-23 17:48:58 +08:00
Johannes Altmanninger
0fbefc6be2 Make IO buffer struct elements public again 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
1bffa823d8 Allow to pass slices of owned strings to trace_if_enabled 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
05ec1039ed Rename autoclose_pipes_t to AutoClosePipes 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
48e728e9fb event: make some types public again 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
6c07af9343 Shorthand for escaping with default options
Should probably do this on the C++ side too.
2023-04-22 22:25:34 +02:00
Johannes Altmanninger
19fe0f6a91 AST: implement try_source_range for union fields
Still not sure where the union fields are going.
I don't think they should implement Node.
2023-04-22 22:25:34 +02:00
Johannes Altmanninger
4c46faea99 Make ParsedSource members public again 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
29891cf771 Finish and fix DirIter API 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
07cc33e7aa parse_util: deduplicate append_syntax_error macro 2023-04-22 22:25:34 +02:00
Johannes Altmanninger
56ad7fe0e5 Silence some more clippy lints
They are at odds with some direct translations.
2023-04-22 22:25:34 +02:00
Johannes Altmanninger
ec176dc07e Port path.h 2023-04-21 13:57:29 +02:00
Johannes Altmanninger
629cbe0115 Env stubs for path port 2023-04-21 13:57:29 +02:00
Johannes Altmanninger
454009d13e Rust.cmake: break up long line 2023-04-21 13:57:29 +02:00
Johannes Altmanninger
eb1598ea9a Port parser_keywords
This drops some of the optimizations, we should probably add them back.
2023-04-21 13:57:29 +02:00
Johannes Altmanninger
1df64a4891 Replace maybe_t::missing_or_empty with a more Rust-friendly helper
There are many places where we want to treat a missing variable the same as
a variable with an empty value.

In C++ we handle this by branching on maybe_t<env_var_t>::missing_or_empty().
If it returns false, we go on to access maybe_t<env_var_t>::value() aka
operator*.

In Rust, Environment::get() will return an Option<EnvVar>.
We could define a MissingOrEmpty trait and implement it for Option<EnvVar>.

However that will still leave us with ugly calls to Option::unwrap()
(by convention Rust does use shorthands like *).

Let's add a variable getter that returns none for empty variables.
2023-04-21 13:57:29 +02:00
Johannes Altmanninger
82a797db9c clang-format C++ builtins 2023-04-21 13:57:29 +02:00
Johannes Altmanninger
33f51b45e4 Tease apart parser.eval() overloads
The most common overload takes a string and an io chain so let that one keep
its name.
2023-04-21 13:57:29 +02:00
may
beca70458b add recent commits to completion for git switch --detach 2023-04-21 07:44:50 +02:00
Fabian Boehm
76b3965648 docs/string: Separate "pad" and "shorten"
This isn't the same as "join"/"join0", where one is just a special
case of the other.

These are two different, if basically opposite commands.

But more importantly this was a huge mess and the formatting was broken.
2023-04-20 22:17:08 +02:00
Johannes Altmanninger
12ce42a2f9 Rename kw() to keyword() also in C++ 2023-04-19 22:43:36 +02:00
Johannes Altmanninger
e4f6169a01 clang-format C++ files
Forgot to run this after the wcstring_list_t -> std::vector<wcstring> rename.
2023-04-19 22:43:36 +02:00
Paiusco
564039093b Create fish_[default|vi]_key_bindings documentation
- Create docs file for both vi and default key bindings
- Remove variable mention on `interactive` and point to their own pages
2023-04-19 19:22:55 +02:00
AsukaMinato
f5e063a462 add-qjsc-fish (#9731)
* add-qjsc-fish

* fix -o qjsc.fish
2023-04-19 19:21:55 +02:00
Johannes Altmanninger
09ffac5a0a Port parse_util_compute_indents 2023-04-19 10:35:22 +02:00
Johannes Altmanninger
c25cc8df5d Adopt rusty parse_util_unescape_wildcards 2023-04-19 10:32:16 +02:00
Johannes Altmanninger
12afb320a3 Port parse_util
Except for the indent visitor bits.

Tests for parse_util_detect_errors* are not ported yet because they depend
on expand.h (and operation_context.h which depends on env.h).
2023-04-19 01:03:16 +02:00
Johannes Altmanninger
36ba912779 Make some names public 2023-04-19 01:03:16 +02:00
Johannes Altmanninger
dc6aead17b ast.rs: add Leaf::has_source() convenience function for now
This is exposed by our FFI bridge for convenience, so this makes porting
easier.
2023-04-19 01:03:16 +02:00
Johannes Altmanninger
966dc0d997 Fix how we pass error list output parameter when parsing AST
This makes it more convenient to pass None.
2023-04-19 01:03:16 +02:00
Johannes Altmanninger
22c8e9f60d Don't leak ParseErrorList FFI crutch type into Rust
Just like 16ea4380c (redirection.rs: don't leak FFI type into Rust code,
2023-04-09).
2023-04-19 01:03:16 +02:00
Johannes Altmanninger
fc5e97e55e Expose u32 source offsets as usize
Computations should use usize, so this makes things more convenient.
Post-FFI we can make SourceRange fields private, to enforce this even easier.
2023-04-19 01:03:16 +02:00
Johannes Altmanninger
2ca27d2c5b Implement Iterator for Tokenizer 2023-04-19 01:03:16 +02:00
Johannes Altmanninger
6ede7f8009 Delete wcstring_list_t
We don't want it in Rust. Remove it to smoothen the transition.
2023-04-19 01:03:16 +02:00
Fabian Boehm
db5c9badad completions/git: Escape custom command names
This can be triggered by having a custom git command in e.g.
`/mnt/c/Program Files (x86)/foo/`.

Fixes #9738
2023-04-18 20:40:14 +02:00
Johannes Altmanninger
fdeb0d9f06 Port the rest of wcstringutil 2023-04-18 12:54:19 +02:00
Fabian Boehm
3bfe798dbb Fix read_blocked
This caused math to assert out because it never wrote into the buffer.

Now, presumably it wrote somewhere but I don't know where, so fixing
this seems like a good idea.

Fixes #9735.
2023-04-17 17:28:24 +02:00
ridiculousfish
1bf29a5e13 Support constructing a wcstring_list_ffi_t from Rust
This allows passing a vector of strings from Rust to C++
2023-04-16 13:36:13 -07:00
ridiculousfish
f0360efbfa Add path_make_canonical in Rust 2023-04-16 13:36:13 -07:00
ridiculousfish
eecc796b04 Add a widestring split() function
This allows splitting widestrings about a char, similar to C++
split_string.
2023-04-16 13:36:13 -07:00
ridiculousfish
621a3a6a8b Add Rust support for null terminated arrays
This adds support for "null-terminated arrays of nul-terminated strings"
as used in execve, etc.
2023-04-16 13:36:13 -07:00
Xiretza
ed3fdaa665 Change read_blocked parameter type to RawFd for clarity 2023-04-16 22:26:46 +02:00
Xiretza
14fc11b5b8 wcstod: adjust tests for new implementation 2023-04-16 22:26:46 +02:00
Xiretza
aab2f660a7 Port math builtin, tinyexpr and wcstod_underscores to Rust 2023-04-16 22:26:46 +02:00
Xiretza
cc744d30c0 io: add FFI wrappers for io_streams_t fields 2023-04-16 22:26:46 +02:00
Xiretza
ba5e1dfb69 builtins: port more error messages 2023-04-16 22:26:46 +02:00
Xiretza
be2ea8edf0 wcstod: extract wcstod_inner()
This function can be called with any char iterator, not just IntoCharIter
values.
2023-04-16 22:26:46 +02:00
Xiretza
6b687adb40 Implement IntoCharIter for &[char] 2023-04-16 22:26:46 +02:00
Fabian Boehm
a91689e211 Remove unneeded & 2023-04-16 22:22:04 +02:00
ridiculousfish
ead329db60 Replace a bunch of from_ffi with as_wstr calls
from_ffi copies a CxxWString into a new Rust WString, but as_wstr simply
gets the slice of chars directly.

Too many string types!
2023-04-16 12:50:53 -07:00
Johannes Altmanninger
971d257e67 Port AST to Rust
The translation is fairly direct though it adds some duplication, for example
there are multiple "match" statements that mimic function overloading.

Rust has no overloading, and we cannot have generic methods in the Node trait
(due to a Rust limitation, the error is like "cannot be made into an object")
so we include the type name in method names.

Give clients like "indent_visitor_t" a Rust companion ("IndentVisitor")
that takes care of the AST traversal while the AST consumption remains
in C++ for now.  In future, "IndentVisitor" should absorb the entirety of
"indent_visitor_t".  This pattern requires that "fish_indent" be exposed
includable header to the CXX bridge.

Alternatively, we could define FFI wrappers for recursive AST traversal.

Rust requires we separate the AST visitors for "mut" and "const"
scenarios. Take this opportunity to concretize both visitors:

The only client that requires mutable access is the populator.  To match the
structure of the C++ populator which makes heavy use of function overloading,
we need to add a bunch of functions to the trait. Since there is no other
mutable visit, this seems acceptable.

The "const" visitors never use "will_visit_fields_of()" or
"did_visit_fields_of()", so remove them (though this is debatable).

Like in the C++ implementation, the AST nodes themselves are largely defined
via macros.  Union fields like "Statement" and "ArgumentOrRedirection"
do currently not use macros but may in future.

This commit also introduces a precedent for a type that is defined in one
CXX bridge and used in another one - "ParseErrorList".  To make this work
we need to manually define "ExternType".

There is one annoyance with CXX: functions that take explicit lifetime
parameters require to be marked as unsafe. This makes little sense
because functions that return `&Foo` with implicit lifetime can be
misused the same way on the C++ side.

One notable change is that we cannot directly port "find_block_open_keyword()"
(which is used to compute an error) because it relies on the stack of visited
nodes. We cannot modify a stack of node references while we do the "mut"
walk. Happily, an idiomatic solution is easy: we can tell the AST visitor
to backtrack to the parent node and create the error there.

Since "node_t::accept_base" is no longer a template we don't need the
"node_visitation_t" trampoline anymore.

The added copying at the FFI boundary makes things slower (memcpy dominates
the profile) but it's not unusable, which is good news:

    $ hyperfine ./fish.{old,new}" -c 'source ../share/completions/git.fish'"
    Benchmark 1: ./fish.old -c 'source ../share/completions/git.fish'
      Time (mean ± σ):     195.5 ms ±   2.9 ms    [User: 190.1 ms, System: 4.4 ms]
      Range (min … max):   193.2 ms … 205.1 ms    15 runs

    Benchmark 2: ./fish.new -c 'source ../share/completions/git.fish'
      Time (mean ± σ):     677.5 ms ±  62.0 ms    [User: 665.4 ms, System: 10.0 ms]
      Range (min … max):   611.7 ms … 805.5 ms    10 runs

    Summary
      './fish.old -c 'source ../share/completions/git.fish'' ran
        3.47 ± 0.32 times faster than './fish.new -c 'source ../share/completions/git.fish''

Leftovers:
- Enum variants are still snakecase; I didn't get around to changing this yet.
- "ast_type_to_string()" still returns a snakecase name. This could be
  changed since  it's not user visible.
2023-04-16 17:46:56 +02:00
Johannes Altmanninger
915db44fbd Implement printf formatting for some parser types 2023-04-16 17:46:56 +02:00
Johannes Altmanninger
dc4cb84ffc Derive Debug for some parser types 2023-04-16 17:46:56 +02:00
Johannes Altmanninger
912f10ceb0 Port io 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
ecb0ab5f34 common.rs: remove G_ prefix from globals 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
238d9bf3a5 Minor cleanup of JobId::acquire 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
4036b1ab95 Make Event::caller_exit take a JobId, not an i32
A JobId is not supposed to convert to other types.

Since this type is defined as NonZeroU32 (which cannot be -1), we need to
add some conversion functions to match the C++ behavior.

Overall, it would have been better to keep using the C++ type.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
37a7fe6738 event.rs: use libc::c_int for signal numbers, not usize
This makes porting easier. Once everything is done, we can apply such
changes globally.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
f5d8087bc6 job_group.rs: use our canonical string type 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
da45bfab6b wait_handle.rs: implement Rusty set_status_and_complete
This function didn't exists in LastC++11 but given that "status" is private
I did not see an obvious alternative.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
141dcde498 signal.rs: crash a bit earlier when signal number is negative
The conversion to usize is used for array accesses, so negative values
would cause crashes either way. Let's do it earlier so we can get rid of
the suspect C-style cast.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
11df0bf54b signal.rs: use wide strings for string conversion
This makes it play better with the rest of the system,
in particular summary_command() from proc.h.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
f9a48dc946 flog.rs: allow trailing commas 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
91008acd3e fd_monitor.rs: make NativeCallback public
The upcoming io.rs calls "FdMonitorItem::new".  We cannot pass a closure,
we must pass an object of type NativeCallback.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
7069455e68 topic_monitor.rs: minor touch-up 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
483f893613 fds.rs: port the open_cloexec family 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
a5cae59082 Replace ScopedPush with scoped_push which is underpinned by ScopeGuard
This allows us to use the scoped push in more scenarios by appeasing the
borrow checker.

Use it in a couple of places instead of ScopeGuard. Hopefully this is makes
porting easier.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
2d4fbc290b Teach ScopeGuard to expose a custom view on deref()
This allows the upcoming scoped_push to stuff internal data into the context,
but not expose it to the user.
(This change is a bit ugly, needs polish)
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
a696f16aa1 compat.c: wrapper to access ncurses cur_term 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
9d436ee5e9 common.rs: port get_by_sorted_name() 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
c6b8b7548f common.rs: add fwprintf and fwputs for convenience
We should get rid of them but this helps with porting.
Not sure if they are fully correct.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
f53aa6f2e3 Port the rest of wutil 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
d3a7e3ffd9 Allow to call join_strings with a &[WString] 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
8e972dbab0 Move wrealpath and normalize_path to match C++ structure 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
b7638b50e4 common.rs: convenience function to convert to OsString
Even though we generally dont' want to use this type (because it's immutable),
it can be advantageous when working with the std::fs API.  This is because
it implements "AsRef<Path>" which neither of CString and Vec<u8> do.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
bfe68e6a83 common.rs: helper to convert from C-string of unknown length to wide
On the C++ side we have an overload that called std::wcslen(), this is the
equivalent one.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
3163efb87f Port most of fallback 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
1426d1bcb0 Port widecharwidth 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
8bbf663dee common.rs: make some functions public 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
bff0caf1d8 common.rs: remove typedefs that have been ported to elsewhere
In general we should keep the existing structure, to minimize surprise.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
8ae1ba3432 wutil: remove unused locale handling code that has been ported already 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
77ae80f842 wutil.cpp: remove unused function 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
d47590b864 proc.h: remove unused declaration 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
16ea4380c5 redirection.rs: don't leak FFI type into Rust code 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
807d1578c3 redirection.rs: make redirection spec fields public like in C++ 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
11e16ef6df env.rs: rename flags::EnvMode to EnvMode
The "flags" module was introduced when these where standalone constants.
Now that we define them as bitflags, we no longer need the extra namespace.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
8e5adbf237 Use borrowing syntax instead of std::ptr::addr_of where possible
We usually don't need to cast; this looks simpler.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
ed2b98dd9a lib.rs: group common.rs before other modules, because it exports macros
This allows us to keep the next group sorted.
2023-04-16 17:21:54 +02:00
Johannes Altmanninger
a848877e65 Remove an overload in io, to prepare for Rust 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
85ae1861fa common.rs: fix leftover comment 2023-04-16 17:21:54 +02:00
Johannes Altmanninger
df6525e770 Make RustBuiltin a scoped enum
This prevents name clashes. It already is used as scoped enum.
2023-04-16 17:21:54 +02:00
Xiretza
61028f020c cargo update
This fixes an issue with rust-analyzer always rebuilding even without changes,
which was introduced by b8189da011.
2023-04-16 17:21:54 +02:00
Fabian Boehm
bf0ebd3967 Actually add builtin.rs 2023-04-16 11:41:41 +02:00
Fabian Boehm
72a32f1a12 Rewrite "builtin" builtin in Rust
This is very simple and basically a subset of type.
2023-04-16 11:30:31 +02:00
Fabian Boehm
b65a53a2a6 Rewrite "command" builtin in Rust
This is basically a subset of type, so we might as well.

To be clear this is `command -s` and friends, if you do `command grep` that's
handled as a keyword.

One issue here is that we can't get "one path or not" because I don't
know how to translate a maybe_t? Do we need to make it a shared_ptr instead?
2023-04-16 11:27:08 +02:00
Fabian Boehm
662a4740e2 Rewrite the type builtin in rust 2023-04-16 11:27:08 +02:00
Fabian Boehm
7c37b681b2 Expose out_is_redirected to rust 2023-04-16 11:27:08 +02:00
Fabian Boehm
d02d0f3309 highlight: Add colorize_shell wrapper
Since we don't reuse the vector anyway, this allows us to keep the
highlighting on the C++-side.
2023-04-16 11:27:08 +02:00
Fabian Boehm
31d65de26c function: Add a bunch of awkward helper functions
This makes function_properties_ref_t not const, in order to work
around cxx
2023-04-16 11:27:08 +02:00
Fabian Boehm
d0c2d0c9cf path: Add method to return wcstring_list_ffi_t
This is palatable to Cxx
2023-04-16 11:27:08 +02:00
ridiculousfish
15c8f08458 Eliminate to_rust_string_vec
This can just use wcstring_list_ffi_t now.
2023-04-15 18:15:37 -07:00
ridiculousfish
dee969bf3a Introduce wcstring_list_ffi_t
wcstring_list_ffi_t is an autocxx-friendly type for passing lists of
strings from C++ to Rust.
2023-04-15 17:53:52 -07:00
Jan Tojnar
9e223577aa Fix composer require completion
When no development dependencies are installed, the completion would crash with:

    KeyError: 'require-dev'
2023-04-12 21:05:23 +02:00
Paweł Piątkowski
bda9d57417 Ansible completion: fix typo in --limit-hosts 2023-04-12 16:52:13 +02:00
Johannes Altmanninger
9983c32a57 Port over builtin exit codes
They used to live in common.h but they are mostly used by builtins so I
grudgingly accept the early move.
2023-04-11 09:29:28 +02:00
Mahmoud Al-Qudsi
d728b884dd Update pinned cxx dependency
Pulls in fish-shell/cxx 00536f3b771c9741bc325b37e7627d52052240a3 which
implements `VectorElement` for `CxxWString`.
2023-04-10 20:51:07 -05:00
Eric N. Vander Weele
fdd4bcf718 completions/git: Allow switch to complete remote branches
While it is true that `git switch <remote-branch>` errors to disallow a detached
head without the `-d` option, it is valid to use any starting point (commit or
reference) in conjunction with the `-c` option. Additionally, the starting point
can occur before any option.

This enables the following completions:

* `git switch -c <local-name> <any-branch>`
* `git switch <any-branch> -c <local-name>`
* `git switch -d <any-starting-point>`
* `git switch <any-branch> -d`

The trade-off is this does allow for `git switch <remote-branch>` to be
completed with an error.

Note that this logically reverts 7e3d3cc30f.
2023-04-10 17:04:34 +02:00
AsukaMinato
8a0510a2f2 add qjs completion 2023-04-10 11:02:43 +02:00
AsukaMinato
36e4b0ff30 add completion for ar (#9720)
* add completion for ar

* clean the function

* update CHANGELOG
2023-04-10 11:01:47 +02:00
ridiculousfish
de24e84a48 Changelog fix for #9722 2023-04-09 11:34:45 -07:00
abp
bbe2a2ba9b completions: Shortened descriptions
- Mainly work is done on gcc
- Some duplicated removed elsewhere
2023-04-09 11:33:23 -07:00
ridiculousfish
0ad3e3a45d Changelog fix for #9717 2023-04-08 20:23:21 -07:00
Eric N. Vander Weele
4ed53d4e3f reader: Apply fish_color_selection fg color and options in vi visual mode
Vi visual mode selection highlighting behaves unexpectedly when the selection
foreground and background in the highlight spec don't match. The following
unexpected behaviors are:

*  The foreground color is not being applied when defined by the
   `fish_color_selection` variable.
* `set_color` options (e.g., `--bold`) would not be applied under the cursor
  when selection begins in the middle of the command line or when the cursor
  moves forward after visually selecting text backward.

With this change, visual selection respects the foreground color and any
`set_color` options are applied consistently regardless of where visual
selection begins and the position of the cursor during selection.
2023-04-08 20:20:58 -07:00
ridiculousfish
169f90448a Stop generating autoccx ffi wrappers for pcre2 regex
We have "native" FFI wrappers for these now via the pcre2 crate.
2023-04-08 19:05:08 -07:00
Andy Hall
6ff971e4c2 Fix typo in set docs 2023-04-08 18:56:46 -07:00
Eric N. Vander Weele
a6e16a11c2 docs/interactive: Document fish_color_history_current variable
All *.theme files set variables documented in the "Syntax highlighting
variables" section, and fish_color_history_current was missing.
2023-04-07 15:29:23 +02:00
David Adam
733b981983 fish.spec/Debian packaging: add cargo dependency 2023-04-07 12:45:24 +08:00
David Adam
8c645186c0 fish.spec: replace tabs with spaces 2023-04-07 12:22:34 +08:00
ridiculousfish
a487b1ecf2 Revert "Revert "Implement builtin_printf in Rust""
This reverts commit 9f7e6a6cd1.

Add additional fixes from code review.
2023-04-06 15:54:09 -07:00
ridiculousfish
2d6f752f6e Revert "Add link-asan to RUSTFLAGS in CI"
This reverts commit 8bb1bb8ae1.
2023-04-06 14:29:18 -07:00
ridiculousfish
14c5c94d01 Use hexponent to implement hex float parsing in wcstod
This teaches wcstod to parse hex floats like 0x1.5p3 via a forked
version of hexponent. This support is necessary for printf.
2023-04-06 14:29:18 -07:00
ridiculousfish
74104f76ad wcstod() to skip leading whitespace
This matches the C implementation.
2023-04-06 14:29:18 -07:00
Fabian Boehm
79f8364bc7 docs/completions: Add a teensy bit more
This should really be expanded instead of just pointing at the example
2023-04-04 18:07:25 +02:00
Fabian Boehm
a6560a4ea8 docs/fish_add_path: Also clarify the examples 2023-04-04 17:55:10 +02:00
Fabian Boehm
4a39772ed2 docs/fish_add_path: More on --path and appending 2023-04-04 17:50:01 +02:00
Miha Filej
b5bfff9cac completions/mix: Add options for phx.new in 1.7.2 (#9706) 2023-04-04 07:41:11 -05:00
Marcin Wojnarowski
0f1ef34736 Fix adb path completion (#9707)
Support paths with spaces.
2023-04-03 22:06:15 -05:00
Mahmoud Al-Qudsi
3932ed118e Update cxx dependency
The let_cxx_wstring!() macro now works and can be used to avoid needing an extra
ffi call to obtain a (pinned) wstring object.
2023-04-03 22:03:08 -05:00
David Adam
5a03a17b9a make_tarball: fix the vendor tarball generation path
Tilde expansion doesn't work inside quotes.
2023-04-02 21:20:49 +08:00
Johannes Altmanninger
a3e6353c05 Remove redundant comment, fish targets Unix-like systems 2023-04-02 15:17:06 +02:00
Johannes Altmanninger
ad5c86604b Simplify string narrowing logic 2023-04-02 15:17:06 +02:00
Johannes Altmanninger
735d6a53a5 common.rs: implement string escaping
This is duplicated (but need not be).
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
05bad5eda1 Port common.{h,cpp} to Rust
Most of it is duplicated, hence untested.

Functions like mbrtowc are not exposed by the libc crate, so declare them
ourselves.
Since we don't know the definition of C macros, add two big hacks to make
this work:
1. Replace MB_LEN_MAX and mbstate_t with values (resp types) that should
   be large enough for any implementation.
2. Detect the definition of MB_CUR_MAX in the build script. This requires
   more changes for each new libc. We could also use this approach for 1.

Additionally, this commit brings a small behavior change to
read_unquoted_escape(): we cannot decode surrogate code points like \UDE01
into a Rust char, so use � (\UFFFD, replacement character) instead.
Previously, we added such code points to a wcstring; looks like they were
ignored when printed.
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
998cb7f1cd New wcs2zstring to explicitly convert to zero-terminated strings
wcs2string converts a wide string to a narrow one.  The result is
null-terminated and may also contain interior null-characters.
std::string allows this.

Rust's null-terminated string, CString, does not like interior null-characters.
This means we will need to use Vec<u8> or OsString for the places where we
use interior null-characters.
On the other hand, we want to use CString for places that require a
null-terminator, because other Rust types don't guarantee the null-terminator.

Turns out there is basically no overlap between the two use cases, so make
it two functions. Their equivalents in Rust will have the same name, so
we'll only need to adjust the type when porting.
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
3b15e995e7 str2wcs: encode invalid Unicode characters in the private use area
Rust does not like invalid code points, so let's ease the transition by
treating them like byte sequences that do not map to any code point.
See https://github.com/fish-shell/fish-shell/pull/9688#discussion_r1155089596
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
746019e4ad common.rs: reorder to match C++ companion
This makes it easier to check that we ported everything.
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
ed3a0b2bc3 Move join_strings into wcstringutil.rs
On the C++ side it lives in wcstringutil.cpp.  We should probably keep
it there until we have ported the entirety of that file.
2023-04-02 15:17:06 +02:00
Johannes Altmanninger
4f14b8dc7b Rename byte encoding helper
Existing C++ code didn't use a function for this but simply added
ENCODE_DIRECT_BASE. In Rust that's more verbose because char won't do
arithmetics, hence the function.

We'll add a dual function for decoding, so let's rename this.

BTW we should get rid of the "wchar" naming, it's just "char" in Rust.
2023-04-02 15:17:06 +02:00
ridiculousfish
0b6605b026 CHANGELOG fix for #9700 2023-04-01 10:07:13 -07:00
BrewingWeasel
d9c1fb5d51 fix E not moving cursor at end of word in VI mode 2023-04-01 10:04:28 -07:00
Fabian Boehm
d671710656 docs: Chapter on combining redirections
Fixes #5319
2023-04-01 16:03:24 +02:00
ridiculousfish
df3f2d678c Changelog fix for #9699 2023-03-31 20:29:26 -07:00
ridiculousfish
c67d77fc18 Revert "Speed up executable command completions"
This reverts commit 0b55f08de2.

This was found to have caused regressions in completions in #9699
2023-03-31 20:21:52 -07:00
Robert Szulist
9bd1dc14e5 Add Zabbix completions (#9647)
Add Zabbix completions
2023-03-31 22:13:40 -05:00
Fabian Boehm
43e8bb4532 fish_vi_cursor: Don't call __fish_cursor_konsole anymore
This hasn't been used for years.
2023-03-31 20:07:54 +02:00
Fabian Boehm
e45bddcbb1 __fish_cursor_xterm: Ignore unknown cursor settings
This prevents leaking the escape sequence by printing nonsense, and it
also allows disabling cursor setting by just setting the variable to
e.g. empty.

And if we ever added any shapes, it would allow them to be used on new
fish and ignored on old

Fixes #9698
2023-03-31 20:07:54 +02:00
David Adam
e78560d927 make_tarball: quote variables
Fixes a shellcheck warning
2023-03-30 13:22:59 +08:00
David Adam
94ae87afa0 make_tarball: support generating a Corrosion vendor tarball 2023-03-30 13:22:01 +08:00
David Adam
9c8c7f9251 make_tarball: correct a comment 2023-03-30 12:12:09 +08:00
David Adam
1c978f7ec5 cmake: add support for vendored cmake
Use a "cmake-vendored" directory if it exists, to avoid accessing the
network if it's available, and a target to create an appropriate tarball
to create that directory.
2023-03-30 12:01:25 +08:00
Clemens Wasser
3ae16a5b95 trace: Port trace to Rust 2023-03-28 20:11:42 -07:00
Fabian Boehm
bc04abe3ec completions/git: Don't take options for --{force-,}create
We do the same for checkout -b.

Fixes #9692
2023-03-28 17:20:45 +02:00
ridiculousfish
9f7e6a6cd1 Revert "Implement builtin_printf in Rust"
This reverts PR #9666. This had outstanding review comments and should
not have been committed.
2023-03-27 22:03:30 -07:00
Fabian Boehm
c39780fefb __fish_complete_directories: Remove --foo= from token
Otherwise this would complete

`git --exec-path=foo`, by running `complete -C"'' --exec-path=foo"`,

which would print "--exec-path=foo", and so it would end as

`git --exec-path=--exec-path=foo` because the "replaces token" bit was
lost.

I'm not sure how to solve it cleanly - maybe an additional option to
`complete`?

Anyway, for now this
Fixes #9538.
2023-03-27 22:57:34 +02:00
Fabian Boehm
563b4d2372 completions/git: Complete branches for --set-upstream-to
See #9538
2023-03-27 22:57:34 +02:00
ridiculousfish
b0a3e14832 Collapse duplicate ENCODE_DIRECT_BASE and ENCODE_DIRECT_END
Credit to @Xiretza for spotting this.
2023-03-27 13:42:38 -07:00
Emily Grace Seville
ba7785856e Add md-to-clip completion
- https://github.com/command-line-interface-pages/v2-tooling/tree/main/md-to-clip
2023-03-27 17:29:53 +02:00
Chris Wendt
3a72d098e2 Use stack's dynamic completions (#9681)
* Use dynamic completions for stack

* Pass the plain command
2023-03-27 17:29:14 +02:00
Fabian Boehm
ca02e88ef1 docs: Prevent overflow for narrow screens
Regression from #9003, this is visible on mobile mainly.

Fixes #9690
2023-03-27 17:21:09 +02:00
ridiculousfish
f096841e4d Remove C++ printf bits
This removes the builtin printf C++ implementation, as it is now in
Rust.
2023-03-26 17:40:24 -07:00
ridiculousfish
3eb6f2ac74 Implement builtin_printf in Rust
This implements builtin_printf in Rust.
2023-03-26 17:40:24 -07:00
ridiculousfish
558baf4957 Implement some locale pieces
This adds locale.rs, which maintains a locale struct sufficient to
support printf.
2023-03-26 17:40:24 -07:00
ridiculousfish
dad1290337 Replace the printf implementation
The existing printf implementation is too buggy to back the printf
builtin. Switch to the new implementation based on printf-compat.
2023-03-26 14:07:29 -07:00
ridiculousfish
389d25e30f Allow sprintf! to work with literal format strings
Now sprintf! has two modes:

- Literal format string
- Widechar runtime-format string
2023-03-26 13:39:23 -07:00
ridiculousfish
aa46e7b27c Correct wcstoi for "leading zeros"
Prior to this change, wcstoi("0x") would fail with missing digits.
However strtoul will "backtrack" to return just the 0 and leave the x as
the remainder. Implement this behavior.
2023-03-26 13:39:23 -07:00
ridiculousfish
f4fa0171f2 wcstoi to match strtoul for unsigned types and negative input
Prior to this change, wcstoi() would return an error if the requested
type were unsigned, and the input had a leading minus sign. However this
causes problems for printf, which expects strtoul behavior.

Add "modulo base" behavior which wraps the negative value to positive.
Factor this into an option; the default is False (but code which
previously used strtoull directly should set it to true).
2023-03-26 13:39:23 -07:00
ridiculousfish
dc8aab3f52 Introduce fish_wcstoi_partial
fish_wcstoi_partial is like fish_wcstoi: it converts from a string to an
int optionally inferring the radix. fish_wcstoi_partial also returns the
number of characters consumed.
2023-03-26 13:39:22 -07:00
ridiculousfish
7729d3206a Implement wcstod() in Rust
This is built around fast-float.

Factor the error type from this and wcstoi() together into a shared
type.
2023-03-26 13:38:58 -07:00
ridiculousfish
0e68405ccd Add our fast-float crate
This adds a dependency on https://github.com/fish-shell/fast-float-rust
which is our forked fast-float crate for parsing.
2023-03-26 13:38:09 -07:00
ridiculousfish
8bb1bb8ae1 Add link-asan to RUSTFLAGS in CI
This fixes our CI for the new crates we're about to add.
2023-03-26 11:07:15 -07:00
Johannes Altmanninger
76145145fd global_safety: port RelaxedAtomicBool 2023-03-26 19:35:57 +02:00
Johannes Altmanninger
a0eed3760e Cargo.toml: sort dependencies 2023-03-26 17:24:45 +02:00
Johannes Altmanninger
eb377d3c65 common.rs: implement Default for EscapeFlags 2023-03-26 17:17:37 +02:00
Johannes Altmanninger
981e470a2e common.rs: use bitflags for escape flags
See this discussion:
https://github.com/fish-shell/fish-shell/pull/9636#discussion_r1125640395
2023-03-26 17:17:37 +02:00
Johannes Altmanninger
312ae36a34 common.h: remove unused declaration 2023-03-26 17:17:37 +02:00
Johannes Altmanninger
b64c3eb79b termsize.rs: export Termsize 2023-03-26 17:17:37 +02:00
Johannes Altmanninger
d073b7140b lib.rs: sort modules 2023-03-26 17:17:37 +02:00
Johannes Altmanninger
16fa942074 parse_constants.rs: stop decoding UTF-8 when parsing keywords
Unfortunately we cannot use wide string literals in match statements
(not sure if there's an easy fix).
Because of this, I converted the input to UTF-8 so we could use the match
statement. This conversion is confusing, let's skip it.
2023-03-26 17:17:37 +02:00
ridiculousfish
b8189da011 Use the rust-pcre2 crate for regex
This adds support for our (forked) rust-pcre2 crate.
2023-03-25 17:01:50 -07:00
Fabian Boehm
aa268696bf reader: Skip FreeBSD directory hack for stdin
This can be triggered on linux with:

```js
import { spawn } from 'child_process';
const shell = spawn('/home/alfa/dev/fish-shell/build-c++/fish', []);
```

Under node 19.8.1.

*No clue* how that happens, but since this is a workaround we shall
skip it.
2023-03-25 20:47:38 +01:00
David Adam
e2579a59ba CHANGELOG: fix date for 3.6.1 2023-03-25 22:57:24 +08:00
David Adam
83a9555b47 Merge branch 'Integration_3.6.1' 2023-03-25 17:19:33 +08:00
NextAlone
45b6622986 completion/ssh-copy-id: add completion (#9675)
Add completions for ssh-copy-id.

Refactored __ssh_history_completions into its own file for autoloading across completions.
2023-03-22 12:24:18 -05:00
NextAlone
ff34c1a573 completion/git: complete tags for force option (#9678) 2023-03-22 11:07:18 -05:00
sigmaSd
860de8aa8f minor cleanup 2023-03-22 11:00:59 -05:00
sigmaSd
b95085609e deno task take one argument max 2023-03-22 11:00:59 -05:00
sigmaSd
93bf4e1187 Update deno task completions to handle deno.jsonc and package.json 2023-03-22 11:00:59 -05:00
NextAlone
da3323bbc2 completion/adb: add execout and complete props
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2023-03-21 22:20:36 -05:00
Fabian Boehm
cd7e8c00e1 Silence fstatat errors
These just keep happening, people run haunted computers.

Fixes #9674.
2023-03-21 17:10:23 +01:00
Mahmoud Al-Qudsi
fb74f77c86 Use bsd feature for signals
Signals present in 4.4BSD can be assumed present on all modern BSD derivatives.
2023-03-20 20:28:25 -05:00
Mahmoud Al-Qudsi
f2cf54608d Migrate existing rust code to Signal type
Everything but signal handlers has been changed to use `Signal` instead of
`c_int` or `i32` signal values.

Event handlers are using `usize` to match C++, at least for now.
2023-03-20 16:17:28 -05:00
Mahmoud Al-Qudsi
1f4c233dfb Add Signal newtype
Signal is a newtype around NonZeroI32. We could use NonZeroU8 since all signal
values comfortably fit, but using i32 lets us avoid a fallible attempt at
narrowing values returned from the system as integers to the narrower u8 type.

Known signals are explicitly defined as constants and can be matched against
with equality or with pattern matching in a `match` block. Unknown signal values
are passed-through without causing any issues.

We're using per-OS targeting to enable certain libc SIGXXX values - we could
change this to dynamically detecting what's available in build.rs but then it
might not match what libc exposes, still giving us build failures.
2023-03-20 16:17:28 -05:00
AsukaMinato
2e66bb19da use $( ... )* syntax 2023-03-20 11:20:12 -07:00
ridiculousfish
732f7284d4 Adopt the new termsize
This eliminates the C++ version.
2023-03-19 16:13:41 -07:00
ridiculousfish
6ec35ce182 Reimplement termsize in Rust
This is not yet adopted by fish.
2023-03-19 16:13:41 -07:00
ridiculousfish
30feef6a72 Migrate env_stack_t::get_or_null to environment_t
Allows it to be used when we only have an environment_t.
2023-03-19 16:13:41 -07:00
Mahmoud Al-Qudsi
3fab931e86 Fix build.rs formatting and prep it for further feature detections 2023-03-19 18:12:50 -05:00
ridiculousfish
99c6c76c5e Add the category name back to FLOG output in Rust
This went missing.
2023-03-19 16:04:57 -07:00
Mahmoud Al-Qudsi
34a4c7de7f Add BSD feature
This should be used in lieu of manually targeting individual operating systems
when using features shared by all BSD families.

e.g. instead of

   #[cfg(any(target_os = "freebsd", target_os = "dragonflybsd", ...))]
   fn foo() { }

you would use

    #[cfg(feature = "bsd")]
    fn foo() { }

This feature is automatically detected at build-time (see build.rs changes) and
should *not* be enabled manually. Additionally, this feature may not be used to
conditionally require any other dependency, as that isn't supported for
auto-enabled features.
2023-03-19 17:55:22 -05:00
ridiculousfish
57f4571a01 Rewrite wait handles and wait handle store in Rust 2023-03-18 18:53:04 -07:00
AsukaMinato
14d6b1c3de Simplify Default impl for ParseError
By implementing `Default` for `ParseErrorCode`, `ParseError` can just
`#[derive(Default)]` instead.

Closes #9637.
2023-03-17 19:59:52 -05:00
Fabian Boehm
a16abf22d9 builtins: Don't crash for negative return values
Another from the "why are we asserting instead of doing something
sensible" department.

The alternative is to make exit() and return() compute their own exit
code, but tbh I don't want any *other* builtin to hit this either?

Fixes #9659
2023-03-14 10:53:35 +01:00
Quinten Roets
f5506803d7 fish_vi_cursor: add new variable for external cursor mode (#9565)
* add new variable for external cursor mode

* fix backwards compatibility

* add documentation

* document change in changelog
2023-03-14 10:50:20 +01:00
Xiretza
b39715434b ScopeGuard: remove memory leak
Calling ScopeGuard::rollback() would leak the `on_drop` callable; this is
a problem for Box<dyn FnOnce> or closures containing Drop data.
2023-03-13 11:54:05 -05:00
lengyijun
aa65856ee0 Fixes #8924 via __fish_complete_suffix overhaul
Before:
* hand write arg parse
* only accepts one suffix

After:
* use `arg_parse` to parse args
* accepts multi suffixes

Closes #9611.
2023-03-12 22:07:44 -05:00
ridiculousfish
dea18b34aa Add tests for normalize_path and fix some bugs 2023-03-12 19:50:35 -07:00
ridiculousfish
33fd679f68 Use char_at instead of to_char_slice() 2023-03-12 19:50:35 -07:00
ridiculousfish
f54a45d09c Add missing builtin_print_help in realpath
This got dropped in the port.
2023-03-12 19:50:35 -07:00
Victor Song
88e0c2137a Added constants for expansions 2023-03-12 19:50:35 -07:00
Victor Song
80c8bc75e6 Switch to errno crate 2023-03-12 19:50:35 -07:00
Victor Song
3dfc9082e6 Use std::io::Error::last_os_error() for errno 2023-03-12 19:50:35 -07:00
Victor Song
ca494778e4 builtins: Port realpath to Rust 2023-03-12 19:50:35 -07:00
Mahmoud Al-Qudsi
47b4e3d067 fixup! Switch signals from usize to i32
Just address two clippy lints that are fallout from changing the signal type.
There's no longer any need to convert these (which gets rid of an unwrap).
2023-03-12 21:38:24 -05:00
Mahmoud Al-Qudsi
4f30993dbb Use ScopeGuard to replace manually saved-and-restored variables 2023-03-12 21:32:35 -05:00
Mahmoud Al-Qudsi
11766cf56f Add a proper rust ScopeGuard
Due to limitations imposed by the borrow checker, there are very few places
where we will be able to use the `ScopedPush` class ported over from the C++
codebase (once you capture the value w/ a `ScopedPush` you can't access the
value - or the mutable reference you used to reach it! - until the `ScopedPush`
object goes out of scope).

This alternative requires binding the previous values to a variable and manually
restoring them in the callback passed to the `ScopeGuard` constructor, but will
work with rust's borrow and `&mut` paradigm.
2023-03-12 21:32:35 -05:00
Victor Song
06547aef54 Detect rust-analyzer in build script to enable autocxx completions
Currently the `autocxx` generated code does not produce any code intelligence
because `rust-analyzer` can't find the generated code since it's not in the
workspace. Here, we detect `rust-analyzer` by checking for a `RUSTC_WRAPPER`
environment variable containing `rust-analyzer` and changing (or avoid changing)
the output directory accordingly.

Closes #9654.
2023-03-12 21:31:28 -05:00
ridiculousfish
409bf2995d Switch signals from usize to i32
This eliminates some conversions.
2023-03-12 17:08:35 -07:00
ridiculousfish
161734f310 Remove bitset module
This was added to support signals; however we are unlikely to use this
for anything else. Remove it; just use a u64 to report signals that have
been set.
2023-03-12 16:58:22 -07:00
Mahmoud Al-Qudsi
8e9dc74a02 Simplify EventType matching slightly 2023-03-12 16:24:04 -05:00
Mahmoud Al-Qudsi
dabe7a1c7c Skip tmux-complete test under WSL
The test passes but only if executed on its own. It's not the most perfect test,
but I can basically never get `make test` to pass under WSL while that's not the
case on all my other machines.
2023-03-12 15:18:17 -05:00
Victor Song
77fe9933e2 builtins: Rewrite pwd in Rust
Closes #9625.
2023-03-12 15:18:15 -05:00
Mahmoud Al-Qudsi
6809a8dfbc Use a bit set for pending signals
This optimizes over both the rust rewrite and the original C++ code. The rust
rewrite saw `std::bitset` replaced with `[bool; 65]` which could result in a
lot of memory copy bandwidth each time we checked for and received no signals.
The original C++ code would iterate over all signal slots to see if any were
set. The code now returns a single u64 and only checks slots that are known to
have signals via an intelligent `Iterator` impl.
2023-03-12 14:55:50 -05:00
Xiretza
9ac6cbefb1 Port event.cpp to rust
Port src/event.cpp to fish-rust/event.rs and some needed functions.

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-03-12 14:55:50 -05:00
Mahmoud Al-Qudsi
c8d2f7a0da Add trait to convert FFI reference to &wstr
You can now use a reference to CxxWString or an allocated UniquePtr<CxxWString>
to get an &wstr temporary to use without having to allocate again (e.g. via
`from_ffi()`).
2023-03-12 14:55:50 -05:00
Shun Sakai
1a7e3024cc Update completions for pandoc (#9651)
- Change completions for input formats, output formats and highlight
  styles to dynamically complete
- Add more valid PDF engines
2023-03-10 16:44:03 -06:00
NextAlone
f0c5484eda completions/adb: unroot and optimize devices show (#9650)
* completions/adb: add unroot command

Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>

* completions/adb: use product and model both to show device

Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>

---------

Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2023-03-10 16:42:54 -06:00
ridiculousfish
5197bf75cd Point fish autocxx and similar dependencies at new fish-shell location
These crates have been moved into fish-shell org; update Cargo.toml to
reflect that.
2023-03-09 21:01:49 -08:00
Mahmoud Al-Qudsi
1bdb7dffaf Use cargo build -Z build-std for ASAN
This is recommended and increases coverage.
2023-03-08 11:27:15 -06:00
Mahmoud Al-Qudsi
ce5686edc7 Have ASAN CI use debug build
This catches things that might be optimized away by the compiler.
2023-03-07 13:04:28 -06:00
Mahmoud Al-Qudsi
91cf526d23 Enable rust address sanitizer for asan ci job (#9643)
Rust has multiple sanitizers available (with llvm integration).
-Zsanitizer=address catches the most likely culprits but we may want to set up a
separate job w/ -Zsanitizer=memory to catch uninitialized reads.

It might be necessary to execute `cargo build` as `cargo build -Zbuild-std` to
get full coverage.

When we're linking against the hybrid C++ codebase, the sanitizer library is
injected into the binary by also include `-fsanitize=address` in CXXFLAGS - we
do *not* want to manually opt-into `-lasan`. We also need to manually specify
the desired target triple as a CMake variable and then explicitly pass it to all
`cargo` invocations if building with ASAN.

Corrosion has been patched to make sure it follows these rules.

The `cargo-test` target is failing to link under ASAN. For some reason it has
autocxx/ffi dependencies even though only rust-native, ffi-free code should be
tested (and one would think the situation wouldn't change depending on the
presence of the sanitizer flag). It's been disabled under ASAN for now.
2023-03-06 18:15:36 -06:00
sigmaSd
307c58dd07 Add completions for deno task subcommand (#9618)
[ci skip]
2023-03-05 13:43:38 -06:00
Xiretza
dd7b177d72 builtins: set_color: remove unhandled -v/--version flag
Invoking `set_color -v` crashes fish.
2023-03-05 16:09:36 +01:00
Xiretza
8c4bbe89e1 gitignore: add clangd .cache directory 2023-03-05 14:04:07 +01:00
Agatha Lovelace
e32e6daced support prepending please instead of sudo/doas 2023-03-05 12:49:27 +01:00
Johannes Altmanninger
c6756e9324 Canonicalize some wide string imports
wchar.rs should not import let alone reexport FFI strings.
Stop re-exporting utf32str! because we use L! instead.

In wchar_ffi.rs, stop re-exporting cxx::CxxWString because that hasn't
seen adoption.

I think we should use re-exports only for aliases like "wstr" or for aliases
into internal modules.
So I'd probably remove `pub use wchar_ffi::wcharz_t = crate::ffi::wcharz_t`
as well.
2023-03-05 10:32:20 +01:00
Johannes Altmanninger
e6994ea3ac Remove obsolete clippy suppression
This type has been extracted to an alias, so it is okay now.
2023-03-05 10:32:20 +01:00
Mahmoud Al-Qudsi
d839fea748 Silence some more clippy lints
bool_assert_comparison is stupid, the reason they give is "it's shorter". Well,
`assert!(!foo)` is nowhere near as readable as `assert_eq!(foo, false)` because
of the ! noise from the macro.

Uninlined format args is a stupid lint that Rust actually walked back when they
made it an official warning because you still have to use a mix of inlined and
un-inlined format args (the latter of which won't complain) since only idents
can be inlined.
2023-03-05 00:54:17 -06:00
Mahmoud Al-Qudsi
4828346f8b Implement and use Read and Write traits for AutoCloseFd
This lets us use any std::io functions that build on top of these, such as
`write_all()` in place of our own `write_loop()`.
2023-03-05 00:33:54 -06:00
Mahmoud Al-Qudsi
455b744bca Port fd_monitor tests to rust
This shows some of the ugliness of the rust borrow checker when it comes to
safely implementing any sort of recursive access and the need to be overly
explicit about which types are actually used across threads and which aren't.

We're forced to use an `Arc` for `ItemMaker` (née `item_maker_t`) because
there's no other way to make it clear that its lifetime will last longer than
the FdMonitor's. But once we've created an `Arc<T>` we can't call
`Arc::get_mut()` to get an `&mut T` once we've created even a single weak
reference to the Arc (because that weak ref could be upgraded to a strong ref at
any time). This means we need to finish configuring any non-atomic properties
(such as `ItemMaker::always_exit`) before we initialize the callback (which
needs an `Arc<ItemMaker>` to do its thing).

Because rust doesn't like self-referential types and because of the fact that we
now need to create both the `ItemMaker` and the `FdMonitorItem` separately
before we set the callback (at which point it becomes impossible to get a
mutable reference to the `ItemMaker`), `ItemMaker::item` is dropped from the
struct and we instead have the "constructor" for `ItemMaker` take a reference to
an `FdMonitor` instance and directly add itself to the monitor's set, meaning we
don't need to move the item out of the `ItemMaker` in order to add it to the
`FdMonitor` set later.
2023-03-05 00:33:53 -06:00
Mahmoud Al-Qudsi
83a220a532 Make fd_monitor types useable from native code
We were only using their ffi implementations which are automatically
exported/public, but the actual functions we would need if we were to use
FdMonitor and co. in native rust code were either private or missing convenient
wrappers.
2023-03-05 00:23:01 -06:00
Mahmoud Al-Qudsi
78a78a834c Port read_loop() and write_loop() to rust
The existing code is kept, but a rusty version of these functions is added for
code that needs them.

These should only be temporarily used when porting 1-to-1 from C++; we should
use the std library's `read()` and `write_all()` methods instead in the future.
2023-03-05 00:22:56 -06:00
Mahmoud Al-Qudsi
f2f7d1d183 Simplify assert_sorted_by_name! macro
By extracting the equivalent of i32::cmp() into its own const function,
it becomes a lot easier to see what is happening and the logic can be
more direct.
2023-03-04 17:05:11 -06:00
Johannes Altmanninger
2c331e9c69 Implement more bitwise operation for parser bitfields
These will be used in the parser.

Maybe this type should be a struct with boolean fields. The current way has
the upside that the usage is exactly the same as in C++.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
5dbffa8b6d Add a maybe_t constructor taking std::unique_ptr
CXX does not allow generic types like maybe_t.  When porting a C++ function
that returns maybe_t to Rust, we return std::unique_ptr instead. Let's make
the transition more seamless by allowing to convert back to maybe_t implicitly.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
494f10a5a8 Use the correct type names for forward-declared parser types
This allows using the types in cxx bridges other than the ones that define
them.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
b92313b79d Allow using wgettext_fmt without comma from macros
Otherwise we'd get this error when using it from another macro

        Some(wgettext_fmt!($fmt $(, $args)*))
                               ^ missing tokens in macro arguments
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
7ec27617ae Support widestring macro on non-literal strings
This enables usage in macros like

        L!(stringify!($snake_case_name))

in the upcoming AST port.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
be89793669 Fix buffer overflow accessing error source in ParseError::describe()
For some reason this error is triggered by tests after the Rust port of
ast.cpp. Might want to get to the bottom of this but moving it back
to match the original C++ logic fixes it.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
386f952c53 Implement constructors for some parser types 2023-03-04 22:24:22 +01:00
Johannes Altmanninger
913eeffa7e Derive Copy for some parser types 2023-03-04 22:24:22 +01:00
Johannes Altmanninger
bb1c64b202 Make some parser types public 2023-03-04 22:24:22 +01:00
Johannes Altmanninger
d0bda9893b Silence -Wcomment warnings in cxx compiler runs
This is one of the few warnings we disable due to false positives.  Let's also
disable it in the preprocessing steps needed for the Rust build.

Other warnings we ignore are -Wno-address -Wunused-local-typedefs and
-Wunused-macros. I didn't add them here because I don't expect that they
will be triggered by the headers we give to cxx.
2023-03-04 22:24:22 +01:00
Johannes Altmanninger
0410bacdf6 clang-format C++ files 2023-03-04 22:24:22 +01:00
Johannes Altmanninger
326e62515b functions/history.fish: also save when called with --exact
After deleting a history item with

    history delete --exact --case-sensitive the-item

it is still reachable by history search until the shell is restarted.

Let's fix this by saving history after each deletion.  The non-exact variants
of "history delete" already do this.  I think this was just an oversight
owed to the fact that hardly anyone uses "--exact" (else we would surely
have changed it to not require an explicit "--case-sensitive").
2023-03-04 22:24:22 +01:00
ridiculousfish
497073f74e Add an assert in wcharz_t's constructor that it is not null
These strings should never be null.
2023-03-04 13:13:24 -08:00
Xiretza
8427e05bf7 Move escape_string tests to Rust
This way, both the Rust FFI wrapper and the actual C++ implementation are
tested.
2023-03-04 12:42:06 -08:00
ridiculousfish
7d48c5d44f Relnote change in #9634
Relnotes fastboot completion changes.
2023-03-04 12:25:20 -08:00
Next Alone
e12e615a5a completion/fastboot: fix completion to flash and format
Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
2023-03-04 12:23:46 -08:00
Xiretza
7585ddf926 Port color.cpp to Rust 2023-03-04 11:46:46 -08:00
Xiretza
a23de237a6 Port ASSERT_SORTED_BY_NAME to Rust 2023-03-04 11:46:46 -08:00
ridiculousfish
a3970c1661 Improve FLOG output
Prior to this fix, the Rust FLOG output was regressed from C++, because
it put quotes around strings. However if we used Display, we would fail
to FLOG non-display types like ThreadIDs.

There is apparently no way in Rust to write a function which formats a
value preferentially using Display, falling back to Debug.

Fix this by introducing two new traits, FloggableDisplay and
FloggableDebug. FloggableDisplay is implemented for all Display types,
and FloggableDebug can be "opted into" for any Debug type:

    impl FloggableDebug for MyType {}

Both traits have a 'to_flog_str' function. FLOG brings them both into
scope, and Rust figures out which 'to_flog_str' gets called.
2023-03-04 11:35:21 -08:00
Fabian Boehm
8471d06c96 Disable FreeBSD 14 CI
Fails randomly on the signals test, no idea why.
2023-03-03 20:45:44 +01:00
Maurizio De Santis
68ba30d8c8 Fix typo 2023-03-03 19:25:17 +01:00
mhmdanas
0f39de2eee xbps: actually show all packages in __fish_print_xbps_packages's output.
`xbps-query` actually parses `-Rsl` as `-Rs l`, which means that packages
without the letter "l" in their names or descriptions are not included in
`__fish_print_xbps_packages`'s output.
2023-03-03 18:07:45 +01:00
Fabian Boehm
af49b4d0f8 Disable bracketed paste for read
It's not of much use (read will only read a single line anyway) and
breaks things

Fixes #8285
2023-03-02 16:56:32 +01:00
Fabian Boehm
1aa3393f05 Test ifind bug with non-ascii codepoints 2023-03-02 16:33:20 +01:00
Fabian Boehm
7c91d009c1 reader: Remove assert in history search
This isn't a great use of `assert` because it turns a benign "oh I
need to search again" bug into a crash.

Fixes #9628
2023-03-02 16:29:49 +01:00
Johannes Altmanninger
14f3a5f79a Re-add highlighter tests
These were removed by accident.
2023-03-02 08:54:58 +01:00
Clemens Wasser
17c1fa9d64 Port bg builtin to Rust (#9621)
* bg: Port bg builtin to Rust
2023-02-28 16:42:12 -06:00
Fabian Boehm
f23103854c docs/if: Link to other builtins 2023-02-28 20:49:11 +01:00
Fabian Boehm
aff84ef87d docs/test: Simplify
A bit stuffy, also link to string/path
2023-02-28 20:47:50 +01:00
Victor Song
c7ea768a74 Rewrite wrealpath from wutil in Rust (#9613)
* wutil: Rewrite `wrealpath` in Rust

* Reduce use of FFI types in `wrealpath`

* Addressed PR comments regarding allocation

* Replace let binding assignment with regular comparison
2023-02-26 20:13:40 -07:00
Clemens Wasser
6f5be9bae4 block: Port block builtin to Rust
Closes #9612.
2023-02-26 14:16:55 -06:00
Clemens Wasser
330e8a86c7 block: Use an integer to count blocks 2023-02-26 14:12:57 -06:00
Xiretza
dff7db2f16 Run rustfmt and clippy in CI (#9616)
* Add machine-readable MSRV to Cargo.toml
* Fix clippy warnings
* CI: add rustfmt and clippy checks
2023-02-26 13:20:20 -06:00
Mahmoud Al-Qudsi
562eeac43e Port job_group to rust (#9608)
More ugliness with types that cxx bridge can't recognize as being POD. Using
pointers to get/set `termios` values with an assert to make sure we're using
identical definitions on both sides (in cpp from the system headers and in rust
from the libc crate as exported).

I don't know why cxx bridge doesn't allow `SharedPtr<OpaqueRustType>` but we can
work around it in C++ by converting a `Box<T>` to a `shared_ptr<T>` then convert
it back when it needs to be destructed. I can't find a clean way of doing it
from the cxx bridge wrapper so for now it needs to be done manually in the C++
code.

Types/values that are drop-in ready over ffi are renamed to match the old cpp
names but for types that now differ due to ffi difficulties I've left the `_ffi`
in the function names to indicate that this isn't the "correct" way of using the
types/methods.
2023-02-25 16:42:45 -06:00
David Adam
7213102942 make_tarball: use Ninja over Make where possible 2023-02-25 19:32:24 +08:00
Johannes Altmanninger
dab4b21a50 Merge pull request #9592 from nrjais/abbr_riir
port abbrs.cpp and abbr builtin to rust
2023-02-25 12:28:09 +01:00
Neeraj Jaiswal
f52569a800 abbr: port abbreviation and abbr builtin to rust 2023-02-25 12:24:58 +01:00
Neeraj Jaiswal
b0ed37c2e0 format: support whitespace padding in str formatting 2023-02-25 12:24:58 +01:00
Neeraj Jaiswal
e384e63b24 re: port regex make anchored to rust and helper ffi funtions for regex 2023-02-25 12:24:57 +01:00
Neeraj Jaiswal
6851d52924 env: port env constants to rust 2023-02-25 12:24:32 +01:00
Neeraj Jaiswal
7bab4c4dda common: pass c_str in ffi escape string 2023-02-25 12:24:32 +01:00
Johannes Altmanninger
5394ca1f96 Address clippy lints 2023-02-25 12:24:25 +01:00
Johannes Altmanninger
0d6b53bc3e Address clippy lints
We want to keep the cast because tv_sec is not always 64 bits, see b5ff175b4
(Fix timer.rs cross-platform compilation, 2023-02-14).
It would be nice to avoid the clippy exemption, perhaps using something like

    #[cfg(target_pointer_width = "32")]
    let seconds = val.tv_sec as i64;
    #[cfg(not(target_pointer_width = "32"))]
    let seconds = val.tv_sec;

but I'm not sure if "target_pointer_width" is the right criteria.
2023-02-25 12:24:25 +01:00
Johannes Altmanninger
b7041ad89b clang-format C++ files 2023-02-25 12:24:25 +01:00
Johannes Altmanninger
30d40c1d49 ffi.rs: sort includes in include_cpp
If we sort includes as we add them instead of adding them at the end, we'll
have fewer conflicts.
2023-02-25 12:24:25 +01:00
Johannes Altmanninger
b6ede1c2a3 complete.cpp: re-use constant in try_complete_variable 2023-02-25 11:53:43 +01:00
Neeraj Jaiswal
3b60bc1de0 contains: port contains builtin to rust 2023-02-22 18:32:27 +01:00
David Adam
a601babcf0 Merge a commit that was not pushed to master but has now been cherry-picked elsewhere 2023-02-22 22:04:19 +08:00
Akatsuki Rui
5a5cf267b7 cmake/Tests.cmake: Fix failure in cargo test (#9603)
The FISH_RUST_TARGET_DIR is not set for Tests.cmake, the target_dir will set to
$CARGO_MANIFEST_DIR/target. But if build.target-dir or CARGO_TARGET_DIR is set,
the real target_dir doesn't at the $CARGO_MANIFEST_DIR/target. It causes failure
in cargo test. Then, set --target-dir for cargo test.

Closes #9600
2023-02-21 11:44:59 -06:00
David Adam
e20d78431b docs/index: update some formatting from #9482 2023-02-21 21:17:26 +08:00
David Adam
ad5b3a5b17 debian packaging: use correct name for rust package 2023-02-21 09:10:45 +08:00
Mahmoud Al-Qudsi
aca7dedf33 Fix Tokenizer::parse_fd() on x86
Upsizing to `usize` from `i32` doesn't work if `usize` is only 32-bits.
I changed the code to use the `FromStr` impl on `i32`, but we could have also
just used `u64` instead of `i32`.

Also, we should get in the habit of using the appropriate type aliases where
possible (`i32` should be `RawFd`).
2023-02-20 13:41:11 -06:00
Mahmoud Al-Qudsi
e616de544e Enable rust overflow checks in release mode, at least for now
We want to try and catch as much unexpected/non-deterministic behavior as we
can. We could run the CI explicitly in debug mode, but I think it makes sense to
always have overflow checks on in both debug/release modes everywhere, at least
for the duration of the codebase transition.
2023-02-20 13:11:29 -06:00
Fabian Boehm
e3b04118b1 Revert "random: Do math as unsigned"
This reverts commit 0902e29f49.

Just doesn't work - overflows.
2023-02-20 19:56:34 +01:00
Fabian Boehm
ad22bf9387 GH Actions: Use our MSRV as the rust-version
Currently we're at 1.67, I don't want to accidentally introduce 1.68
features once that's released
2023-02-20 19:40:47 +01:00
Fabian Boehm
0902e29f49 random: Do math as unsigned
Hahah bits go brrrr
2023-02-20 19:39:55 +01:00
Xiretza
77a474ee37 Move POD components of library_data_t to separate struct
This allows them to be accessed as regular fields from Rust, rather than having
to create setter/getter methods for each of them.
2023-02-20 11:32:12 +01:00
Mahmoud Al-Qudsi
59fe124c40 builtins/random: Don't lock the mutex unnecessarily
The mutex was being locked from the very start, before it was needed and
possibly before it would be needed.

Also rename the static global to stick to rust naming conventions.

Note that `once_cell::sync::Lazy<T>` actually internally uses its own lock
around the value, but in this case it's insufficient because `SmallRng` doesn't
implement `SeedableRng` so we can't reseed it with only an `&mut` reference and
must instead replace its value.

We probably *could* still use `Lazy<SmallRng>` directly and then rely on
`std::mem::swap()` to replace the contents of the shared global static without
reassigning the variable directly with a new `SmallRng` instance, but I'm not
sure that's a great idea. This is just a built-in, there's no real harm in
locking twice (especially while fish remains essentially single-threaded).
2023-02-19 16:54:50 -06:00
Mahmoud Al-Qudsi
51eb5168e8 builtins/random: Fix stale comments and use explicit output type
The old comments about using i128 logic were still there even though we are no
longer using that approach and the output type was very much misleadingly a u64
printed to the console (but via `%d` so it was ultimately shown as an i64). Be
explicit about the resulting being a valid i64 value before passing it to the
sprintf!() macro.

Also add comments about the safety of the final `unwrap()` operation.
2023-02-19 16:54:50 -06:00
Mahmoud Al-Qudsi
05265e7d90 Port (and use) ASSERT_IS_BACKGROUND_THREAD/ASSERT_IS_MAIN_THREAD
Rust doesn't have __FUNCTION__ or __func__ (though you can hack around it with a
proc macro, but that will require a separate crate and slowing down compilation
times with heavy proc macro dependencies), so these are just regular functions
(at least for now). Rust's default stack trace on panic (even in release mode)
should be enough (and the functions themselves are inlined so the calling
function should be the second frame from the top, after the #[cold] panic
functions).
2023-02-19 16:54:50 -06:00
Mahmoud Al-Qudsi
452cd90c6c Add test asserting std::thread's behavior matches pthread's on *nix
This is to allow us to verify some implementation details that aren't explicitly
documented in the rust standard library's documentation.

std::thread uses `pthread_create()` underneath the hood on *nix platforms, so
this *should* merely be a formality.
2023-02-19 15:42:07 -06:00
Mahmoud Al-Qudsi
aaf2d1c19d Use * const u8 instead of * const c_void
The way cxx bridge works, it doesn't recognize any types from another module as
being shared cxx bridge types with generations native to both C++ and Rust,
meaning every module that was going to use function pointers would have to
define its own `c_void` type (because cxx bridge doesn't recognize any of
libc::c_void, std::ffi::c_void, or autocxx::c_void).

FFI on other platforms has long used the equivalent of `uint8_t *` as an
alternative to `void *` for code where `void` was not available or was
undesirable for some reason. We can join the club - this way we can always use
`* {const|mut} u8` in our rust code and `uint8_t *` in our C++ code to pass
around parameters or values over the C abi.
2023-02-19 15:42:07 -06:00
Mahmoud Al-Qudsi
4f6fe0999e Disable TSAN in CI for now
See issues encountered in #9586 due to TSAN not recognizing valid/safe rust
patterns.
2023-02-19 15:42:07 -06:00
Mahmoud Al-Qudsi
8deaede6c7 Patch a few minor issues in fd_monitor
These differ from the C++ code and are being committed separately.
2023-02-19 15:42:07 -06:00
Mahmoud Al-Qudsi
ce559bc20e Port fd_monitor (and its needed components)
I needed to rename some types already ported to rust so they don't clash with
their still-extant cpp counterparts. Helper ffi functions added to avoid needing
to dynamically allocate an FdMonitorItem for every fd (we use dozens per basic
prompt).

I ported some functions from cpp to rust that are used only in the backend but
without removing their existing cpp counterparts so cpp code can continue to use
their version of them (`wperror` and `make_detached_pthread`).

I ran into issues porting line-by-line logic because rust inverts the behavior
of `std::remove_if(..)` by making it (basically) `Vec::retain_if(..)` so I
replaced bools with an explict enum to make everything clearer.

I'll port the cpp tests for this separately, for now they're using ffi.

Porting closures was ugly. It's nothing hard, but it's very ugly as now each
capturing lambda has been changed into an explicit struct that contains its
parameters (that needs to be dynamically allocated), a standalone callback
(member) function to replace the lambda contents, and a separate trampoline
function to call it from rust over the shared C abi (not really relevant to
x86_64 w/ its single calling convention but probably needed on other platforms).

I don't like that `fd_monitor.rs` has its own `c_void`. I couldn't find a way to
move that to `ffi.rs` but still get cxx bridge to consider it a shared POD.
Every time I moved it to a different module, it would consider it to be an
opaque rust type instead. I worry this means we're going to have multiple
`c_void1`, `c_void2`, etc. types as we continue to port code to use function
pointers.

Also, rust treats raw pointers as foreign so you can't do `impl Send for * const
Foo` even if `Foo` is from the same module. That necessitated a wrapper type
(`void_ptr`) that implements `Send` and `Sync` so we can move stuff between
threads.

The code in fd_monitor_t has been split into two objects, one that is used by
the caller and a separate one associated with the background thread (this is
made nice and clean by rust's ownership model). Objects not needed under the
lock (i.e. accessed by the background thread exclusively) were moved to the
separate `BackgroundFdMonitor` type.
2023-02-19 15:42:03 -06:00
Fabian Boehm
f01a5d2a1b random: Do it in 64-bits
Turns out we can do it without switching to 128-bit wide numbers.

Co-authored-by: Xiretza <xiretza@xiretza.xyz>
2023-02-19 21:01:46 +01:00
Fabian Boehm
4fd1458d85 Port random to rust 2023-02-19 21:01:46 +01:00
Fabian Boehm
bc7c29d597 wcstoi: Allow erroring out if there are chars left
*No* idea if this is the idiomatic thing to do
2023-02-19 21:01:46 +01:00
Shun Sakai
189f4ca3c3 Add completions for scrypt 2023-02-19 10:22:01 -08:00
ridiculousfish
27f5490a55 Merge branch 'riir'
This merges the Rust bits.
2023-02-19 08:57:47 -08:00
Fabian Boehm
acde38fed3 webconfig: Set a variable before
This fixes things if a theme is entirely empty.

Fixes #9590
2023-02-19 14:57:32 +01:00
Xiretza
46aef09a90 Add more clippy exceptions for ffi module 2023-02-18 18:53:50 +01:00
Xiretza
698db6c2a7 builtins: make io_streams_t methods publicly accessible 2023-02-18 18:53:50 +01:00
Xiretza
71c2f08e5d printf: implement Printf for &WString 2023-02-18 18:53:50 +01:00
Xiretza
333056a9ec rust: add bindings for signal conversion functions 2023-02-18 18:53:50 +01:00
Xiretza
e6e866e455 Port escape_string() to Rust 2023-02-18 18:53:50 +01:00
Xiretza
15d4310ae9 Port scoped_push to Rust 2023-02-18 18:53:50 +01:00
Neeraj Jaiswal
844174367b wgetopt: fix long option match to always match prefix 2023-02-18 18:53:40 +01:00
Neeraj Jaiswal
1adfce18ee builtins: port return/exit to rust 2023-02-18 18:53:40 +01:00
bagohart
3dd8db281b Add tab completion for stow (#9571) 2023-02-18 18:37:45 +01:00
Delapouite
a29d760ca0 completions/systemctl: add import-environment command
Man page reference:
https://man.archlinux.org/man/systemctl.1#Environment_Commands
2023-02-18 18:36:30 +01:00
Xiretza
ba0bfb9df7 functions: list caller-exit handlers correctly
`functions --handlers-type caller-exit` did not list any functions, while
`functions --handlers-type process-exit` listed both process-exit and
caller-exit handlers:

$ echo (function foo --on-job-exit caller; end; functions --handlers-type caller-exit | grep foo)

$ echo (function foo --on-job-exit caller; end; functions --handlers-type process-exit | grep foo)
caller-exit foo
2023-02-18 18:35:40 +01:00
Fabian Boehm
4a1a59c5a8 tests/git: Also give the email to stash
WHYYYYYYYY

(anyway this seems to affect old git versions since we only seem to
hit it on old Ubuntu)
2023-02-15 20:11:46 +01:00
Fabian Boehm
d32449fe2e tests/git: Don't silence error, give email
(otherwise git complains about "AUTHOR UNKNOWN HELP HELP HELP I CANNAE
DO ANYTHIN'")

(i also don't know why git is scottish in my imagination)
2023-02-15 19:50:45 +01:00
Sam Bull
ef3516ecdf Test displaying only stash count (#9573) 2023-02-15 19:32:50 +01:00
Fabian Boehm
5aaa1e69bc fish_git_prompt: Allow counting stash without full informative
Fixes #9572
2023-02-15 19:28:18 +01:00
NextAlone
dcc8147147 docs: add apkanalyzer to changelog
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2023-02-15 19:00:47 +01:00
NextAlone
176097cc49 completions/apkanalyzer: add completion for apkanalyzer
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2023-02-15 19:00:47 +01:00
rymrg
43b1be0579 Improve fossil prompt execution time (#9528)
* Improve prompt execution time

* Change status to changes

* Remove grep/awk/sort

* Remove calls to grep/awk/sort
* Don't overwrite user defined colors

* Make look more consistent with git
2023-02-15 18:52:05 +01:00
Fabian Boehm
9c8b50cb8f docs: Make some code lines shorter
For code, we need to limit the length because it can't be reflowed automatically
2023-02-15 18:50:28 +01:00
Fabian Boehm
811dbf0f9a docs: More on dereferencing variables
Also that unclosed quote was driving me up the wall
2023-02-15 18:29:14 +01:00
Mahmoud Al-Qudsi
b5ff175b45 Fix timer.rs cross-platform compilation
* macOS does not have RUSAGE_THREAD
* tv_sec and tv_usec may be i32 instead of i64
2023-02-14 16:36:00 -06:00
Mahmoud Al-Qudsi
a1a8bc3d8d Port timer.cpp to rust 2023-02-14 15:54:18 -06:00
Fabian Boehm
cbc66fe6ea completions: More shortened descriptions 2023-02-14 21:16:22 +01:00
Fabian Boehm
d9a9fb50d0 completions/cargo: Descriptions 2023-02-14 21:04:05 +01:00
Fabian Boehm
902782b1f4 completions/rsync: Remove one thing that isn't an option 2023-02-14 20:47:52 +01:00
Fabian Boehm
38b21fc1c7 completions/gcc: Shorten descriptions
Many of these are just entirely useless and I'm thinking of removing a
bunch of options.
2023-02-14 20:47:52 +01:00
mhmdanas
a67b089c89 completions/xbps-query: complete package name after -X 2023-02-14 20:32:33 +01:00
Fabian Boehm
4a8ebc0744 __fish_complete_path: Also use an empty command
This removes a weird `ls` call (that just decorates directories), and
makes it behave like normal path completion.

(really, this should be a proper option to complete)

Fixes #9285
2023-02-14 17:09:58 +01:00
Fabian Boehm
200095998a __fish_complete_directories: Use an empty command as the dummy
Fixes #9574
2023-02-14 17:09:58 +01:00
Jay
ce268b74dd completions/trash-cli: add completions for trash-cli (#9560)
Add completions for trash-cli commands:
trash, trash-empty, trash-list, trash-put and trash-restore.

``trash --help`` are used to identify the executable in trash cli completion.
2023-02-13 12:10:55 -06:00
esdmr
a607421912 functions --copy: store file and lineno (#9542)
Keeps the location of original function definition, and also stores
where it was copied. `functions` and `type` show both locations,
instead of none. It also retains the line numbers in the stack trace.
2023-02-13 09:59:28 -06:00
matt wartell
904839dcce fix 3 instances of old command substitution $() 2023-02-12 16:49:40 +01:00
David Adam
340db7f7d3 fish.spec/debian packaging: add initial Rust dependencies 2023-02-12 22:53:14 +08:00
Dmitry Gerasimov
c3a72111e9 completions/meson: rewrite meson completions (#9539)
Rewrite completions for meson to expose meson commands with their
options and subcommands. New completions are based on the meson 1.0.

Subcommands were introduced in meson 0.42.0 (August 2017), so new
completions will only work for versions after 0.42.0. At this moment,
even oldstable Debian (buster) has meson 0.49.2 -- which means it is
unlikely someone will be affected.

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-02-11 17:58:45 -06:00
ridiculousfish
15c3698258 Mark Dup2List as a struct, not a class
Fixes clang warnings "class 'Dup2List' was previously declared as a
struct."
2023-02-11 12:13:51 -08:00
ridiculousfish
b7de768c73 Allow custom completions to have leading dots
By default, fish does not complete files that have leading dots, unless the
wildcard itself has a leading dot. However this also affected completions;
for example `git add` would not offer `.gitlab-ci.yml` because it has a
leading dot.

Relax this for custom completions. Default file expansion still
suppresses leading dots, but now custom completions can create
leading-dot completions and they will be offered.

Fixes #3707.
2023-02-11 11:27:14 -08:00
Xiretza
5a76c7d3b1 Port emit builtin to rust 2023-02-11 15:04:57 +01:00
Xiretza
3ed86fae1c Port parse_help_only_cmd_opts to Rust
This is duplicated for now, since a `&mut [&wstr]` can't be passed over FFI.
2023-02-11 15:04:57 +01:00
Fabian Boehm
b1b2294390 Add workaround for Midnight Commander's issue with prompt extraction
When we draw the prompt, we move the cursor to the actual
position *we* think it is by issuing a carriage return (via
`move(0,0)`), and then going forward until we hit the spot.

This helps when the terminal and fish disagree on the width of the
prompt, because we are now definitely in the correct place, so we can
only overwrite a bit of the prompt (if it renders longer than we
expected) or leave space after the prompt. Both of these are benign in
comparison to staircase effects we would otherwise get.

Unfortunately, midnight commander ("mc") tries to extract the last
line of the prompt, and does so in a way that is overly naive - it
resets everything to 0 when it sees a `\r`, and doesn't account for
cursor movement. In effect it's playing a terminal, but not committing
to the bit.

Since this has been an open request in mc for quite a while, we hack
around it, by checking the $MC_SID environment variable.

If we see it, we skip the clearing. We end up most likely doing
relative movement from where we think we are, and in most cases it
should be *fine*.
2023-02-11 14:18:10 +01:00
Fabian Boehm
7ac2fe2bd3 share/config: Erase on_interactive before doing __fish_config_interactive
This removes a possibility of an infinite loop where something in
__fish_config_interactive triggers a fish_prompt or fish_read event,
which calls __fish_on_interactive which calls
__fish_config_interactive again, ...

Fixes #9564
2023-02-11 14:15:44 +01:00
Xiretza
27c8845075 rust: fix typos in documentation, add links
Closes #9556
2023-02-11 08:54:53 +01:00
Fabian Boehm
24fb7ff67c completion/scons: Shorten descriptions 2023-02-10 21:10:05 +01:00
Fabian Boehm
4adb34d349 completions/dpkg-reconfigure: Don't run awkward things on source time
This wanted to get the default priority, and it ran a thing *at source
time*.

This can lead to a variety of errors and I don't believe it's all that
useful, so we remove it.
2023-02-10 20:58:58 +01:00
Fabian Boehm
85504ca694 completions/zfs: Check for zpool
This is an additional tool, and this function is executed on source
time so we'd spew errors.

(also remove an ineffective line - it's probably *nicer* with the
read, but that's not what's currently effectively doing anything)
2023-02-10 20:55:37 +01:00
Fabian Boehm
7d7b72f995 Use path basename instead of basename
This is faster and guaranteed to be available
2023-02-10 20:51:22 +01:00
Fabian Boehm
7b8684e469 completions/netcat: Use path 2023-02-10 20:50:14 +01:00
Fabian Boehm
cac483c67a completions: Quote some tests 2023-02-10 20:47:49 +01:00
Fabian Boehm
6fe4b0c24d completions/kb: Fix 2023-02-10 20:46:34 +01:00
NextAlone
c587b2ffcc completions/fastboot: fix flash completion
Signed-off-by: NextAlone <12210746+NextAlone@users.noreply.github.com>
2023-02-09 20:44:12 -08:00
Johannes Altmanninger
a8c992236e Document some porting bits 2023-02-09 00:39:01 +01:00
Johannes Altmanninger
39f3c894d7 Port tokenizer.cpp to Rust
In hindsight, I should probably have split this into three different commits.
2023-02-09 00:37:22 +01:00
Johannes Altmanninger
7f8d247211 Port parse_constants.h to Rust 2023-02-09 00:37:22 +01:00
Johannes Altmanninger
25816627de Port redirection.cpp to Rust 2023-02-09 00:37:22 +01:00
Johannes Altmanninger
9ca160eac2 Convert parse_error_code_t to a scoped enum
This will make the Rust port's diff smaller.
2023-02-08 21:49:54 +01:00
Johannes Altmanninger
8fd1db06ed Remove unused parse error code 2023-02-08 21:49:54 +01:00
Johannes Altmanninger
4639f7ec40 Follow Rust naming convention for some types
But don't do it for enum variants just yet.
2023-02-08 21:49:54 +01:00
Johannes Altmanninger
958ad3a9e7 ffi.rs: silence warning about get_procs()
We should fix this warning eventually.  Silence it for now to make Clippy
pass without warnings, which makes it much more useful.

       Compiling fish-rust v0.1.0 (/home/johannes/git/fish-riir/fish-rust)
    error: mutable borrow from immutable input(s)
      --> src/ffi.rs:79:32
       |
    79 |     pub fn get_procs(&self) -> &mut [UniquePtr<process_t>] {
       |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: immutable borrow here
      --> src/ffi.rs:79:22
       |
    79 |     pub fn get_procs(&self) -> &mut [UniquePtr<process_t>] {
       |                      ^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
       = note: `#[deny(clippy::mut_from_ref)]` on by default

    error: could not compile `fish-rust` due to previous error
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
29a2c4b718 gettext.rs: allow translating non-literal strings
A following commit will pass global string constants to the gettext macro.
This is not ideal because we might accidentally use the constants without
gettext (which we should never do). To fix that we might need to define a
macro per constant, or use a proc macro which is maybe not worth it.
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
47cc98fd57 wutil.h: enable implicit conversion from wcharz_t to wcstring
This allows to write

    wcstring result = some_rust_function_that_returns_wcharz_t();
2023-02-08 21:49:41 +01:00
Johannes Altmanninger
bfa94bfa7a Fix rustc warning about auto deref
warning: deref which would be done by auto-deref
      --> src/wchar_ffi.rs:81:5
       |
    81 |     &*EMPTY_WSTRING
       |     ^^^^^^^^^^^^^^^ help: try this: `&EMPTY_WSTRING`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
       = note: `#[warn(clippy::explicit_auto_deref)]` on by default
2023-02-08 21:49:41 +01:00
bagohart
ef07e21d40 Add separate completions for neovim (#9543)
Separate the neovim completions from the vim ones, as their supported
options have diverged considerably.

Some documented options are not yet implemented, these are added but
commented out.

Closes #9535.

---------

Co-authored-by: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
2023-02-08 12:47:08 -06:00
Septatrix
fdce63f8ab webconfig: Rewrite color tab with Alpine.js 2023-02-08 16:08:10 +01:00
Septatrix
ad90ae292d webconfig: First POC of Alpine.js rewrite 2023-02-08 00:34:10 +01:00
Xiretza
a16e2ecb1b Port echo builtin to Rust 2023-02-07 22:25:47 +01:00
Xiretza
4b85c2f6db builtin: propagate status from Rust builtins
The return type of `builtin_run_rust()` reflects that of C++ builtins.
2023-02-07 22:25:47 +01:00
Xiretza
cfb5bb2505 builtin: correctly flush streams after running Rust builtin 2023-02-07 22:25:47 +01:00
Fabian Boehm
8ff78eddf0 man: Reroute ".",":","[" to the proper names
Fixes #9552
2023-02-07 19:23:26 +01:00
Fabian Boehm
e90f003d2d Silence ENODEV errors for fstatat
Some broken gdrive filesystem can return these.

Fixes #9550
2023-02-06 21:49:07 +01:00
Fabian Boehm
f6b390dc61 completions/git: Remove a for-loop
This is an easy win for `git add ` completion time if we have multiple descriptions.

What happened was we did things once per description string, but the
things included a bunch of computation (including multiple `string`
calls and even a `realpath`!). Because these don't change, we can
simply do them once.

And it turns out we can just use a cartesian product:

for d in $desc
    printf '%s\t%s\n' $file $d
end

becomes

printf '%s\n' $file\t$desc
2023-02-06 21:49:07 +01:00
Mahmoud Al-Qudsi
0b160ebe71 Drop lazy_static from Cargo.toml
This should have been included as part of the previous commit, mea culpa.
2023-02-05 18:20:26 -06:00
Mahmoud Al-Qudsi
d7febd4f3e Use once_cell instead of lazy_static
lazy_static has better ergonomics at the call/access sites (it returns a
reference to the type directly, whereas with once_cell we get a static Lazy<T>
that we must dereference instead) but the once_cell api is slated for
integration into the standard library [0] and has been the "preferred" way to
declare static global variables w/ deferred initialization. It's also less
opaque and easier to comprehend how it works, I guess?

(Both `once_cell` and `lazy_static` are already in our dependency tree, so this
should have no detrimental effect on build times. It actually negligibly
*improves* build times by not using macros, reducing the amount of expansion the
compiler has to do by a miniscule amount.)

[0]: https://github.com/rust-lang/rust/issues/74465
2023-02-05 17:58:33 -06:00
Mahmoud Al-Qudsi
96deaae7d8 completions/apt: Read from the dpkg cache directly
I have no idea why `apt-cache --no-generate show` is so slow since it basically
dumps the contents of the cache file located at `/var/lib/dpkg/status`. We are
technically bypassing any waits on the cache lock file so this may produce
incorrect results if the cache is being regenerated in the moment, but that's a
small price to pay and the results are likely confined to simply not generating
comprehensive results.

With this change, we no longer need to truncate results to the first n matches
and we no longer only print packages beginning with the commandline argument
enabling fish's partial completions logic to offer less-perfect suggestions when
no better options are available.

Even though we are generating more usable completions, we still trounce the old
performance by leaps and bounds:

```
Benchmark #1: fish -c "complete -C\"apt install ac\""
  Time (mean ± σ):      2.165 s ±  0.033 s    [User: 267.0 ms, System: 1932.2 ms]
  Range (min … max):    2.136 s …  2.256 s    10 runs

Benchmark #2: build/fish -c "complete -C\"apt install ac\""
  Time (mean ± σ):     111.1 ms ±   1.8 ms    [User: 38.9 ms, System: 72.9 ms]
  Range (min … max):   108.2 ms … 114.9 ms    26 runs

Summary
  'build/fish -c "complete -C\"apt install ac\""' ran
   19.49 ± 0.44 times faster than 'fish -c "complete -C\"apt install ac\""'
```
2023-02-05 16:30:34 -06:00
Mahmoud Al-Qudsi
6f3711902b completions/apt: Use is_first_token instead of seen_subcommand_from
I think this should be preferred for all subcommand completions because it
handles typos or subcommands we don't recognize better (`apt foo <TAB>` no
longer suggests subcommands since the subcommand position has been taken).
2023-02-05 16:15:15 -06:00
Johannes Altmanninger
39c3faeaf4 gettext.rs: make trailing comma actually optional 2023-02-05 12:24:29 +01:00
Johannes Altmanninger
f167ec9063 clippy: silence manual_is_ascii_check
It's debatable whether is_ascii_digit() is better than (0..=9).contains().
(Probably we want to go with the mainstream Rust choice eventually.)
Let's disable the warning for now since it's not terribly important.
2023-02-05 12:24:29 +01:00
Johannes Altmanninger
c8bf2be408 wchar_ffi.rs: implement from_ffi() for more FFI strings 2023-02-05 12:22:42 +01:00
Johannes Altmanninger
dcca3cfe3c Prefer taking native Rust strings instead of wcharz_t
We should only be dealing with wcharz_t at the language boundary.
Rust callers should prefer the equivalent &wstr.
Since wcsfilecmp() is no longer exposed directly it can take &wstr only.
2023-02-05 12:22:42 +01:00
NextAlone
3604e8854b completion/adb: remove wait-for-device from subcommand detect
wait-for-device should not be used in subcommand detect, cause it is used as seperate command, following with others.
2023-02-05 12:13:45 +01:00
Branch Vincent
d69a290c2f completions: add pre-commit 2023-02-05 12:12:47 +01:00
Wout De Puysseleir
43a7c20ddb completions/mix: Add mix phx
- Added phx completions. These are very common completions for the Elixir Phoenix Framework.
  Documentation can be found here: https://hexdocs.pm/phoenix/1.7.0-rc.2/Mix.Tasks.Local.Phx.html#content
- Added argument completions
- Made all descriptions start with an uppercase for better consistency
- Update CHANGELOG.rst
2023-02-05 12:10:31 +01:00
Johannes Altmanninger
a446a16471 flog.rs: use qualified name in FLOG! macro
Otherwise this macro fails when used in a context that doesn't import
this name.
2023-02-05 12:02:48 +01:00
Johannes Altmanninger
7347c90d1e builtins.rs: correct error message on unknown option 2023-02-05 12:02:48 +01:00
Johannes Altmanninger
476b12e06a util.rs: simplify wcsfilecmp a bit further 2023-02-05 12:02:48 +01:00
Johannes Altmanninger
ba1c5d495f util.rs: fix Yoda condition 2023-02-05 12:02:48 +01:00
Xiretza
8460b37b6a rust: util: use Ordering instead of integers 2023-02-05 11:57:25 +01:00
Xiretza
8b483735b4 rust: fix doc comments 2023-02-05 11:57:25 +01:00
Xiretza
cee13531e3 rust: silence warnings on auto-generated FFI bindings 2023-02-05 11:57:25 +01:00
Xiretza
cba03fc1e8 rust: remove unnecessary newline 2023-02-05 11:57:25 +01:00
Xiretza
35083c72ef rust: silence some clippy warnings 2023-02-05 11:57:25 +01:00
Xiretza
853649f8dc rust: fix issues reported by clippy 2023-02-05 11:57:25 +01:00
ridiculousfish
c2df63f586 Remove an errant printf from fish_tests 2023-02-04 11:24:54 -07:00
Johannes Altmanninger
83fd7ea7c4 Port future_feature_flags.cpp to Rust
This is early work but I guess there's no harm in pushing it?
Some thoughts on the conventions:

Types that live only inside Rust follow Rust naming convention
("FeatureMetadata").

Types that live on both sides of the language boundary follow the existing
naming ("feature_flag_t").
The alternative is to define a type alias ("using feature_flag_t =
rust::FeatureFlag") but that doesn't seem to be supported in "[cxx::bridge]"
blocks. We could put it in a header ("future_feature_flags.h").

"feature_metadata_t" is a variant of "FeatureMetadata" that can cross
the language boundary. This has the advantage that we can avoid tainting
"FeatureMetadata" with "CxxString" and such. This is an experimental approach,
probably not what we should do in general.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
132d99a27b Call rust_init() in fish_indent too
The initial port of feature flags requires a global initialization. Since
fish_indent accesses feature flags, let's make sure to initialize them here.
In future, we can stop initializing things fish_indent doesn't need (like
the topic monitor) but that's no big deal. Global initialization should
always be a benign addition.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
517d53dc46 Port util.cpp to Rust
The original implementation without the test took me 3 hours (first time
seriously looking into this)

The functions take "wcharz_t" for smooth integration with existing C++ callers.
This is at the expense of Rust callers, which would prefer "&wstr".  Would be
nice to declare a function parameter that accepts both but I don't think
that really works since "wcharz_t" drops the lifetime annotation.
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
44d75409d0 build.rs: re-run autocxx if any ffi module changed
I'm not 100% sure this is the right thing but it seems to fix a scenario
where a change to a Rust module was not propagated by "make".
2023-02-03 18:55:06 +01:00
Johannes Altmanninger
a502cb16c3 ffi.rs: prevent rustfmt from breaking "use" statements
rustfmt removes the "::" prefix from qualifiers. This breaks the build because
I think a later "pub use ffi::*" results in "std" being an ambiguous reference.
2023-02-03 18:55:05 +01:00
Mahmoud Al-Qudsi
91be7489bc CI: Disable some Cirrus CI jobs during RIIR transition
We can re-enable these once we're nearing a RIIR release (or if someone thinks
it's a good use of their time to fix them before then). Otherwise we're just
going to have GitHub reporting CI failure for all commits instead of just the
ones that actually broke something.

(I'm mainly trying to get the branch in a good state to merge into master.)
2023-02-03 11:52:01 -06:00
Mahmoud Al-Qudsi
2dc2c8de3b Fix FreeBSD CI builds of rust-enabled codebase
Use rustup to install the latest version of rust. The latest version of rust
available from pkg is 1.66.0 while the code currently needs 1.67.0 or later.
2023-02-03 11:36:21 -06:00
Mahmoud Al-Qudsi
60bd186e21 Fix linking errors under FreeBSD
The nix crate had all its default features enabled, which included features that
are not present under BSD. We should only enable the select subset of crate
features that we know are available cross-platform (or else use conditional
targeting in Cargo.toml to only enable Linux-only features when compiling for
Linux targets).

For now, it seems we can just use the nix crate with all features disabled as it
still builds under Linux and FreeBSD in this state.
2023-02-03 11:36:21 -06:00
Mahmoud Al-Qudsi
c18fb74fa8 Fix rust-invoked build of c/cpp sources under FreeBSD
Due to an upstream issue with cc-rs [0], the rust-generated C++ interface would
fail to compile. A PR has been opened to patch the issue upstream [1], but in
the meantime `Cargo.toml` has been patched to use a fork of cc-rs with the
relevant fixes.

[0]: https://github.com/rust-lang/cc-rs/issues/463
[1]: https://github.com/rust-lang/cc-rs/pull/785
2023-02-03 11:36:21 -06:00
Mahmoud Al-Qudsi
538518cdf3 CI: Use the cmake-core package on FreeBSD
The `cmake` meta package pulls in `cmake-core`, `cmake-docs`, and `cmake-man` -
we don't need the latter two.

(It seems to be available on all the versions/architectures we target.)
2023-02-02 20:41:57 -06:00
Mahmoud Al-Qudsi
608f2bab31 CI: Use git-lite instead of git under FreeBSD
The git-lite flavor, being significantly smaller and downloading/installing much
faster with fewer dependencies, is much better suited for CI environments (at
the cost of not supporting interactive git commands).
2023-02-02 20:41:57 -06:00
Mahmoud Al-Qudsi
440dcb48c5 CI: Upgrade FreeBSD 13 to 13.1
By default /etc/pkg/FreeBSD.conf uses either the /quarterly or /latest pkg
builds, which are built against the latest minor release of FreeBSD for the
given ${ABI} string at the time they were last updated.

The nature of the shared binary packages means everyone (across all minor
versions of the same major version on the same architecture, all of which share
the same stable ABI) gets the same binary build.

There are however packages which depend on symbols exported by system-provided
libraries (rather than by other packages, which are always going to be in sync)
that *aren't* stable across minor releases, leaving packages like llvm
broken if you install the latest llvm from pkg's binary repos built against,
say, FreeBSD 13.1 while running FreeBSD 13.0.

The other option is to use the "snapshots" of the binary packages available upon
the release of each minor version, by using /release_0, /release_1, etc instead
of /quarterly or /latest, but then you're limited to the ports that were
available at that specific date and those old versions.

tl;dr just make sure we're always using the latest minor release for each major
version of FreeBSD we intend to support.
2023-02-02 20:41:57 -06:00
ridiculousfish
76adfed0e7 Implement builtin_wait in Rust
This implements builtin_wait in Rust.
2023-02-02 19:34:48 -07:00
ridiculousfish
f38543ccb7 Rename ast::job_t to ast::job_pipeline_t
This works around an autocxx limitations where different types cannot
have the same name even if they live in different namespace.

ast::job_t conflicts with job_t.
2023-02-02 19:34:48 -07:00
ridiculousfish
e674678ea4 Add a printf implementation
This allows using existing format strings.
The implementation is adapted from https://github.com/tjol/sprintf-rs
2023-02-02 19:34:48 -07:00
ridiculousfish
55f655f003 Add a gettext wrapper in Rust
This allows the wgettext! macro, which calls into C++.
2023-02-02 19:34:48 -07:00
ridiculousfish
681a165721 Add an FFI test facility
This allow testing Rust functions (from fish_tests.cpp) which need to
cross the FFI. See the example in smoke.rs.
2023-02-02 19:34:48 -07:00
ridiculousfish
096b254c4a Port fish_wcstoi to Rust
This adds an implementation of fish_wcstoi in Rust, mirroring the one in
fish. As Rust does not have a string to number which infers the radix
(i.e. looks for leading 0x or 0), we add that manually.
2023-02-02 19:34:48 -07:00
ridiculousfish
d843b67d2d Initial Rust commit 2023-02-02 19:34:47 -07:00
David Adam
fb3056d7a1 fish.spec: drop long-obsolete BuildRoot directive
Ignored since RPM 4.6.0, released in 2009!
2023-02-01 22:26:30 +08:00
LingMan
0af2a7a9b7 Upgrade GitHub action dessant/lock-threads to v4
In v3 several input parameters where renamed and since v4 it requires Node.js 16.

This resolves warnings about Node.js 12 and `set-output` being deprecated and
slated for removal in the `Lock threads` workflow.
2023-02-01 10:40:46 +08:00
Mahmoud Al-Qudsi
31f63b2f87 Upgrade GitHub CI actions/checkout to v3
This addresses the node v12 deprecation warning in the GitHub CI, caused by the
dependency on actions/checkout@v2.

While actions/checkout@v3 introduces some new features and changes some
defaults, the subset of features that we use should not be affected by this
migration.

The "breaking change" from v2 to v3 can be seen at [0]. Since we are tracking
only v2 without a dot release specified, we are already opting into any breakage
across minor versions, so really the only change of note is the node version
upgrade.

[0]: https://github.com/actions/checkout/compare/v2.4.2...v3.0.0
2023-01-31 11:50:57 -06:00
nat-418
cf67709931 feat: add support for fossil-scm in prompt (#9500)
* feat: add support for fossil-scm in prompt

* fix: change directory testing and string matching
2023-01-29 16:54:39 +01:00
Fabian Boehm
d239e26f6b docs: Add a missing newline
Sphinx is annoyingly specific here
2023-01-29 14:46:35 +01:00
Fabian Boehm
177ce0d40e __fish_make_completion_signals: Check for "kill" 2023-01-29 14:44:59 +01:00
Fabian Boehm
dd7d432cd6 Only define kill wrapper if we have a kill to wrap 2023-01-29 14:44:45 +01:00
David Adam
2a24295e50 debian packaging: add dependency on procps
See https://bugs.debian.org/1029940
2023-01-29 21:21:47 +08:00
Johannes Altmanninger
243ade838b completions/git: also complete filepaths as second argument to git grep
Fixes a regression in f81e8c7de (completions/git: complete refs for "git
grep", 2022-12-08).

Fixes #9513
2023-01-28 21:25:42 +01:00
Fabian Boehm
7f2cb47437 fish_key_reader: Don't translate things to "\v" and friends
This translated ctrl-k to "\v", which is a "vertical tab", and ctrl-l
to "\f" and ctrl-g to "\a".

There is no "vertical tab" or "alarm" or "\f" *key*, so these
shouldn't be translated. Just drop these and call them `\ck` and such.

(vertical tab specifically is utterly useless and I would be okay with
dropping it entirely, I have never seen it used anywhere)
2023-01-27 17:07:18 +01:00
Johannes Altmanninger
befa240756 completions/git: use builtin path for finding subcommands
This is more elegant and efficient. No functional change.

As suggested by 2da1a4ae7 (completions/git: Fix git-foo commands, 2023-01-09).
2023-01-24 20:37:38 +01:00
Johannes Altmanninger
f033b4df7d completions/git: fix typo 2023-01-24 20:37:38 +01:00
Johannes Altmanninger
7c1c3f9f77 completions/git: do not use user input as format string
Suggested by f5711ad5e (git.fish: collapse repeat complete cmds, set -f,
rm unneeded funcs, 2022-10-27).
2023-01-24 20:37:38 +01:00
Johannes Altmanninger
72e9d02650 Revert "git.fish: collapse repeat complete cmds, set -f, rm unneeded funcs"
That commit did way too many things, making it hard to see the 5 regressions
it introduced. Let's revert it and its stragglers. In future, we could redo
some of the changes.

Reverts changes to share/completions/git.fish from

- 3548aae55 (completions/git: Don't leak submodule subcommands, 2023-01-23)
- 905f788b3 (completions/git: Remove awkward newline symbol, 2023-01-10)
- 2da1a4ae7 (completions/git: Fix git-foo commands, 2023-01-09)
- e9bf8b9a4 (Run fish_indent on share/completions/*.fish, 2022-12-08)
- d31847b1d (Fix apparent dyslexia, 2022-11-12)
- 054d0ac0e (git completions: undo mistaken `set -f` usage, 2022-10-28)
- f5711ad5e (git.fish: collapse repeat complete cmds, set -f, rm unneeded funcs, 2022-10-27)
2023-01-24 20:37:38 +01:00
Johannes Altmanninger
04cae2c559 completions/kak: show -debug arguments
Technically this is a |-separated list, we might need to teach __fish_append
to tokenize.
2023-01-24 20:37:38 +01:00
Johannes Altmanninger
29a3344226 Make bracketed paste add only one undo entry
Bracketed paste adds one undo entry unless the pasted text contains a '
or \.  This is because the "paste" bind-mode has bindings for those keys,
so they effectively start a new undo entry.

Let's fix this by adding an explicit undo group (our first use of this
feature!).
2023-01-24 20:32:13 +01:00
Fabian Boehm
21f1eebd01 completions/git: Some rewordings
These are the longest subcommand descriptions, so it gives us more space
2023-01-23 21:18:03 +01:00
Fabian Boehm
3548aae552 completions/git: Don't leak submodule subcommands
Introduced in f5711ad5ed through an unclean edit.
2023-01-23 21:17:53 +01:00
Fabian Boehm
bd871c5372 Fix last PCRE2_UCHAR32
See #9502
2023-01-23 20:03:29 +01:00
Johannes Altmanninger
d055726ed7 CHANGELOG: fuzzy matching in history-pager 2023-01-22 16:14:14 +01:00
Johannes Altmanninger
610d19cec1 CHANGELOG: don't mention the overly-specific terraform fix 2023-01-22 16:14:00 +01:00
Eddie Lebow
00692bcdfe Include subsequence matches in history-pager
If a `contains` search yields no results, try again with `contains_subsequence`.
2023-01-22 16:11:46 +01:00
1573 changed files with 672005 additions and 809101 deletions

View File

@@ -1,25 +1,26 @@
image: alpine/edge
packages:
- cargo
- cmake
- ninja
- ncurses-dev
- pcre2-dev
- py3-pexpect
- python3
- py-pip
- rust
- tmux
sources:
- https://git.sr.ht/~faho/fish
- https://github.com/fish-shell/fish-shell
tasks:
- build: |
pip3 install pexpect
cd fish
mkdir build || :
cd fish-shell
mkdir build
cd build
cmake -G Ninja .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_DATADIR=share \
-DCMAKE_INSTALL_DOCDIR=share/doc/fish \
-DCMAKE_INSTALL_SYSCONFDIR=/etc
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_DATADIR=share \
-DCMAKE_INSTALL_DOCDIR=share/doc/fish \
-DCMAKE_INSTALL_SYSCONFDIR=/etc
ninja
- test: |
cd fish/build
env ninja test
cd fish-shell/build
ninja fish_run_tests

View File

@@ -4,6 +4,7 @@ packages:
- ninja
- python
- python-pexpect
- tmux
sources:
- https://git.sr.ht/~faho/fish
tasks:
@@ -19,4 +20,4 @@ tasks:
ninja
- test: |
cd fish/build
env ninja test
ninja fish_run_tests

View File

@@ -1,26 +1,29 @@
image: freebsd/latest
packages:
- ncurses
- cmake
- gcc
- gettext
- cmake
- gmake
- llvm
- ninja
- pcre2
- py311-pexpect
- python
- py38-pexpect
- rust
- tmux
sources:
- https://git.sr.ht/~faho/fish
- https://github.com/fish-shell/fish-shell
tasks:
- build: |
cd fish
mkdir build || :
cd fish-shell
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_DATADIR=share \
-DCMAKE_INSTALL_DOCDIR=share/doc/fish \
-DCMAKE_INSTALL_SYSCONFDIR=/etc
gmake -j2
cmake -GNinja .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_DATADIR=share \
-DCMAKE_INSTALL_DOCDIR=share/doc/fish \
-DCMAKE_INSTALL_SYSCONFDIR=/etc
ninja
- test: |
cd fish/build
gmake test
cd fish-shell/build
ninja fish_run_tests

29
.builds/openbsd.yml Normal file
View File

@@ -0,0 +1,29 @@
image: openbsd/latest
packages:
- cmake
- gcc
- gettext
- gmake
- llvm
- ninja
- pcre2
- py311-pexpect
- python
- rust
- tmux
sources:
- https://github.com/fish-shell/fish-shell
tasks:
- build: |
cd fish-shell
mkdir build
cd build
cmake -GNinja .. \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_INSTALL_DATADIR=share \
-DCMAKE_INSTALL_DOCDIR=share/doc/fish \
-DCMAKE_INSTALL_SYSCONFDIR=/etc
ninja
- test: |
cd fish-shell/build
ninja fish_run_tests

8
.cargo/config.toml Normal file
View File

@@ -0,0 +1,8 @@
# This file is _not_ included in the tarballs for now
# Binary builds on Linux packaging infrastructure need to overwrite it to make `cargo vendor` work
# Releases and development builds made using OBS/Launchpad will _not_ reflect the contents of this
# file
[resolver]
# Make cargo 1.84+ respect MSRV (rust-version in Cargo.toml)
incompatible-rust-versions = "fallback"

View File

@@ -1,5 +1,7 @@
skip: $CIRRUS_REPO_OWNER == 'fish-shell' && $CIRRUS_BRANCH == 'master'
env:
CIRRUS_CLONE_DEPTH: 1
CIRRUS_CLONE_DEPTH: 100
CI: 1
linux_task:
@@ -8,29 +10,19 @@ linux_task:
container: &step
image: ghcr.io/fish-shell/fish-ci/alpine:latest
memory: 4GB
- name: centos7
- name: jammy
container:
<<: *step
image: ghcr.io/fish-shell/fish-ci/centos7:latest
- name: centos8
container:
<<: *step
image: ghcr.io/fish-shell/fish-ci/centos8:latest
- name: focal-32bit
container:
<<: *step
image: ghcr.io/fish-shell/fish-ci/focal-32bit:latest
image: ghcr.io/fish-shell/fish-ci/jammy:latest
tests_script:
# cirrus at times gives us 32 procs and 2 GB of RAM
# Unrestriced parallelism results in OOM
- lscpu || true
- (cat /proc/meminfo | grep MemTotal) || true
- mkdir build && cd build
- cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCTEST_PARALLEL_LEVEL=6 ..
- ninja -j 6 fish fish_tests
- FISH_TEST_MAX_CONCURRENCY=6 cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
- ninja -j 6 fish
- ninja fish_run_tests
only_if: $CIRRUS_REPO_OWNER == 'fish-shell'
linux_arm_task:
@@ -38,28 +30,26 @@ linux_arm_task:
- name: focal-arm64
arm_container:
image: ghcr.io/fish-shell/fish-ci/focal-arm64
only_if: $CIRRUS_REPO_OWNER == 'fish-shell'
tests_script:
# cirrus at times gives us 32 procs and 2 GB of RAM
# Unrestriced parallelism results in OOM
- lscpu || true
- (cat /proc/meminfo | grep MemTotal) || true
- mkdir build && cd build
- cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCTEST_PARALLEL_LEVEL=6 ..
- ninja -j 6 fish fish_tests
- file ./fish
- FISH_TEST_MAX_CONCURRENCY=6 cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
- ninja -j 6 fish
- ninja fish_run_tests
only_if: $CIRRUS_REPO_OWNER == 'fish-shell'
freebsd_task:
matrix:
- name: FreeBSD 13
- name: FreeBSD 14
freebsd_instance:
image: freebsd-13-2-release-amd64
image: freebsd-14-3-release-amd64-ufs
tests_script:
- pkg install -y cmake devel/pcre2 devel/ninja misc/py-pexpect git
- pkg install -y cmake-core devel/pcre2 devel/ninja gettext git-lite lang/rust misc/py-pexpect
# libclang.so is a required build dependency for rust-c++ ffi bridge
- pkg install -y llvm
# BSDs have the following behavior: root may open or access files even if
# the mode bits would otherwise disallow it. For example root may open()
# a file with write privileges even if the file has mode 400. This breaks
@@ -70,8 +60,7 @@ freebsd_task:
- mkdir build && cd build
- chown -R fish-user ..
- sudo -u fish-user -s whoami
- sudo -u fish-user -s cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCTEST_PARALLEL_LEVEL=1 ..
- sudo -u fish-user -s ninja -j 6 fish fish_tests
- sudo -u fish-user -s FISH_TEST_MAX_CONCURRENCY=1 cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
- sudo -u fish-user -s ninja -j 6 fish
- sudo -u fish-user -s ninja fish_run_tests
only_if: $CIRRUS_REPO_OWNER == 'fish-shell'

View File

@@ -6,11 +6,3 @@
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 4
# Place config.h first always.
IncludeCategories:
- Regex: '^"config.h"'
Priority: -1
# We don't want OCLint pragmas to be reformatted.
CommentPragmas: '^!OCLINT'

View File

@@ -1,17 +0,0 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-valist.Uninitialized,cert-*,performance-*,portability-*,-modernize-use-auto,modernize-loop-convert,modernize-use-bool-literals,modernize-use-using,hicpp-uppercase-literal-suffix,readability-make-member-function-const,readability-redundant-string-init,readability-inconsistent-declaration-parameter-name,readability-redundant-access-specifiers,-performance-noexcept-move-constructor,-cert-dcl21-cpp,-cert-dcl37-c,-cert-dcl50-cpp,-cert-dcl51-cpp,-cert-str34-c,-cert-env33-c,misc-static-assert,readability-use-anyofallof,readability-simplify-*,readability-redundant-*,modernize-redundant-void-arg,modernize-make-shared,modernize-make-unique,modernize-loop-convert,'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: File
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: modernize-loop-convert.MinConfidence
value: 'risky'
- key: modernize-use-auto.RemoveStars
value: '1'
...

View File

@@ -13,16 +13,20 @@ max_line_length = 100
indent_style = tab
[*.{md,rst}]
max_line_length = unset
trim_trailing_whitespace = false
[*.{sh,ac}]
indent_size = 2
[*.sh]
indent_size = 4
[build_tools/release.sh]
max_line_length = 72
[Dockerfile]
indent_size = 2
[share/{completions,functions}/**.fish]
max_line_length = none
max_line_length = unset
[{COMMIT_EDITMSG,git-revise-todo}]
max_line_length = 80
[{COMMIT_EDITMSG,git-revise-todo,*.jjdescription}]
max_line_length = 72

19
.gitattributes vendored
View File

@@ -1,13 +1,12 @@
# normalize newlines
* text=auto
*.fish text
*.bat eol=crlf
* text=auto eol=lf
# let git show off diff hunk headers, help git diff -L:
# https://git-scm.com/docs/gitattributes
*.cpp diff=cpp
*.c diff=cpp
*.h diff=cpp
*.py diff=py
*.rs diff=rust
# add a [diff "fish"] to git config with pattern
*.fish diff=fish
@@ -21,13 +20,13 @@
/.github/* export-ignore
/.builds export-ignore
/.builds/* export-ignore
# to make cargo vendor work correctly
/.cargo/ export-ignore
/.cargo/config.toml export-ignore
# for linguist; let github identify our project as C++ instead of C due to pcre2
pcre2/** linguist-vendored
angular.js linguist-vendored
angular-*.js linguist-vendored
# for linguist, which drives GitHub's language statistics
alpine.js linguist-vendored
doc_src/** linguist-documentation
*.fish linguist-language=fish
src/*.h linguist-language=c++
src/builtins/*.h linguist-language=c++
# see 70f2899fcd which attempts to "rig the count"
share/completions/*.fish linguist-documentation

View File

@@ -1,14 +1,22 @@
---
name: "Bug Report"
about: "Simple template for bug reports"
title: ""
labels: []
assignees: []
---
<!--
Please tell us which fish version you are using by executing the following:
fish --version
echo $version
Please tell us which operating system and terminal you are using. The output of `uname -a` and `echo $TERM` may be helpful in this regard although other commands might be relevant in your specific situation.
Please tell us which operating system (output of `uname`) and terminal you are using.
Please tell us if you tried fish without third-party customizations by executing this command and whether it affected the behavior you are reporting:
sh -c 'env HOME=$(mktemp -d) fish'
sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= XDG_DATA_DIRS= fish'
Tell us how to reproduce the problem. Including an asciinema.org recording is useful for problems that involve the visual display of fish output such as its prompt.
-->

View File

@@ -8,4 +8,4 @@ Fixes issue #
<!-- Just check off what what we know been done so far. We can help you with this stuff. -->
- [ ] Changes to fish usage are reflected in user documentation/manpages.
- [ ] Tests have been added for regressions fixed
- [ ] User-visible changes noted in CHANGELOG.rst
- [ ] User-visible changes noted in CHANGELOG.rst <!-- Don't document changes for completions inside CHANGELOG.rst, there are lot of such edits -->

View File

@@ -0,0 +1,43 @@
name: Install dependencies for system tests
inputs:
include_sphinx:
description: Whether to install Sphinx
required: true
default: false
include_pcre:
description: Whether to install the PCRE library
required: false
default: true
permissions:
contents: read
runs:
using: "composite"
steps:
- shell: bash
env:
include_sphinx: ${{ inputs.include_sphinx }}
include_pcre: ${{ inputs.include_pcre }}
run: |
set -x
: "optional dependencies"
sudo apt install \
gettext \
$(if $include_pcre; then echo libpcre2-dev; fi) \
$(if $include_sphinx; then echo python3-sphinx; fi) \
;
: "system test dependencies"
sudo apt install \
diffutils $(: "for diff") \
git \
gettext \
less \
$(if ${{ inputs.include_pcre }}; then echo libpcre2-dev; fi) \
python3-pexpect \
tmux \
wget \
;
- uses: ./.github/actions/install-sphinx-markdown-builder
if: ${{ inputs.include_sphinx == 'true' }}

View File

@@ -0,0 +1,14 @@
name: Install sphinx-markdown-builder
permissions:
contents: read
runs:
using: "composite"
steps:
- shell: bash
run: |
set -x
commit=b259de1dc97573a71470a1d71c3d83535934136b
pip install git+https://github.com/krobelus/sphinx-markdown-builder@"$commit"
python -c 'import sphinx_markdown_builder'

View File

@@ -0,0 +1,41 @@
name: Rust Toolchain
inputs:
toolchain_channel:
description: Either "stable" or "msrv"
required: true
targets:
description: Comma-separated list of target triples to install for this toolchain
required: false
components:
description: Comma-separated list of components to be additionally installed
required: false
permissions:
contents: read
runs:
using: "composite"
steps:
- name: Set toolchain
env:
toolchain_channel: ${{ inputs.toolchain_channel }}
shell: bash
run: |
set -x
toolchain=$(
case "$toolchain_channel" in
(stable) echo 1.90 ;;
(msrv) echo 1.70 ;;
(*)
printf >&2 "error: unsupported toolchain channel %s" "$toolchain_channel"
exit 1
;;
esac
)
printf 'TOOLCHAIN=%s\n' "$toolchain" >>"$GITHUB_ENV"
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.TOOLCHAIN }}
targets: ${{ inputs.targets }}
components: ${{ inputs.components }}

View File

@@ -0,0 +1,21 @@
name: Oldest Supported Rust Toolchain
inputs:
targets:
description: Comma-separated list of target triples to install for this toolchain
required: false
components:
description: Comma-separated list of components to be additionally installed
required: false
permissions:
contents: read
runs:
using: "composite"
steps:
- uses: ./.github/actions/rust-toolchain
with:
toolchain_channel: "msrv"
targets: ${{ inputs.targets }}
components: ${{ inputs.components }}

View File

@@ -0,0 +1,21 @@
name: Stable Rust Toolchain
inputs:
targets:
description: Comma-separated list of target triples to install for this toolchain
required: false
components:
description: Comma-separated list of components to be additionally installed
required: false
permissions:
contents: read
runs:
using: "composite"
steps:
- uses: ./.github/actions/rust-toolchain
with:
toolchain_channel: "stable"
targets: ${{ inputs.targets }}
components: ${{ inputs.components }}

40
.github/workflows/autolabel_prs.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: Auto-Label PRs
on:
pull_request_target:
types: [opened, synchronize]
jobs:
label-and-milestone:
runs-on: ubuntu-latest
steps:
- name: Set label and milestone
id: set-label-milestone
uses: actions/github-script@v7
with:
script: |
const completionsLabel = 'completions';
// Get changed files in the pull request
const prNumber = context.payload.pull_request.number;
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
// Check if any file matches /share/completions/*.fish and no change is outside of /share/
const completionsRegex = new RegExp('^share/completions/.*\.fish');
const isCompletions = files.some(file => completionsRegex.test(file.filename))
&& files.every(file => file.filename.startsWith('share/'));
if (isCompletions) {
// Add label to PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [completionsLabel],
});
console.log(`PR ${prNumber} assigned label "${completionsLabel}"`);
}

View File

@@ -0,0 +1,126 @@
name: Build Docker test images
on:
push:
branches:
- master
workflow_dispatch:
concurrency:
group: docker-builds
env:
REGISTRY: ghcr.io
NAMESPACE: fish-ci
ONLY_FOR_REPO_OWNER: fish-shell
jobs:
check-docker-changes:
if: github.repository_owner == env.ONLY_FOR_REPO_OWNER
runs-on: ubuntu-latest
outputs:
docker-changed: ${{ steps.changes.outputs.docker }}
steps:
- uses: actions/checkout@v5
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
docker:
- 'docker/**'
docker-build:
needs: check-docker-changes
if: github.repository_owner == env.ONLY_FOR_REPO_OWNER && needs.check-docker-changes.outputs.docker-changed == 'true'
permissions:
contents: read
packages: write
attestations: write
id-token: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: alpine
- os: ubuntu-latest
target: centos9
- os: ubuntu-latest
target: fedora
- os: ubuntu-latest
target: focal-32bit
- os: ubuntu-24.04-arm
target: focal-arm64
- os: ubuntu-latest
target: focal
- os: ubuntu-24.04-arm
target: jammy-armv7-32bit
- os: ubuntu-latest
target: jammy-asan
- os: ubuntu-latest
target: jammy-tsan
- os: ubuntu-latest
target: jammy
- os: ubuntu-latest
target: noble
- os: ubuntu-latest
target: opensuse-tumbleweed
runs-on: ${{ matrix.os }}
steps:
-
name: Checkout
uses: actions/checkout@v5
-
name: Login to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.NAMESPACE }}/${{ matrix.target }}
flavor: |
latest=true
-
name: Build and push
uses: docker/build-push-action@v6
with:
context: docker/context
push: true
file: docker/${{ matrix.target }}.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
trigger-cirrus:
needs: [check-docker-changes, docker-build]
if: always() && github.repository_owner == env.ONLY_FOR_REPO_OWNER
runs-on: ubuntu-latest
steps:
- name: Trigger Cirrus CI
env:
CIRRUS_TOKEN: ${{ secrets.CIRRUS_TOKEN }}
run: |
set -x
# N.B. push-triggered workflows are usually from master.
branch=${{ github.ref_name }}
repository_id=${{ github.repository_id }}
curl -X POST \
-H "Authorization: Bearer $CIRRUS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "mutation {
createBuild(input: {
repositoryId: \"$repository_id\",
branch: \"$branch\"
})
{ build { id } }
}"
}' \
https://api.cirrus-ci.com/graphql

59
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,59 @@
name: Lint
on: [push, pull_request]
permissions:
contents: read
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/rust-toolchain@stable
with:
components: rustfmt
- name: install dependencies
run: pip install ruff
- name: build fish
run: cargo build
- name: check format
run: PATH="target/debug:$PATH" build_tools/style.fish --all --check
clippy:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rust_version: "stable"
features: ""
- rust_version: "stable"
features: "--no-default-features"
- rust_version: "msrv"
features: ""
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/rust-toolchain
with:
toolchain_channel: ${{ matrix.rust_version }}
components: clippy
- name: Install deps
run: |
sudo apt install gettext
- name: cargo clippy
run: cargo clippy --workspace --all-targets ${{ matrix.features }} -- --deny=warnings
rustdoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/rust-toolchain@stable
- name: Install deps
run: |
sudo apt install gettext
- name: cargo doc
run: |
RUSTDOCFLAGS='-D warnings' cargo doc --workspace
- name: cargo doctest
run: |
cargo test --doc --workspace

View File

@@ -12,14 +12,15 @@ permissions:
jobs:
lock:
if: github.repository_owner == 'fish-shell'
permissions:
issues: write # for dessant/lock-threads to lock issues
pull-requests: write # for dessant/lock-threads to lock PRs
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
- uses: dessant/lock-threads@v4
with:
github-token: ${{ github.token }}
issue-lock-inactive-days: '365'
pr-lock-inactive-days: '365'
issue-exclude-labels: 'question, needs more info'
issue-inactive-days: '365'
pr-inactive-days: '365'
exclude-any-issue-labels: 'question, needs more info'

View File

@@ -1,143 +0,0 @@
name: make test
on: [push, pull_request]
env:
CTEST_PARALLEL_LEVEL: "1"
CMAKE_BUILD_PARALLEL_LEVEL: "4"
permissions:
contents: read
jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install deps
run: |
sudo apt install gettext libncurses5-dev libpcre2-dev python3-pip tmux
sudo pip3 install pexpect
# Generate a locale that uses a comma as decimal separator.
sudo locale-gen fr_FR.UTF-8
- name: cmake
env:
# Some warnings upgraded to errors to match Open Build Service platforms
CXXFLAGS: "-Werror=address -Werror=return-type"
run: |
mkdir build && cd build
cmake ..
- name: make
run: |
make
- name: make test
run: |
make test
ubuntu-32bit-fetched-pcre2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install deps
run: |
sudo apt update
sudo apt install gettext lib32ncurses5-dev python3-pip g++-multilib tmux
sudo pip3 install pexpect
- name: cmake
env:
CXXFLAGS: "-m32 -Werror=address -Werror=return-type"
CFLAGS: "-m32"
run: |
mkdir build && cd build
cmake -DFISH_USE_SYSTEM_PCRE2=OFF ..
- name: make
run: |
make
- name: make test
run: |
make test
ubuntu-asan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install deps
run: |
sudo apt install gettext libncurses5-dev libpcre2-dev python3-pip tmux
sudo pip3 install pexpect
- name: cmake
env:
CC: clang
CXX: clang++
CXXFLAGS: "-fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address -DFISH_CI_SAN"
run: |
mkdir build && cd build
cmake ..
- name: make
run: |
make
- name: make test
env:
FISH_CI_SAN: 1
ASAN_OPTIONS: check_initialization_order=1:detect_stack_use_after_return=1:detect_leaks=1
UBSAN_OPTIONS: print_stacktrace=1:report_error_type=1
# use_tls=0 is a workaround for LSAN crashing with "Tracer caught signal 11" (SIGSEGV),
# which seems to be an issue with TLS support in newer glibc versions under virtualized
# environments. Follow https://github.com/google/sanitizers/issues/1342 and
# https://github.com/google/sanitizers/issues/1409 to track this issue.
LSAN_OPTIONS: verbosity=0:log_threads=0:use_tls=0
run: |
make test
ubuntu-threadsan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install deps
run: |
sudo apt install gettext libncurses5-dev libpcre2-dev python3-pip tmux
sudo pip3 install pexpect
- name: cmake
env:
FISH_CI_SAN: 1
CC: clang
CXX: clang++
CXXFLAGS: "-fsanitize=thread"
run: |
mkdir build && cd build
cmake ..
- name: make
run: |
make
- name: make test
run: |
make test
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Install deps
run: |
sudo pip3 install pexpect
brew install tmux
- name: cmake
run: |
mkdir build && cd build
cmake -DWITH_GETTEXT=NO ..
- name: make
run: |
make
- name: make test
run: |
make test

191
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,191 @@
name: Create a new release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (tag name)'
required: true
type: string
permissions:
contents: write
jobs:
is-release-tag:
name: Pre-release checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Workaround for https://github.com/actions/checkout/issues/882
ref: ${{ inputs.version }}
- name: Check if the pushed tag looks like a release
run: |
set -x
commit_subject=$(git log -1 --format=%s)
tag=$(git describe)
[ "$commit_subject" = "Release $tag" ]
source-tarball:
needs: [is-release-tag]
name: Create the source tarball
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tarball-name: ${{ steps.version.outputs.tarball-name }}
steps:
- uses: actions/checkout@v4
with:
# Workaround for https://github.com/actions/checkout/issues/882
ref: ${{ inputs.version }}
- name: Install dependencies
run: sudo apt install cmake gettext ninja-build python3-pip python3-sphinx
- uses: ./.github/actions/install-sphinx-markdown-builder
- name: Create tarball
run: |
set -x
mkdir /tmp/fish-built
FISH_ARTEFACT_PATH=/tmp/fish-built ./build_tools/make_tarball.sh
relnotes=/tmp/fish-built/release-notes.md
# Need history since the last release (i.e. tag) for stats.
git fetch --tags
git fetch --unshallow
sh -x ./build_tools/release-notes.sh >"$relnotes"
# Delete title
sed -n 1p "$relnotes" | grep -q "^## fish .*"
sed -n 2p "$relnotes" | grep -q '^$'
sed -i 1,2d "$relnotes"
- name: Upload tarball artifact
uses: actions/upload-artifact@v4
with:
name: source-tarball
path: |
/tmp/fish-built/fish-${{ inputs.version }}.tar.xz
/tmp/fish-built/release-notes.md
if-no-files-found: error
packages-for-linux:
needs: [is-release-tag]
name: Build single-file fish for Linux (experimental)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Workaround for https://github.com/actions/checkout/issues/882
ref: ${{ inputs.version }}
- name: Install Rust Stable
uses: ./.github/actions/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl,aarch64-unknown-linux-musl
- name: Install dependencies
run: sudo apt install crossbuild-essential-arm64 gettext musl-tools python3-sphinx
- name: Build statically-linked executables
run: |
set -x
cargo build --release --target x86_64-unknown-linux-musl --bin fish
CFLAGS="-D_FORTIFY_SOURCE=2" \
CC=aarch64-linux-gnu-gcc \
RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc -C link-arg=-lgcc -C link-arg=-D_FORTIFY_SOURCE=0" \
cargo build --release --target aarch64-unknown-linux-musl --bin fish
- name: Compress
run: |
set -x
for arch in x86_64 aarch64; do
tar -cazf fish-$(git describe)-linux-$arch.tar.xz \
-C target/$arch-unknown-linux-musl/release fish
done
- uses: actions/upload-artifact@v4
with:
name: Static builds for Linux
path: fish-${{ inputs.version }}-linux-*.tar.xz
if-no-files-found: error
create-draft-release:
needs:
- is-release-tag
- source-tarball
- packages-for-linux
name: Create release draft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Workaround for https://github.com/actions/checkout/issues/882
ref: ${{ inputs.version }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: /tmp/artifacts
- name: List artifacts
run: find /tmp/artifacts -type f
- name: Create draft release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.version }}
name: fish ${{ inputs.version }}
body_path: /tmp/artifacts/release-notes.md
draft: true
files: |
/tmp/artifacts/fish-${{ inputs.version }}.tar.xz
/tmp/artifacts/fish-${{ inputs.version }}-linux-*.tar.xz
packages-for-macos:
needs: [is-release-tag, create-draft-release]
name: Build packages for macOS
runs-on: macos-latest
environment: macos-codesign
steps:
- uses: actions/checkout@v4
with:
# Workaround for https://github.com/actions/checkout/issues/882
ref: ${{ inputs.version }}
- name: Install Rust
uses: ./.github/actions/rust-toolchain@oldest-supported
with:
targets: x86_64-apple-darwin
- name: Install Rust Stable
uses: ./.github/actions/rust-toolchain@stable
with:
targets: aarch64-apple-darwin
- name: Install dependencies
run: brew install gettext
- name: Build and codesign
run: |
die() { echo >&2 "$*"; exit 1; }
[ -n "$MAC_CODESIGN_APP_P12_BASE64" ] || die "Missing MAC_CODESIGN_APP_P12_BASE64"
[ -n "$MAC_CODESIGN_INSTALLER_P12_BASE64" ] || die "Missing MAC_CODESIGN_INSTALLER_P12_BASE64"
[ -n "$MAC_CODESIGN_PASSWORD" ] || die "Missing MAC_CODESIGN_PASSWORD"
[ -n "$MACOS_NOTARIZE_JSON" ] || die "Missing MACOS_NOTARIZE_JSON"
set -x
export FISH_ARTEFACT_PATH=/tmp/fish-built
# macOS runners keep having issues loading Cargo.toml dependencies from git (GitHub) instead
# of crates.io, so give this a try. It's also sometimes significantly faster on all platforms.
export CARGO_NET_GIT_FETCH_WITH_CLI=true
cargo install apple-codesign
mkdir -p "$FISH_ARTEFACT_PATH"
echo "$MAC_CODESIGN_APP_P12_BASE64" | base64 --decode >/tmp/app.p12
echo "$MAC_CODESIGN_INSTALLER_P12_BASE64" | base64 --decode >/tmp/installer.p12
echo "$MACOS_NOTARIZE_JSON" >/tmp/notarize.json
./build_tools/make_macos_pkg.sh -s -f /tmp/app.p12 \
-i /tmp/installer.p12 -p "$MAC_CODESIGN_PASSWORD" \
-n -j /tmp/notarize.json
version=$(git describe)
[ -f "${FISH_ARTEFACT_PATH}/fish-$version.app.zip" ]
[ -f "${FISH_ARTEFACT_PATH}/fish-$version.pkg" ]
rm /tmp/installer.p12 /tmp/app.p12 /tmp/notarize.json
env:
MAC_CODESIGN_APP_P12_BASE64: ${{ secrets.MAC_CODESIGN_APP_P12_BASE64 }}
MAC_CODESIGN_INSTALLER_P12_BASE64: ${{ secrets.MAC_CODESIGN_INSTALLER_P12_BASE64 }}
MAC_CODESIGN_PASSWORD: ${{ secrets.MAC_CODESIGN_PASSWORD }}
MACOS_NOTARIZE_JSON: ${{ secrets.MACOS_NOTARIZE_JSON }}
- name: Add macOS packages to the release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version=$(git describe)
gh release upload $version \
/tmp/fish-built/fish-$version.app.zip \
/tmp/fish-built/fish-$version.pkg

173
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,173 @@
name: Test
on: [push, pull_request]
env:
FISH_TEST_MAX_CONCURRENCY: "4"
CMAKE_BUILD_PARALLEL_LEVEL: "4"
permissions:
contents: read
jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/rust-toolchain@oldest-supported
- name: Install deps
uses: ./.github/actions/install-dependencies
with:
include_sphinx: true
- name: Generate a locale that uses a comma as decimal separator.
run: |
sudo locale-gen fr_FR.UTF-8
- name: cmake
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
- name: make
run: |
make -C build VERBOSE=1
- name: make fish_run_tests
run: |
make -C build VERBOSE=1 fish_run_tests
- name: translation updates
run: |
# Generate PO files. This should not result it a change in the repo if all translations are
# up to date.
# Ensure that fish is available as an executable.
PATH="$PWD/build:$PATH" build_tools/update_translations.fish
# Show diff output. Fail if there is any.
git --no-pager diff --exit-code || { echo 'There are uncommitted changes after regenerating the gettext PO files. Make sure to update them via `build_tools/update_translations.fish` after changing source files.'; exit 1; }
ubuntu-32bit-static-pcre2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/rust-toolchain@oldest-supported
with:
targets: "i586-unknown-linux-gnu"
- name: Install deps
uses: ./.github/actions/install-dependencies
with:
include_pcre: false
include_sphinx: false
- name: Install g++-multilib
run: |
sudo apt install g++-multilib
- name: cmake
env:
CFLAGS: "-m32"
run: |
mkdir build && cd build
cmake -DFISH_USE_SYSTEM_PCRE2=OFF -DRust_CARGO_TARGET=i586-unknown-linux-gnu ..
- name: make
run: |
make -C build VERBOSE=1
- name: make fish_run_tests
run: |
make -C build VERBOSE=1 fish_run_tests
ubuntu-asan:
runs-on: ubuntu-latest
env:
# Rust has two different memory sanitizers of interest; they can't be used at the same time:
# * AddressSanitizer detects out-of-bound access, use-after-free, use-after-return,
# use-after-scope, double-free, invalid-free, and memory leaks.
# * MemorySanitizer detects uninitialized reads.
#
RUSTFLAGS: "-Zsanitizer=address"
# RUSTFLAGS: "-Zsanitizer=memory -Zsanitizer-memory-track-origins"
steps:
- uses: actions/checkout@v4
# All -Z options require running nightly
- uses: dtolnay/rust-toolchain@nightly
with:
# ASAN uses `cargo build -Zbuild-std` which requires the rust-src component
# this is comma-separated
components: rust-src
- name: Install deps
uses: ./.github/actions/install-dependencies
with:
include_sphinx: false
- name: Install llvm
run: |
sudo apt install llvm # for llvm-symbolizer
- name: cmake
env:
CC: clang
run: |
mkdir build && cd build
# Rust's ASAN requires the build system to explicitly pass a --target triple. We read that
# value from CMake variable Rust_CARGO_TARGET.
cmake .. -DASAN=1 -DRust_CARGO_TARGET=x86_64-unknown-linux-gnu -DCMAKE_BUILD_TYPE=Debug
- name: make
run: |
make -C build VERBOSE=1
- name: make fish_run_tests
env:
FISH_CI_SAN: 1
ASAN_OPTIONS: check_initialization_order=1:detect_stack_use_after_return=1:detect_leaks=1:fast_unwind_on_malloc=0
# use_tls=0 is a workaround for LSAN crashing with "Tracer caught signal 11" (SIGSEGV),
# which seems to be an issue with TLS support in newer glibc versions under virtualized
# environments. Follow https://github.com/google/sanitizers/issues/1342 and
# https://github.com/google/sanitizers/issues/1409 to track this issue.
# UPDATE: this can cause spurious leak reports for __cxa_thread_atexit_impl() under glibc.
LSAN_OPTIONS: verbosity=0:log_threads=0:use_tls=1:print_suppressions=0
run: |
set -x
export ASAN_SYMBOLIZER_PATH=$(command -v /usr/bin/llvm-symbolizer* | sort -n | head -1)
export LSAN_OPTIONS="$LSAN_OPTIONS:suppressions=$PWD/build_tools/lsan_suppressions.txt"
make -C build VERBOSE=1 fish_run_tests
macos:
runs-on: macos-latest
env:
# macOS runners keep having issues loading Cargo.toml dependencies from git (GitHub) instead
# of crates.io, so give this a try. It's also sometimes significantly faster on all platforms.
CARGO_NET_GIT_FETCH_WITH_CLI: true
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/rust-toolchain@oldest-supported
- name: Install deps
run: |
# --break-system-packages because homebrew has now declared itself "externally managed".
# this is CI so we don't actually care.
sudo pip3 install --break-system-packages pexpect
brew install gettext tmux
- name: cmake
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
- name: make
run: |
make -C build VERBOSE=1
- name: make fish_run_tests
run: |
make -C build VERBOSE=1 fish_run_tests
windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
update: true
msystem: MSYS
- name: Install deps
# Not using setup-msys2 `install` option to make it easier to copy/paste
run: |
pacman --noconfirm -S --needed git rust
- name: cargo build
run: |
cargo build
- name: smoketest
# We can't use `cargo test` yet, there are just too many failures
# so this is just a quick check to make sure that fish can swim
run: |
set -x
[ "$(target/debug/fish.exe -c 'echo (math 1 + 1)')" = 2 ]

21
.gitignore vendored
View File

@@ -38,7 +38,6 @@ Desktop.ini
Thumbs.db
ehthumbs.db
messages.pot
.directory
.fuse_hidden*
@@ -77,6 +76,7 @@ __pycache__
/share/__fish_build_paths.fish
/share/pkgconfig
/tests/*.tmp.*
/tests/.last-check-all-files
# xcode
## Build generated
@@ -89,3 +89,22 @@ __pycache__
/tags
xcuserdata/
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Generated by clangd
/.cache
# JetBrains editors.
.idea/
# AI slop
.claude/

95
.oclint
View File

@@ -1,95 +0,0 @@
rules:
rule-configurations:
#
# This is the default value (as of the time I wrote this) but I'm making
# it explicit since it needs to agree with the value used by clang-format.
# Thus, if we ever change the fish style to allow longer or shorter lines
# this should be changed (as well as the corresponding .clang-format file).
#
- key: LONG_LINE
value: 100
#
# The default limit for the length of variable names is 20. Long names are
# problematic but twenty chars results in way too many errors. So increase
# the limit to something more reasonable.
#
- key: LONG_VARIABLE_NAME
value: 30
#
# This allows us to avoid peppering our code with inline comments such as
#
# scoped_lock locker(m_lock); //!OCLINT(side-effect)
#
# Specifically, this config key tells oclint that the named classes have
# RAII behavior so the local vars are actually used.
#
- key: RAII_CUSTOM_CLASSES
value: scoped_lock scoped_buffer_t builtin_commandline_scoped_transient_t scoped_push
# We're slightly more persmissive regarding the total number of lines in a
# function. Default is 50.
- key: LONG_METHOD
value: 60
# We're slightly more persmissive regarding the number of non-comment
# lines in a function. Default is 30.
- key: NCSS_METHOD
value: 40
# We're willing to allow slighly more linearly independent paths through a
# function. Most of our code has a lot of `switch` blocks or consecutive
# `if` tests that are straightforward to interpret but which increase this
# metric. Default is 10.
- key: CYCLOMATIC_COMPLEXITY
value: 14
# We're willing to allow slighly more execution paths through a function.
# Default is 200.
- key: NPATH_COMPLEXITY
value: 300
disable-rules:
#
# A few instances of "useless parentheses" errors are meaningful. Mostly
# in the context of the `return` statement. Unfortunately the vast
# majority would result in removing parentheses that decreases
# readability. So we're going to ignore this warning and rely on humans to
# notice when the parentheses are truly not needed.
#
# Also, some macro expansions, such as FD_SET(), trigger this warning and
# we don't want to suppress each of those individually.
#
- UselessParentheses
#
# OCLint wants variable names to be at least three characters in length.
# Which would be fine if it supported a reasonable set of exceptions
# (e.g., "i", "j", "k") and allowed adding additional exceptions to match
# conventions employed by a project. Since it doesn't, and thus generates
# a lot of really annoying warnings, we're going to disable this rule.
#
- ShortVariableName
#
# This rule flags perfectly reasonable conditions like `if (!some_condition)`
# and is therefore just noise. Disable this rule.
#
- InvertedLogic
#
# The idea behind the "double negative" rule is sound since constructs
# like "!!(var & flag)" should be written as "static_cast<bool>(var &
# flag)". Unfortunately this rule has way too many false positives;
# especially in the context of assert statements. So disable this rule.
#
- DoubleNegative
#
# Avoiding bitwise operators in a conditional is a good idea with one
# exception: testing whether a bit flag is set. Which happens to be the
# only time you'll see something like `if (j->flags & JOB_CONSTRUCTED)`
# in fish source.
#
- BitwiseOperatorInConditional
#
# I don't think I've ever seen a case where assigning a value to a
# parameter inside the function body was unclear, let along dangerous or
# an error. This rule is therefore just noise. Disable this rule.
#
- ParameterReassignment

View File

@@ -31,7 +31,7 @@ PREFIX?=/usr/local
build/fish: build/$(BUILDFILE)
$(CMAKE) --build build
# Don't split the mkdir into its own rule because that would cause CMake to regenerate the build
# Don't split the mkdir into its own rule because that would cause CMake to regenerate the build
# files after each build (because it adds the mdate of the build directory into the out-of-date
# calculation tree). GNUmake supports order-only dependencies, BSDmake does not seem to.
build/$(BUILDFILE):
@@ -48,7 +48,11 @@ clean:
.PHONY: test
test: build/fish
$(CMAKE) --build build --target test
$(CMAKE) --build build --target fish_run_tests
.PHONY: fish_run_tests
fish_run_tests: build/fish
$(CMAKE) --build build --target fish_run_tests
.PHONY: run
run: build/fish

View File

@@ -1,3 +1,597 @@
fish ?.?.? (released ???)
=========================
fish 4.1.3 (released ???)
=========================
This release fixes the following regressions identified in 4.1.0:
- Crash on invalid :doc:`function <cmds/function>` command (:issue:`11912`).
as well as the following regressions identified in 4.0.0:
- Crash when passing negative PIDs to :doc:`wait <cmds/wait>` (:issue:`11929`).
fish 4.1.2 (released October 7, 2025)
=====================================
This release fixes the following regressions identified in 4.1.0:
- Fixed spurious error output when completing remote file paths for ``scp`` (:issue:`11860`).
- Fixed the :kbd:`alt-l` binding not formatting ``ls`` output correctly (one entry per line, no colors) (:issue:`11888`).
- Fixed an issue where focus events (currently only enabled in ``tmux``) would cause multiline prompts to be redrawn in the wrong line (:issue:`11870`).
- Stopped printing output that would cause a glitch on old versions of Midnight Commander (:issue:`11869`).
- Added a fix for some configurations of Zellij where :kbd:`escape` key processing was delayed (:issue:`11868`).
- Fixed a case where the :doc:`web-based configuration tool <cmds/fish_config>` would generate invalid configuration (:issue:`11861`).
- Fixed a case where pasting into ``fish -c read`` would fail with a noisy error (:issue:`11836`).
- Fixed a case where upgrading fish would break old versions of fish that were still running.
In general, fish still needs to be restarted after it is upgraded,
except for `standalone builds <https://github.com/fish-shell/fish-shell/?tab=readme-ov-file#building-fish-with-embedded-data-experimental>`__.
fish 4.1.1 (released September 30, 2025)
========================================
This release fixes the following regressions identified in 4.1.0:
- Many of our new Chinese translations were more confusing than helpful; they have been fixed or removed (:issue:`11833`).
Note that you can work around this type of issue by configuring fish's :doc:`message localization <cmds/_>`:
if your environment contains something like ``LANG=zh_CN.UTF-8``,
you can use ``set -g LC_MESSAGES en`` to use English messages inside fish.
This will not affect fish's child processes unless ``LC_MESSAGES`` was already exported.
- Some :doc:`fish_config <cmds/fish_config>` subcommands for showing prompts and themes had been broken in standalone Linux builds (those using the ``embed-data`` cargo feature), which has been fixed (:issue:`11832`).
- On Windows Terminal, we observed an issue where fish would fail to read the terminal's response to our new startup queries, causing noticeable lags and a misleading error message. A workaround has been added (:issue:`11841`).
- A WezTerm `issue breaking shifted key input <https://github.com/wezterm/wezterm/issues/6087>`__ has resurfaced on some versions of WezTerm; our workaround has been extended to cover all versions for now (:issue:`11204`).
- Fixed a crash in :doc:`the web-based configuration tool <cmds/fish_config>` when using the new underline styles (:issue:`11840`).
fish 4.1.0 (released September 27, 2025)
========================================
.. ignore for 4.1: 10929 10940 10948 10955 10965 10975 10989 10990 10998 11028 11052 11055 11069 11071 11079 11092 11098 11104 11106 11110 11140 11146 11148 11150 11214 11218 11259 11288 11299 11328 11350 11373 11395 11417 11419
Notable improvements and fixes
------------------------------
- Compound commands (``begin; echo 1; echo 2; end``) can now be written using braces (``{ echo1; echo 2 }``), like in other shells.
- fish now supports transient prompts: if :envvar:`fish_transient_prompt` is set to 1, fish will reexecute prompt functions with the ``--final-rendering`` argument before running a commandline (:issue:`11153`).
- Tab completion results are truncated up to the common directory path, instead of somewhere inside that path. E.g. if you complete "share/functions", and it includes the files "foo.fish" and "bar.fish",
the completion pager will now show "…/foo.fish" and "…/bar.fish" (:issue:`11250`).
- Self-installing builds as created by e.g. ``cargo install`` no longer install other files, see :ref:`below <changelog-4.1-embedded>`.
- Our gettext-based message-localization has been reworked,
adding translations to self-installing builds; see :ref:`below <changelog-4.1-gettext>`.
Deprecations and removed features
---------------------------------
- ``set_color --background=COLOR`` no longer implicitly activates bold mode.
If your theme is stored in universal variables (the historical default), some bold formatting might be lost.
To fix this, we suggest updating to the latest version of our theme, to explicitly activate bold mode,
for example use ``fish_config theme save "fish default"``.
- ``{echo,echo}`` or ``{ echo, echo }`` are no longer interpreted as brace expansion tokens but as :doc:`compound commands <cmds/begin>`.
- Terminfo-style key names (``bind -k nul``) are no longer supported. They had been superseded by fish's :doc:`own key names <cmds/bind>` since 4.0 (:issue:`11342`).
- fish no longer reads the terminfo database, so its behavior is generally no longer affected by the :envvar:`TERM` environment variable (:issue:`11344`).
For the time being, this change can be reversed via the ``ignore-terminfo`` :ref:`feature flag <featureflags>`.
To do so, run the following once and restart fish::
set -Ua fish_features no-ignore-terminfo
- The ``--install`` option when fish is built as self-installing is removed, see :ref:`below <changelog-4.1-embedded>`.
- ``set_color ff0000`` now outputs 24-bit RGB true-color even if :envvar:`COLORTERM` is unset.
One can override this by setting :envvar:`fish_term24bit` to 0 (:issue:`11372`).
- fish now requires the terminal to respond to queries for the :ref:`Primary Device Attribute <term-compat-primary-da>`.
For now, this can be reversed via a :ref:`feature flag <featureflags>`,
by running (once) ``set -Ua fish_features no-query-term`` and restarting fish.
- Users of GNU screen may experience :ref:`minor glitches <term-compat-dcs-gnu-screen>` when starting fish.
Scripting improvements
----------------------
- The :doc:`argparse <cmds/argparse>` builtin has seen many improvements, see :ref:`below <changelog-4.1-argparse>`.
- The :doc:`string pad <cmds/string-pad>` command now has a ``-C/--center`` option.
- The :doc:`psub <cmds/psub>` command now allows combining ``--suffix`` with ``--fifo`` (:issue:`11729`).
- The :doc:`read <cmds/read>` builtin has learned the ``--tokenize-raw`` option to tokenize without quote removal (:issue:`11084`).
Interactive improvements
------------------------
- Autosuggestions are now also provided in multi-line command lines. Like :kbd:`ctrl-r`, these operate only on the current line.
- Autosuggestions used to not suggest multi-line command-lines from history; now autosuggestions include individual lines from multi-line command-lines.
- The history pager search now preserves ordering between :kbd:`ctrl-s` forward and :kbd:`ctrl-r` backward searches.
- Instead of highlighting events by flashing *all text to the left of the cursor*,
failing history token search (:kbd:`alt-.`) flashes the associated token,
failing tab-completion flashes the to-be-completed token (:issue:`11050`),
deleting an autosuggestion (:kbd:`shift-delete`) flashes the suggestion,
and all other scenarios flash the full command line.
- Pasted commands are now stripped of any :code:`$\ ` command prefixes, to help pasting code snippets.
- Builtin help options (e.g. ``abbr --help``) now use ``man`` directly, meaning that variables like :envvar:`MANWIDTH` are respected (:issue:`11786`).
- ``funced`` will now edit copied functions directly, instead of the file where ``function --copy`` was invoked. (:issue:`11614`)
- Added a simple ``fish_jj_prompt`` which reduces visual noise in the prompt inside `Jujutsu <https://jj-vcs.github.io/jj/latest/>`__ repositories that are colocated with Git.
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- On non-macOS systems, :kbd:`alt-left`, :kbd:`alt-right`, :kbd:`alt-backspace` and :kbd:`alt-delete` no longer operate on punctuation-delimited words but on whole arguments, possibly including special characters like ``/`` and quoted spaces.
On macOS, the corresponding :kbd:`ctrl-` prefixed keys operate on whole arguments.
Word operations are still available via the other respective modifier, just like in most web browsers.
- :kbd:`ctrl-z` (undo) after executing a command will restore the previous cursor position instead of placing the cursor at the end of the command line.
- The :kbd:`alt-s` binding will now also use ``run0`` if available.
- Some mouse support has been added: the OSC 133 prompt marking feature has learned about kitty's ``click_events=1`` flag, which allows moving fish's cursor by clicking in the command line,
and selecting pager items (:issue:`10932`).
- Before clearing the screen and redrawing, :kbd:`ctrl-l` now pushes all text located above the prompt to the terminal's scrollback,
via a new special input function :ref:`scrollback-push <special-input-functions-scrollback-push>`.
For compatibility with terminals that do not implement ECMA-48's :ref:`SCROLL UP <term-compat-indn>` command,
this function is only used if the terminal advertises support for that via :ref:`XTGETTCAP <term-compat-xtgettcap>`.
- Vi mode has learned :kbd:`ctrl-a` (increment) and :kbd:`ctrl-x` (decrement) (:issue:`11570`).
Completions
^^^^^^^^^^^
- ``git`` completions now show the remote URL as description when completing remotes.
- ``systemctl`` completions no longer print escape codes if ``SYSTEMD_COLORS`` happens to be set (:issue:`11465`).
- Added and improved many completion scripts, notably ``tmux``.
Improved terminal support
^^^^^^^^^^^^^^^^^^^^^^^^^
- Support for double, curly, dotted and dashed underlines, for use in ``fish_color_*`` variables and the :doc:`set_color builtin <cmds/set_color>` (:issue:`10957`).
- Underlines can now be colored independent of text (:issue:`7619`).
- New documentation page :doc:`Terminal Compatibility <terminal-compatibility>` (also accessible via ``man fish-terminal-compatibility``) lists the terminal control sequences used by fish.
Other improvements
------------------
- Updated Chinese and German translations.
- ``fish_indent --dump-parse-tree`` now emits simple metrics about the tree including its memory consumption.
- We added some tools to improve development workflows, for example ``build_tools/{check,update_translations,release}.sh`` and ``tests/test_driver.py``.
In conjunction with ``cargo``, these enable almost all day-to-day development tasks without using CMake.
For distributors
----------------
- Builtin commands that support the ``--help`` option now require the ``man`` program.
The direct dependency on ``mandoc`` and ``nroff`` has been removed.
- fish no longer uses gettext MO files, see :ref:`below <changelog-4.1-gettext>`.
If you have use cases which are incompatible with our new approach, please let us know.
- The :doc:`fish_indent <cmds/fish_indent>` and :doc:`fish_key_reader <cmds/fish_key_reader>` programs are now also available as builtins.
If fish is invoked via e.g. a symlink with one of these names,
it will act like the given tool (i.e. it's a multi-call binary).
This allows truly distributing fish as a single file (:issue:`10876`).
- The CMake build configuration has been simplified and no longer second-guesses rustup.
It will run rustc and cargo via :envvar:`PATH` or in ~/.cargo/bin/.
If that doesn't match your setup, set the Rust_COMPILER and Rust_CARGO CMake variables (:issue:`11328`).
- Cygwin support has been reintroduced, since `Rust gained a Cygwin target <https://github.com/rust-lang/rust/pull/134999>`__ (:issue:`11238`).
- CMake 3.15 is now required.
.. _changelog-4.1-embedded:
Changes to self-installing builds
---------------------------------
The self-installing build type introduced in fish 4.0 has been changed (:issue:`11143`).
Now fish built with embedded data will just read the data straight from its own binary or write it out to temporary files when necessary, instead of requiring an installation step on start.
That means it is now possible to build fish as a single file and copy it to any system with a compatible CPU architecture, including as a different user, without extracting any files.
As before, this is the default when building via ``cargo``, and disabled when building via CMake.
For packagers we continue to recommend CMake.
Note: When fish is built like this, the :envvar:`__fish_data_dir` variable will be empty because that directory no longer has meaning.
You should generally not need these files.
For example, if you want to make sure that completions for "foo" are loaded, use ``complete -C"foo " >/dev/null`` instead).
The raw files are still exposed via :ref:`status subcommands <status-get-file>`, mainly for fish's internal use, but you can also use them as a last resort.
Remaining benefits of a full installation (as currently done by CMake) are:
- man pages like ``fish(1)`` in standard locations, easily accessible from outside fish.
- a local copy of the HTML documentation, typically accessed via the :doc:`help <cmds/help>` function.
In builds with embedded data, ``help`` will redirect to e.g. `<https://fishshell.com/docs/current/>`__
- ``fish_indent`` and ``fish_key_reader`` as separate files, making them easily accessible outside fish
- an (empty) ``/etc/fish/config.fish`` as well as empty directories ``/etc/fish/{functions,completions,conf.d}``
- ``$PREFIX/share/pkgconfig/fish.pc``, which defines directories for configuration-snippets, like ``vendor_completions.d``
.. _changelog-4.1-gettext:
Changes to gettext localization
-------------------------------
We replaced several parts of the gettext functionality with custom implementations (:issue:`11726`).
Most notably, message extraction, which should now work reliably, and the runtime implementation, where we no longer dynamically link to gettext, but instead use our own implementation, whose behavior is similar to GNU gettext, with some :doc:`minor deviations <cmds/_>`.
Our implementation now fully respects fish variables, so locale variables do not have to be exported for fish localizations to work.
They still have to be exported to inform other programs about language preferences.
The :envvar:`LANGUAGE` environment variable is now treated as a path variable, meaning it is an implicitly colon-separated list.
While we no longer have any runtime dependency on gettext, we still need gettext tools for building, most notably ``msgfmt``.
When building without ``msgfmt`` available, localization will not work with the resulting executable.
Localization data is no longer sourced at runtime from MO files on the file system, but instead built into the executable.
This is always done, independently of the other data embedding, so all fish executables will have access to all message catalogs, regardless of the state of the file system.
Disabling our new ``localize-messages`` cargo feature will cause fish to be built without localization support.
CMake builds can continue to use the ``WITH_GETTEXT`` option, with the same semantics as the ``localize-messages`` feature.
The current implementation does not provide any configuration options for controlling which language catalogs are built into the executable (other than disabling them all).
As a workaround, you can delete files in the ``po`` directory before building to exclude unwanted languages.
.. _changelog-4.1-argparse:
Changes to the :doc:`argparse <cmds/argparse>` builtin
------------------------------------------------------
- ``argparse`` now saves recognised options, including option-arguments in :envvar:`argv_opts`, allowing them to be forwarded to other commands (:issue:`6466`).
- ``argparse`` options can now be marked to be deleted from :envvar:`argv_opts` (by adding a ``&`` at the end of the option spec, before a ``!`` if present). There is now also a corresponding ``-d`` / ``--delete`` option to ``fish_opt``.
- ``argparse --ignore-unknown`` now removes preceding known short options from groups containing unknown options (e.g. when parsing ``-abc``, if ``a`` is known but ``b`` is not, then :envvar:`argv` will contain ``-bc``).
- ``argparse`` now has an ``-u`` / ``--move-unknown`` option that works like ``--ignore-unknown`` but preserves unknown options in :envvar:`argv`.
- ``argparse`` now has an ``-S`` / ``--strict-longopts`` option that forbids abbreviating long options or passing them with a single dash (e.g. if there is a long option called ``foo``, ``--fo`` and ``--foo`` won't match it).
- ``argparse`` now has a ``-U`` / ``--unknown-arguments`` option to specify how to parse unknown option's arguments.
- ``argparse`` now allows specifying options that take multiple optional values by using ``=*`` in the option spec (:issue:`8432`).
In addition, ``fish_opt`` has been modified to support such options by using the ``--multiple-vals`` together with ``-o`` / ``--optional-val``; ``-m`` is also now acceptable as an abbreviation for ``--multiple-vals``.
- ``fish_opt`` no longer requires you give a short flag name when defining options, provided you give it a long flag name with more than one character.
- ``argparse`` option specifiers for long-only options can now start with ``/``, allowing the definition of long options with a single letter. Due to this change, the ``--long-only`` option to ``fish_opt`` is now no longer necessary and is deprecated.
- ``fish_opt`` now has a ``-v`` / ``--validate`` option you can use to give a fish script to validate values of the option.
--------------
fish 4.0.9 (released September 27, 2025)
========================================
This release fixes:
- a regression in 4.0.6 causing shifted keys to not be inserted on some terminals (:issue:`11813`).
- a regression in 4.0.6 causing the build to fail on systems where ``char`` is unsigned (:issue:`11804`).
- a regression in 4.0.0 causing a crash on an invalid :doc:`bg <cmds/bg>` invocation.
--------------
fish 4.0.8 (released September 18, 2025)
========================================
This release fixes a regression in 4.0.6 that caused user bindings to be shadowed by either fish's or a plugin's bindings (:issue:`11803`).
--------------
fish 4.0.6 (released September 12, 2025)
========================================
This release of fish fixes a number of issues identified in fish 4.0.2:
- fish now properly inherits $PATH under Windows WSL2 (:issue:`11354`).
- Remote filesystems are detected properly again on non-Linux systems.
- the :doc:`printf <cmds/printf>` builtin no longer miscalculates width of multi-byte characters (:issue:`11412`).
- For many years, fish has been "relocatable" -- it was possible to move the entire ``CMAKE_INSTALL_PREFIX`` and fish would use paths relative to its binary.
Only gettext locale paths were still determined purely at compile time, which has been fixed.
- the :doc:`commandline <cmds/commandline>` builtin failed to print the commandline set by a ``commandline -C`` invocation, which broke some completion scripts.
This has been corrected (:issue:`11423`).
- To work around terminals that fail to parse Operating System Command (OSC) sequences, a temporary feature flag has been added.
It allows you to disable prompt marking (OSC 133) by running (once) ``set -Ua fish_features no-mark-prompt`` and restarting fish (:issue:`11749`).
- The routines to save history and universal variables have seen some robustness improvements.
- builtin :doc:`status current-command <cmds/status>` no longer prints a trailing blank line.
- A crash displaying multi-line quoted command substitutions has been fixed (:issue:`11444`).
- Commands like ``set fish_complete_path ...`` accidentally disabled completion autoloading, which has been corrected.
- ``nmcli`` completions have been fixed to query network information dynamically instead of only when completing the first time.
- Git completions no longer print an error when no `git-foo` executable is in :envvar:`PATH`.
- Custom completions like ``complete foo -l long -xa ...`` that use the output of ``commandline -t``.
on a command-line like ``foo --long=`` have been invalidated by a change in 4.0; the completion scripts have been adjusted accordingly (:issue:`11508`).
- Some completions were misinterpreted, which caused garbage to be displayed in the completion list. This has been fixed.
- fish no longer interprets invalid control sequences from the terminal as if they were :kbd:`alt-[` or :kbd:`alt-o` key strokes.
- :doc:`bind <cmds/bind>` has been taught about the :kbd:`printscreen` and :kbd:`menu` keys.
- :kbd:`alt-delete` now deletes the word right of the cursor.
- :kbd:`ctrl-alt-h` erases the last word again (:issue:`11548`).
- :kbd:`alt-left` :kbd:`alt-right` were misinterpreted because they send unexpected sequences on some terminals; a workaround has been added. (:issue:`11479`).
- Key bindings like ``bind shift-A`` are no longer accepted; use ``bind shift-a`` or ``bind A``.
- Key bindings like ``bind shift-a`` take precedence over ``bind A`` when the key event included the shift modifier.
- Bindings using shift with non-ASCII letters (such as :kbd:`ctrl-shift-ä`) are now supported.
- Bindings with modifiers such as ``bind ctrl-w`` work again on non-Latin keyboard layouts such as a Russian one.
This is implemented by allowing key events such as :kbd:`ctrl-ц` to match bindings of the corresponding Latin key, using the kitty keyboard protocol's base layout key (:issue:`11520`).
- Vi mode: The cursor position after pasting via :kbd:`p` has been corrected.
- Vi mode: Trying to replace the last character via :kbd:`r` no longer replaces the last-but-one character (:issue:`11484`).
--------------
fish 4.0.2 (released April 20, 2025)
====================================
This release of fish fixes a number of issues identified in fish 4.0.1:
- Completions are quoted, rather than backslash-escaped, only if the completion is unambiguous. Continuing to edit the token is therefore easier (:issue:`11271`). This changes the behavior introduced in 4.0.0 where all completions were quoted.
- The warning when the terminfo database can't be found has been downgraded to a log message. fish will act as if the terminal behaves like xterm-256color, which is correct for the vast majority of cases (:issue:`11277`, :issue:`11290`).
- Key combinations using the super (Windows/command) key can now (actually) be bound using the :kbd:`super-` prefix (:issue:`11217`). This was listed in the release notes for 4.0.1 but did not work correctly.
- :doc:`function <cmds/function>` is stricter about argument parsing, rather than allowing additional parameters to be silently ignored (:issue:`11295`).
- Using parentheses in the :doc:`test <cmds/test>` builtin works correctly, following a regression in 4.0.0 where they were not recognized (:issue:`11387`).
- :kbd:`delete` in Vi mode when Num Lock is active will work correctly (:issue:`11303`).
- Abbreviations cannot alter the command-line contents, preventing a crash (:issue:`11324`).
- Improvements to various completions, including new completions for ``wl-randr`` (:issue:`11301`), performance improvements for ``cargo`` completions by avoiding network requests (:issue:`11347`), and other improvements for ``btrfs`` (:issue:`11320`), ``cryptsetup`` (:issue:`11315`), ``git`` (:issue:`11319`, :issue:`11322`, :issue:`11323`), ``jj`` (:issue:`11046`), and ``systemd-analyze`` (:issue:`11314`).
- The Mercurial (``hg``) prompt can handle working directories that contain an embedded newline, rather than producing errors (:issue:`11348`).
- A number of crashes have been fixed. Triggers include prompts containing backspace characters (:issue:`11280`), history pager search (:issue:`11355`), invalid UTF-8 in :doc:`read <cmds/read>` (:issue:`11383`), and the ``kill-selection`` binding (:issue:`11367`).
- A race condition in the test suite has been fixed (:issue:`11254`), and a test for fish versioning relaxed to support downstream distributors' modifications (:issue:`11173`).
- Small improvements to the documentation (:issue:`11264`, :issue:`11329`, :issue:`11361`).
--------------
fish 4.0.1 (released March 12, 2025)
====================================
This release of fish includes the following improvements compared to fish 4.0.0:
- Key combinations using the super (Windows/command) key can be bound using the :kbd:`super-` prefix (:issue:`11217`).
- Konsole's menu shows the "Open folder with" option again (:issue:`11198`).
- ``$fish_color_search_match`` will now only be applied to the foreground color if it has an explicit foreground. For example, this allows setting::
set -g fish_color_search_match --reverse
- Cursor shape commands (``\e[2 q``) are no longer sent in non-interactive shells or in redirections (:issue:`11255`).
- :doc:`status <cmds/status>` gained a ``is-interactive-read`` subcommand, to check whether the script is being called from an interactive :doc:`read <cmds/read>` invocation.
- fish's background tasks are now started in a way that avoids an error on macOS Terminal.app (:issue:`11181`).
- Using key combinations within qemu should work correctly.
- Prompts containing control characters no longer cause incorrect display of command lines (:issue:`11252`).
- Cancelling the command-line in Vi mode displays correctly again (:issue:`11261`).
- The acidhub prompt properly displays the git branch again (:issue:`11179`).
- Completions for ``wine`` correctly include files again (:issue:`11202`).
- On macOS, paths from ``/etc/paths`` and ``/etc/manpaths`` containing colons are handled correctly (:issue:`10684`). This functionality was included in the 4.0.0 release notes but was missing from the source code.
- The XTerm ``modifyOtherKeys`` keyboard encoding is no longer used under WezTerm, as it does not work correctly in all layouts (:issue:`11204`).
- :kbd:`option-left` and other similar keys should now work in iTerm versions before 3.5.12; the kitty keyboard protocol is now disabled on these versions (:issue:`11192`).
- The kitty keyboard protocol is no longer used under Midnight Commander, as it does not work correctly (:issue:`10640`).
- fish now sends the commandline along with the OSC 133 semantic prompt command start sequence. This fixes a test in the kitty terminal (:issue:`11203`).
- Git completions for third-party commands like "git-absorb" are completed correctly again (:issue:`11205`).
- Completions for ``diskutil`` no longer produce an error (:issue:`11201`).
- The output of certain error messages no longer prints newlines to standard output (:issue:`11248`).
- A number of crashes have been fixed, including file names longer than 255 bytes (:issue:`11221`), using fish on a btrfs filesystem (:issue:`11219`), history files that do not have the expected format (:issue:`11236`), and pasting into an empty command line (:issue:`11256`).
--------------
fish 4.0.0 (released February 27, 2025)
=======================================
fish's core code has been ported from C++ to Rust (:issue:`9512`). This means a large change in dependencies and how to build fish. However, there should be no direct impact on users. Packagers should see the :ref:`For Distributors <rust-packaging>` section at the end.
Notable backwards-incompatible changes
--------------------------------------
- As part of a larger binding rework, ``bind`` gained a new key notation.
In most cases the old notation should keep working, but in rare cases you may have to change a ``bind`` invocation to use the new notation.
See :ref:`below <changelog-4.0-new-bindings>` for details.
- :kbd:`ctrl-c` now calls a new bind function called ``clear-commandline``. The old behavior, which leaves a "^C" marker, is available as ``cancel-commandline`` (:issue:`10935`)
- ``random`` will produce different values from previous versions of fish when used with the same seed, and will work more sensibly with small seed numbers.
The seed was never guaranteed to give the same result across systems,
so we do not expect this to have a large impact (:issue:`9593`).
- Variables in command position that expand to a subcommand keyword are now forbidden to fix a likely user error.
For example, ``set editor command emacs; $editor`` is no longer allowed (:issue:`10249`).
- ``functions --handlers`` will now list handlers in a different order.
Now it is definition order, first to last, where before it was last to first.
This was never specifically defined, and we recommend not relying on a specific order (:issue:`9944`).
- The ``qmark-noglob`` feature, introduced in fish 3.0, is enabled by default. That means ``?`` will no longer act as a single-character glob.
You can, for the time being, turn it back on by adding ``no-qmark-noglob`` to :envvar:`fish_features` and restarting fish::
set -Ua fish_features no-qmark-noglob
The flag will eventually be made read-only, making it impossible to turn off.
- Terminals that fail to ignore unrecognized OSC or CSI sequences may display garbage. We know cool-retro-term and emacs' ansi-term are affected, but most mainstream terminals are not.
- fish no longer searches directories from the Windows system/user ``$PATH`` environment variable for Linux executables. To execute Linux binaries by name (i.e. not with a relative or absolute path) from a Windows folder, make sure the ``/mnt/c/...`` path is explicitly added to ``$fish_user_paths`` and not just automatically appended to ``$PATH`` by ``wsl.exe`` (:issue:`10506`).
- Under Microsoft Windows Subsystem for Linux 1 (not WSL 2), backgrounded jobs that have not been disowned and do not terminate on their own after a ``SIGHUP`` + ``SIGCONT`` sequence will be explicitly killed by fish on exit (after the usual prompt to close or disown them) to work around a WSL 1 deficiency that sees backgrounded processes that run into ``SIGTTOU`` remain in a suspended state indefinitely (:issue:`5263`). The workaround is to explicitly ``disown`` processes you wish to outlive the shell session.
Notable improvements and fixes
------------------------------
.. _changelog-4.0-new-bindings:
- fish now requests XTerm's ``modifyOtherKeys`` keyboard encoding and `kitty keyboard protocol's <https://sw.kovidgoyal.net/kitty/keyboard-protocol/>`_ progressive enhancements (:issue:`10359`).
Depending on terminal support, this allows to binding more key combinations, including arbitrary combinations of modifiers :kbd:`ctrl`, :kbd:`alt` and :kbd:`shift`, and distinguishing (for example) :kbd:`ctrl-i` from :kbd:`tab`.
Additionally, ``bind`` now supports a human-readable syntax in addition to byte sequences.
This includes modifier names, and names for keys like :kbd:`enter` and :kbd:`backspace`.
For example
- ``bind up 'do something'`` binds the up-arrow key instead of a two-key sequence ("u" and then "p")
- ``bind ctrl-x,alt-c 'do something'`` binds a sequence of two keys.
Any key argument that starts with an ASCII control character (like ``\e`` or ``\cX``) or is up to 3 characters long, not a named key, and does not contain ``,`` or ``-`` will be interpreted in the old syntax to keep compatibility for the majority of bindings.
Keyboard protocols can be turned off by disabling the "keyboard-protocols" feature flag::
set -Ua fish_features no-keyboard-protocols
This is a temporary measure to work around buggy terminals (:issue:`11056`), which appear to be relatively rare.
Use this if something like "=0" or "=5u" appears in your commandline mysteriously.
- fish can now be built as a self-installing binary (:issue:`10367`). That means it can be easily built on one system and copied to another, where it can extract supporting files.
To do this, run::
cargo install --path . # in a clone of the fish repository
# or `cargo build --release` and copy target/release/fish{,_indent,_key_reader} wherever you want
The first time it runs interactively, it will extract all the data files to ``~/.local/share/fish/install/``. A specific path can be used for the data files with ``fish --install=PATH`` To uninstall, remove the fish binaries and that directory.
This build system is experimental; the main build system, using ``cmake``, remains the recommended approach for packaging and installation to a prefix.
- A new function ``fish_should_add_to_history`` can be overridden to decide whether a command should be added to the history (:issue:`10302`).
- Bindings can now mix special input functions and shell commands, so ``bind ctrl-g expand-abbr "commandline -i \n"`` works as expected (:issue:`8186`).
- Special input functions run from bindings via ``commandline -f`` are now applied immediately, instead of after the currently executing binding (:issue:`3031`, :issue:`10126`).
For example, ``commandline -i foo; commandline | grep foo`` succeeds now.
- Undo history is no longer truncated after every command, but kept for the lifetime of the shell process.
- The :kbd:`ctrl-r` history search now uses glob syntax (:issue:`10131`).
- The :kbd:`ctrl-r` history search now operates only on the line or command substitution at cursor, making it easier to combine commands from history (:issue:`9751`).
- Abbreviations can now be restricted to specific commands. For instance::
abbr --add --command git back 'reset --hard HEAD^'
will expand "back" to ``reset --hard HEAD^``, but only when the command is ``git`` (:issue:`9411`).
Deprecations and removed features
---------------------------------
- ``commandline --tokenize`` (short option ``-o``) has been deprecated in favor of ``commandline --tokens-expanded`` (short option ``-x``) which expands variables and other shell syntax, removing the need to use :doc:`eval <cmds/eval>` in completion scripts (:issue:`10212`).
- Two new feature flags:
- ``remove-percent-self`` (see ``status features``) disables PID expansion of ``%self``, which has been supplanted by ``$fish_pid`` (:issue:`10262`).
- ``test-require-arg`` disables ``test``'s one-argument mode. That means ``test -n`` without an additional argument will return false, ``test -z`` will keep returning true. Any other option without an argument, anything that is not an option and no argument will be an error. This also goes for ``[``, test's alternate name.
This is a frequent source of confusion and so we are breaking with POSIX explicitly in this regard.
In addition to the feature flag, there is a debug category "deprecated-test". Running fish with ``fish -d deprecated-test`` will show warnings whenever a ``test`` invocation that would change is used. (:issue:`10365`).
These can be enabled with::
set -Ua fish_features remove-percent-self test-require-arg
We intend to enable them by default in future, and after that eventually make them read-only.
- Specifying key names as terminfo names (using the ``bind -k`` syntax) is deprecated and may be removed in a future version.
- When a terminal pastes text into fish using bracketed paste, fish used to switch to a special ``paste`` bind mode.
This bind mode has been removed. The behavior on paste is no longer configurable.
- When an interactive fish is stopped or terminated by a signal that cannot be caught (SIGSTOP or SIGKILL), it may leave the terminal in a state where keypresses with modifiers are sent as CSI u sequences, instead of traditional control characters or escape sequences that are recognized by Readline and compatible programs, such as bash and python.
If this happens, you can use the ``reset`` command from ``ncurses`` to restore the terminal state.
- ``fish_key_reader --verbose`` no longer shows timing information.
- Terminal information is no longer read from hashed terminfo databases, or termcap databases (:issue:`10269`). The vast majority of systems use a non-hashed terminfo database, which is still supported.
- ``source`` returns an error if used without a filename or pipe/redirection (:issue:`10774`).
Scripting improvements
----------------------
- ``for`` loops will no longer remember local variables from the previous iteration (:issue:`10525`).
- A new ``history append`` subcommand appends a command to the history, without executing it (:issue:`4506`).
- A new redirection: ``<? /path/to/file`` will try opening the file as input, and if it doesn't succeed silently uses ``/dev/null`` instead.
This can help with checks like ``test -f /path/to/file; and string replace foo bar < /path/to/file``. (:issue:`10387`)
- A new option ``commandline --tokens-raw`` prints a list of tokens without any unescaping (:issue:`10212`).
- A new option ``commandline --showing-suggestion`` tests whether an autosuggestion is currently displayed (:issue:`10586`).
- ``functions`` and ``type`` now show that a function was copied and its source, rather than solely ``Defined interactively`` (:issue:`6575`).
- Stack trace now shows line numbers for copied functions (:issue:`6575`).
- ``foo & && bar`` is now a syntax error, like in other shells (:issue:`9911`).
- ``if -e foo; end`` now prints a more accurate error (:issue:`10000`).
- ``cd`` into a directory that is not readable but accessible (permissions ``--x``) is now possible (:issue:`10432`).
- An integer overflow in ``string repeat`` leading to a near-infinite loop has been fixed (:issue:`9899`).
- ``string shorten`` behaves better in the presence of non-printable characters, including fixing an integer overflow that shortened strings more than intended (:issue:`9854`).
- ``string pad`` no longer allows non-printable characters as padding (:issue:`9854`).
- ``string repeat`` now allows omission of ``-n`` when the first argument is an integer (:issue:`10282`).
- ``string match`` and ``replace`` have a new ``--max-matches`` option to return as soon as the specified number of matches have been identified, which can improve performance in scripts (:issue:`10587`).
- ``functions --handlers-type caller-exit`` once again lists functions defined as ``function --on-job-exit caller``, rather than them being listed by ``functions --handlers-type process-exit``.
- A new ``set --no-event`` option sets or erases variables without triggering a variable event. This can be useful to change a variable in an event handler (:issue:`10480`).
- Commas in command substitution output are no longer used as separators in brace expansion, preventing a surprising expansion in some cases (:issue:`5048`).
- Universal variables can now store strings containing invalid UTF-8 (:issue:`10313`).
- A new ``path basename -E`` option that causes it to return the basename ("filename" with the directory prefix removed) with the final extension (if any) also removed. This is a shorter version of ``path change-extension "" (path basename $foo)`` (:issue:`10521`).
- A new ``math --scale-mode`` option to select ``truncate``, ``round``, ``floor``, ``ceiling`` as you wish; the default value is ``truncate``. (:issue:`9117`).
- ``random`` is now less strict about its arguments, allowing a start larger or equal to the end. (:issue:`10879`)
- ``function --argument-names`` now produces an error if a read-only variable name is used, rather than simply ignoring it (:issue:`10842`).
- Tilde expansion in braces (that is, ``{~,}``) works correctly (:issue:`10610`).
Interactive improvements
------------------------
- Autosuggestions were sometimes not shown after recalling a line from history, which has been fixed (:issue:`10287`).
- Up-arrow search matches -- which are highlighted in reverse colors -- are no longer syntax-highlighted, to fix bad contrast with the search match highlighting.
- Command abbreviations (those with ``--position command`` or without a ``--position``) now also expand after decorators like ``command`` (:issue:`10396`).
- Abbreviations now expand after process separators like ``;`` and ``|``. This fixes a regression in version 3.6 (:issue:`9730`).
- When exporting interactively defined functions (using ``type``, ``functions`` or ``funcsave``) the function body is now indented, to match the interactive command line editor (:issue:`8603`).
- :kbd:`ctrl-x` (``fish_clipboard_copy``) on multiline commands now includes indentation (:issue:`10437`).
- :kbd:`ctrl-v` (``fish_clipboard_paste``) now strips ASCII control characters from the pasted text.
This is consistent with normal keyboard input (:issue:`5274`).
- When a command like ``fg %2`` fails to find the given job, it no longer behaves as if no job spec was given (:issue:`9835`).
- Redirection in command position like ``>echo`` is now highlighted as error (:issue:`8877`).
- ``fish_vi_cursor`` now works properly inside the prompt created by builtin ``read`` (:issue:`10088`).
- fish no longer fails to open a FIFO if interrupted by a terminal resize signal (:issue:`10250`).
- ``read --help`` and friends no longer ignore redirections. This fixes a regression in version 3.1 (:issue:`10274`).
- Measuring a command with ``time`` now considers the time taken for command substitution (:issue:`9100`).
- ``fish_add_path`` now automatically enables verbose mode when used interactively (in the command line), in an effort to be clearer about what it does (:issue:`10532`).
- fish no longer adopts TTY modes of failed commands (:issue:`10603`).
- ``complete -e cmd`` now prevents autoloading completions for ``cmd`` (:issue:`6716`).
- fish's default color scheme no longer uses the color "blue", as it has bad contrast against the background in a few terminal's default palettes (:issue:`10758`, :issue:`10786`)
The color scheme will not be upgraded for existing installs. If you want, you should select it again via ``fish_config``.
- Command lines which are larger than the terminal are now displayed correctly, instead of multiple blank lines being displayed (:issue:`7296`).
- Prompts that use external commands will no longer produce an infinite loop if the command crashes (:issue:`9796`).
- The output of ``jobs`` shows "-" for jobs that have the same process group ID as the fish process, rather than "-2" (:issue:`10833`).
- Job expansion (``%1`` syntax) works properly for jobs that are a mixture of external commands and functions (:issue:`10832`).
- Command lines which have more lines than the terminal can be displayed and edited correctly (:issue:`10827`).
- Functions that have been erased are no longer highlighted as valid commands (:issue:`10866`).
- ``not``, ``time``, and variable assignments (that is ``not time a=b env``) is correctly recognized as valid syntax (:issue:`10890`).
- The Web-based configuration removes old right-hand-side prompts again, fixing a regression in fish 3.4.0 (:issue:`10675`).
- Further protection against programs which crash and leave the terminal in an inconsistent state (:issue:`10834`, :issue:`11038`).
- A workaround for git being very slow on macOS has been applied, improving performance after a fresh boot (:issue:`10535`).
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- When the cursor is on a command that resolves to an executable script, :kbd:`alt-o` will now open that script in your editor (:issue:`10266`).
- During up-arrow history search, :kbd:`shift-delete` will delete the current search item and move to the next older item. Previously this was only supported in the history pager.
- :kbd:`shift-delete` will also remove the currently-displayed autosuggestion from history, and remove it as a suggestion.
- :kbd:`ctrl-Z` (also known as :kbd:`ctrl-shift-z`) is now bound to redo.
- Some improvements to the :kbd:`alt-e` binding which edits the command line in an external editor:
- The editor's cursor position is copied back to fish. This is currently supported for Vim and Kakoune.
- Cursor position synchronization is only supported for a set of known editors, which are now also detected in aliases which use ``complete --wraps``. For example, use ``complete --wraps my-vim vim`` to synchronize cursors when ``EDITOR=my-vim``.
- Multiline commands are indented before being sent to the editor, which matches how they are displayed in fish.
- The ``...-path-component`` bindings, like ``backward-kill-path-component``, now treat ``#`` as part of a path component (:issue:`10271`).
- Bindings like :kbd:`alt-l` that print output in between prompts now work correctly with multiline commandlines.
- :kbd:`alt-d` on an empty command line lists the directory history again. This restores the behavior of version 2.1.
- ``history-prefix-search-backward`` and ``-forward`` now maintain the cursor position, instead of moving the cursor to the end of the command line (:issue:`10430`).
- The following keys have refined behavior if the terminal supports :ref:`the new keyboard encodings <changelog-4.0-new-bindings>`:
- :kbd:`shift-enter` now inserts a newline instead of executing the command line.
- :kbd:`ctrl-backspace` now deletes the last word instead of only one character (:issue:`10741`).
- :kbd:`ctrl-delete` deletes the next word (same as :kbd:`alt-d`).
- New special input functions:
- ``forward-char-passive`` and ``backward-char-passive`` are like their non-passive variants but do not accept autosuggestions or move focus in the completion pager (:issue:`10398`).
- ``forward-token``, ``backward-token``, ``kill-token``, and ``backward-kill-token`` are similar to the ``*-bigword`` variants but for the whole argument token (which includes escaped spaces) (:issue:`2014`).
- ``clear-commandline``, which merely clears the command line, as an alternative to ``cancel-commandline`` which prints ``^C`` and a new prompt (:issue:`10213`).
- The ``accept-autosuggestion`` special input function now returns false when there was nothing to accept (:issue:`10608`).
- Vi mode has seen some improvements but continues to suffer from the lack of people working on it.
- New default cursor shapes for insert and replace mode.
- :kbd:`ctrl-n` in insert mode accepts autosuggestions (:issue:`10339`).
- Outside insert mode, the cursor will no longer be placed beyond the last character on the commandline.
- When the cursor is at the end of the commandline, a single :kbd:`l` will accept an autosuggestion (:issue:`10286`).
- The cursor position after pasting (:kbd:`p`) has been corrected.
- Added an additional binding, :kbd:`_`, for moving to the beginning of the line (:issue:`10720`).
- When the cursor is at the start of a line, escaping from insert mode no longer moves the cursor to the previous line.
- Added bindings for clipboard interaction, like :kbd:`",+,p` and :kbd:`",+,y,y`.
- Deleting in visual mode now moves the cursor back, matching vi (:issue:`10394`).
- The :kbd:`;`, :kbd:`,`, :kbd:`v`, :kbd:`V`, :kbd:`I`, and :kbd:`gU` bindings work in visual mode (:issue:`10601`, :issue:`10648`).
- Support :kbd:`%` motion (:issue:`10593`).
- :kbd:`ctrl-k` to remove the contents of the line beyond the cursor in all modes (:issue:`10648`).
- Support `ab` and `ib` vi text objects. New input functions are introduced ``jump-{to,till}-matching-bracket`` (:issue:`1842`).
- The :kbd:`E` binding now correctly handles the last character of the word, by jumping to the next word (:issue:`9700`).
Completions
^^^^^^^^^^^
- Command-specific tab completions may now offer results whose first character is a period. For example, it is now possible to tab-complete ``git add`` for files with leading periods. The default file completions hide these files, unless the token itself has a leading period (:issue:`3707`).
- Option completion now uses fuzzy subsequence filtering, just like non-option completion (:issue:`830`).
This means that ``--fb`` may be completed to ``--foobar`` if there is no better match.
- Completions that insert an entire token now use quotes instead of backslashes to escape special characters (:issue:`5433`).
- Normally, file name completions start after the last ``:`` or ``=`` in a token.
This helps commands like ``rsync --files-from=``.
This special meaning can now disabled by escaping these separators as ``\:`` and ``\=``.
This matches Bash's behavior.
Note that this escaping is usually not necessary since the completion engine already tries
to guess whether the separator is actually part of a file name.
- Various new completion scripts and numerous updates to existing ones.
- Completions could hang if the ``PAGER`` environment variable was sent to certain editors on macOS, FreeBSD and some other platforms. This has been fixed (:issue:`10820`).
- Generated completions are now stored in ``$XDG_CACHE_HOME/fish`` or ``~/.cache/fish`` by default (:issue:`10369`)
- A regression in fish 3.1, where completing a command line could change it completely, has been fixed (:issue:`10904`).
Improved terminal support
^^^^^^^^^^^^^^^^^^^^^^^^^
- fish now marks the prompt and command-output regions (via OSC 133) to enable terminal shell integration (:issue:`10352`).
Shell integration shortcuts can scroll to the next/previous prompt or show the last command output in a pager.
- fish now reports the working directory (via OSC 7) unconditionally instead of only for some terminals (:issue:`9955`).
- fish now sets the terminal window title (via OSC 0) unconditionally instead of only for some terminals (:issue:`10037`).
- Focus reporting in tmux is no longer disabled on the first prompt.
- Focus reporting is now disabled during commands run inside key bindings (:issue:`6942`).
- Cursor changes are applied to all terminals that support them, and the list of specifically-supported terminals has been removed (:issue:`10693`).
- If it cannot find the terminfo entry given by :envvar:`TERM` environment variable, fish will now use an included ``xterm-256color`` definition to match the vast majority of current terminal emulators (:issue:`10905`). If you need to have a specific terminfo profile for your terminal's ``TERM`` variable, install it into the terminfo database.
- Further improvements to the correct display of prompts which fill the width of the terminal (:issue:`8164`).
Other improvements
------------------
- ``status`` gained a ``build-info`` subcommand, to print information on how fish was built, to help with debugging (:issue:`10896`).
- ``fish_indent`` will now collapse multiple empty lines into one (:issue:`10325`).
- ``fish_indent`` now preserves the modification time of files if there were no changes (:issue:`10624`).
- Performance in launching external processes has been improved for many cases (:issue:`10869`).
- Performance and interactivity under Windows Subsystem for Linux has been improved, with a workaround for Windows-specific locations being appended to ``$PATH`` by default (:issue:`10506`).
- On macOS, paths from ``/etc/paths`` and ``/etc/manpaths`` containing colons are handled correctly (:issue:`10684`).
- Additional filesystems such as AFS are properly detected as remote, which avoids certain hangs due to expensive filesystem locks (:issue:`10818`).
- A spurious error when launching multiple instances of fish for the first time has been removed (:issue:`10813`).
.. _rust-packaging:
For distributors
----------------
fish has been ported to Rust. This means a significant change in dependencies, which are listed in the README. In short, Rust 1.70 or greater is required, and a C++ compiler is no longer needed (although a C compiler is still required, for some C glue code and the tests).
CMake remains the recommended build system, because of cargo's limited support for installing support files. Version 3.5 remains the minimum supported version. The Xcode generator for CMake is not supported any longer (:issue:`9924`). CMake builds default to optimized release builds (:issue:`10799`).
fish no longer depends on the ncurses library, but still uses a terminfo database. When packaging fish, please add a dependency on the package containing your terminfo database instead of curses.
The ``test`` target was removed as it can no longer be defined in new CMake versions. Use ``make fish_run_tests``. Any existing test target will not print output if it fails (:issue:`11116`).
The Web-based configuration has been rewritten to use Alpine.js (:issue:`9554`).
--------------
fish 4.0b1 (released December 17, 2024)
=======================================
A number of improvements were included in fish 4.0.0 following the beta release of 4.0b1. These include fixes for regressions, improvements to completions and documentation, and the removal of a small number of problematic changes.
The full list of fixed issues can be found on the `GitHub milestone page for 4.0-final <https://github.com/fish-shell/fish-shell/milestone/43>`_.
--------------
fish 3.7.1 (released March 19, 2024)
====================================
@@ -33,7 +627,7 @@ Notable improvements and fixes
- Improvements to the history pager, including:
- The history pager will now also attempt subsequence matches (:issue:`9476`), so you can find a command line like ``git log 3.6.1..Integration_3.7.0`` by searching for ``gitInt``.
- Opening the history pager will now fill the search field with a search string if you're already in a search (:issue:`10005`). This makes it nicer to search something with :kbd:`` and then later decide to switch to the full pager.
- Opening the history pager will now fill the search field with a search string if you're already in a search (:issue:`10005`). This makes it nicer to search something with :kbd:`up` and then later decide to switch to the full pager.
- Closing the history pager with enter will now copy the search text to the commandline if there was no match, so you can continue editing the command you tried to find right away (:issue:`9934`).
- Performance improvements for command completions and globbing, where supported by the operating system, especially on slow filesystems such as NFS (:issue:`9891`, :issue:`9931`, :issue:`10032`, :issue:`10052`).
@@ -63,21 +657,21 @@ Interactive improvements
- Vi mode now uses :envvar:`fish_cursor_external` to set the cursor shape for external commands (:issue:`4656`).
- Opening the history search in vi mode switches to insert mode correctly (:issue:`10141`).
- Vi mode cursor shaping is now enabled in iTerm2 (:issue:`9698`).
- Working directory reporting is enabled for iTerm2 (:issue:`9955`).
- Completing commands as root includes commands not owned by root, fixing a regression introduced in fish 3.2.0 (:issue:`9699`).
- Selection uses ``fish_color_selection`` for the foreground and background colors, as intended, rather than just the background (:issue:`9717`).
- The completion pager will no longer sometimes skip the last entry when moving through a long list (:issue:`9833`).
- The interactive ``history delete`` interface now allows specifying index ranges like "1..5" (:issue:`9736`), and ``history delete --exact`` now properly saves the history (:issue:`10066`).
- Command completion will now call the stock ``manpath`` on macOS, instead of a potential Homebrew version. This prevents awkward error messages (:issue:`9817`).
- A new bind function ``history-pager-delete``, bound to :kbd:`Shift` + :kbd:`Delete` by default, will delete the currently-selected history pager item from history (:issue:`9454`).
- the ``redo`` special input function restores the pre-undo cursor position.
- A new bind function ``history-pager-delete``, bound to :kbd:`shift-delete` by default, will delete the currently-selected history pager item from history (:issue:`9454`).
- ``fish_key_reader`` will now use printable characters as-is, so pressing "ö" no longer leads to it telling you to bind ``\u00F6`` (:issue:`9986`).
- ``open`` can be used to launch terminal programs again, as an ``xdg-open`` bug has been fixed and a workaround has been removed (:issue:`10045`).
- The ``repaint-mode`` binding will now only move the cursor if there is repainting to be done. This fixes :kbd:`Alt` combination bindings in vi mode (:issue:`7910`).
- A new ``clear-screen`` bind function is used for :kbd:`Ctrl` + :kbd:`l` by default. This clears the screen and repaints the existing prompt at first,
- The ``repaint-mode`` binding will now only move the cursor if there is repainting to be done. This fixes :kbd:`alt` combination bindings in vi mode (:issue:`7910`).
- A new ``clear-screen`` bind function is used for :kbd:`ctrl-l` by default. This clears the screen and repaints the existing prompt at first,
so it eliminates visible flicker unless the terminal is very slow (:issue:`10044`).
- The ``alias`` convenience function has better support for commands with unusual characters, like ``+`` (:issue:`8720`).
- A longstanding issue where items in the pager would sometimes display without proper formatting has been fixed (:issue:`9617`).
- The :kbd:`Alt` + :kbd:`l` binding, which lists the directory of the token under the cursor, correctly expands tilde (``~``) to the home directory (:issue:`9954`).
- The :kbd:`alt-l` binding, which lists the directory of the token under the cursor, correctly expands tilde (``~``) to the home directory (:issue:`9954`).
- Various fish utilities that use an external pager will now try a selection of common pagers if the :envvar:`PAGER` environment variable is not set, or write the output to the screen without a pager if there is not one available (:issue:`10074`).
- Command-specific tab completions may now offer results whose first character is a period. For example, it is now possible to tab-complete ``git add`` for files with leading periods. The default file completions hide these files, unless the token itself has a leading period (:issue:`3707`).
@@ -181,6 +775,7 @@ This release of fish contains a number of fixes for problems identified in fish
Notable improvements and fixes
------------------------------
- ``abbr --erase`` now also erases the universal variables used by the old abbr function. That means::
abbr --erase (abbr --list)
can now be used to clean out all old abbreviations (:issue:`9468`).
@@ -203,10 +798,10 @@ Interactive improvements
- Variables that were set while the locale was C (the default ASCII-only locale) will now properly be encoded if the locale is switched (:issue:`2613`, :issue:`9473`).
- Escape during history search restores the original command line again (fixing a regression in 3.6.0).
- Using ``--help`` on builtins now respects the ``$MANPAGER`` variable, in preference to ``$PAGER`` (:issue:`9488`).
- :kbd:`Control-G` closes the history pager, like other shells (:issue:`9484`).
- :kbd:`ctrl-g` closes the history pager, like other shells (:issue:`9484`).
- The documentation for the ``:``, ``[`` and ``.`` builtin commands can now be looked up with ``man`` (:issue:`9552`).
- fish no longer crashes when searching history for non-ASCII codepoints case-insensitively (:issue:`9628`).
- The :kbd:`Alt-S` binding will now also use ``please`` if available (:issue:`9635`).
- The :kbd:`alt-s` binding will now also use ``please`` if available (:issue:`9635`).
- Themes that don't specify every color option can be installed correctly in the Web-based configuration (:issue:`9590`).
- Compatibility with Midnight Commander's prompt integration has been improved (:issue:`9540`).
- A spurious error, noted when using fish in Google Drive directories under WSL 2, has been silenced (:issue:`9550`).
@@ -252,8 +847,8 @@ fish 3.6.0 (released January 7, 2023)
Notable improvements and fixes
------------------------------
- By default, :kbd:`Control-R` now opens the command history in the pager (:issue:`602`). This is fully searchable and syntax-highlighted, as an alternative to the incremental search seen in other shells. The new special input function ``history-pager`` has been added for custom bindings.
- Abbrevations are more flexible (:issue:`9313`, :issue:`5003`, :issue:`2287`):
- By default, :kbd:`ctrl-r` now opens the command history in the pager (:issue:`602`). This is fully searchable and syntax-highlighted, as an alternative to the incremental search seen in other shells. The new special input function ``history-pager`` has been added for custom bindings.
- Abbreviations are more flexible (:issue:`9313`, :issue:`5003`, :issue:`2287`):
- They may optionally replace tokens anywhere on the command line, instead of only commands
- Matching tokens may be described using a regular expression instead of a literal word
@@ -348,15 +943,15 @@ Interactive improvements
- If the terminal definition for :envvar:`TERM` can't be found, fish now tries using the "xterm-256color" and "xterm" definitions before "ansi" and "dumb". As the majority of terminal emulators in common use are now more or less xterm-compatible (often even explicitly claiming the xterm-256color entry), this should often result in a fully or almost fully usable terminal (:issue:`9026`).
- A new variable, :envvar:`fish_cursor_selection_mode`, can be used to configure whether the command line selection includes the character under the cursor (``inclusive``) or not (``exclusive``). The new default is ``exclusive``; use ``set fish_cursor_selection_mode inclusive`` to get the previous behavior back (:issue:`7762`).
- fish's completion pager now fills half the terminal on first tab press instead of only 4 rows, which should make results visible more often and save key presses, without constantly snapping fish to the top of the terminal (:issue:`9105`, :issue:`2698`).
- The ``complete-and-search`` binding, used with :kbd:`Shift-Tab` by default, selects the first item in the results immediately (:issue:`9080`).
- ``bind`` output is now syntax-highlighted when used interacively.
- :kbd:`Alt-H` (the default ``__fish_man_page`` binding) does a better job of showing the manual page of the command under cursor (:issue:`9020`).
- The ``complete-and-search`` binding, used with :kbd:`shift-tab` by default, selects the first item in the results immediately (:issue:`9080`).
- ``bind`` output is now syntax-highlighted when used interactively.
- :kbd:`alt-h` (the default ``__fish_man_page`` binding) does a better job of showing the manual page of the command under cursor (:issue:`9020`).
- If :envvar:`fish_color_valid_path` contains an actual color instead of just modifiers, those will be used for valid paths even if the underlying color isn't "normal" (:issue:`9159`).
- The key combination for the QUIT terminal sequence, often :kbd:`Control-Backslash` (``\x1c``), can now be sused as a binding (:issue:`9234`).
- The key combination for the QUIT terminal sequence, often :kbd:`ctrl-\\` (``\x1c``), can now be used as a binding (:issue:`9234`).
- fish's vi mode uses normal xterm-style sequences to signal cursor change, instead of using the iTerm's proprietary escape sequences. This allows for a blinking cursor and makes it work in complicated scenarios with nested terminals. (:issue:`3741`, :issue:`9172`)
- When running fish on a remote system (such as inside SSH or a container), :kbd:`Control-X` now copies to the local client system's clipboard if the terminal supports OSC 52.
- When running fish on a remote system (such as inside SSH or a container), :kbd:`ctrl-x` now copies to the local client system's clipboard if the terminal supports OSC 52.
- ``commandline`` gained two new options, ``--selection-start`` and ``--selection-end``, to set the start/end of the current selection (:issue:`9197`, :issue:`9215`).
- fish's builtins now handle keyboard interrupts (:kbd:`Control-C`) correctly (:issue:`9266`).
- fish's builtins now handle keyboard interrupts (:kbd:`ctrl-c`) correctly (:issue:`9266`).
Completions
^^^^^^^^^^^
@@ -466,9 +1061,9 @@ This release of fish introduces the following small enhancements:
This release also fixes a number of problems identified in fish 3.5.0.
- Completing ``git blame`` or ``git -C`` works correctly (:issue:`9053`).
- On terminals that emit a ``CSI u`` sequence for :kbd:`Shift-Space`, fish inserts a space instead of printing an error. (:issue:`9054`).
- On terminals that emit a ``CSI u`` sequence for :kbd:`shift-space`, fish inserts a space instead of printing an error. (:issue:`9054`).
- ``status fish-path`` on Linux-based platforms could print the path with a " (deleted)" suffix (such as ``/usr/bin/fish (deleted)``), which is now removed (:issue:`9019`).
- Cancelling an initial command (from fish's ``--init-command`` option) with :kbd:`Control-C` no longer prevents configuration scripts from running (:issue:`9024`).
- Cancelling an initial command (from fish's ``--init-command`` option) with :kbd:`ctrl-c` no longer prevents configuration scripts from running (:issue:`9024`).
- The job summary contained extra blank lines if the prompt used multiple lines, which is now fixed (:issue:`9044`).
- Using special input functions in bindings, in combination with ``and``/``or`` conditionals, no longer crashes (:issue:`9051`).
@@ -566,7 +1161,7 @@ Interactive improvements
- The ``vared`` command can now successfully edit variables named "tmp" or "prompt" (:issue:`8836`, :issue:`8837`).
- ``time`` now emits an error if used after the first command in a pipeline (:issue:`8841`).
- ``fish_add_path`` now prints a message for skipped non-existent paths when using the ``-v`` flag (:issue:`8884`).
- Since fish 3.2.0, pressing :kbd:`Control-D` while a command is running would end up inserting a space into the next commandline, which has been fixed (:issue:`8871`).
- Since fish 3.2.0, pressing :kbd:`ctrl-d` while a command is running would end up inserting a space into the next commandline, which has been fixed (:issue:`8871`).
- A bug that caused multi-line prompts to be moved down a line when pasting or switching modes has been fixed (:issue:`3481`).
- The Web-based configuration system no longer strips too many quotes in the abbreviation display (:issue:`8917`, :issue:`8918`).
- Fish started with ``--no-config`` will now use the default keybindings (:issue:`8493`)
@@ -577,10 +1172,10 @@ Interactive improvements
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- The :kbd:`Alt-S` binding will now insert ``doas`` instead of ``sudo`` if necessary (:issue:`8942`).
- The ``kill-whole-line`` special input function now kills the newline preceeding the last line. This makes ``dd`` in vi-mode clear the last line properly.
- The :kbd:`alt-s` binding will now insert ``doas`` instead of ``sudo`` if necessary (:issue:`8942`).
- The ``kill-whole-line`` special input function now kills the newline preceding the last line. This makes ``dd`` in vi-mode clear the last line properly.
- The new ``kill-inner-line`` special input function kills the line without any newlines, allowing ``cc`` in vi-mode to clear the line while preserving newlines (:issue:`8983`).
- On terminals that emit special sequences for these combinations, :kbd:`Shift-Space` is bound like :kbd:`Space`, and :kbd:`Ctrl-Return` is bound like :kbd:`Return` (:issue:`8874`).
- On terminals that emit special sequences for these combinations, :kbd:`shift-space` is bound like :kbd:`space`, and :kbd:`ctrl-enter` is bound like :kbd:`return` (:issue:`8874`).
Improved prompts
^^^^^^^^^^^^^^^^
@@ -626,7 +1221,7 @@ This release of fish fixes the following problems identified in fish 3.4.0:
- An error printed after upgrading, where old instances could pick up a newer version of the ``fish_title`` function, has been fixed (:issue:`8778`)
- fish builds correctly on NetBSD (:issue:`8788`) and OpenIndiana (:issue:`8780`).
- ``nextd-or-forward-word``, bound to :kbd:`Alt-Right Arrow` by default, was inadvertently changed to move like ``forward-bigword``. This has been corrected (:issue:`8790`).
- ``nextd-or-forward-word``, bound to :kbd:`alt-right` by default, was inadvertently changed to move like ``forward-bigword``. This has been corrected (:issue:`8790`).
- ``funcsave -q`` and ``funcsave --quiet`` now work correctly (:issue:`8830`).
- Issues with the ``csharp`` and ``nmcli`` completions were corrected.
@@ -687,7 +1282,7 @@ Deprecations and removed features
> set -Ua fish_features ampersand-nobg-in-token
- ``$status`` is now forbidden as a command, to prevent a surprisingly common error among new users: Running ``if $status`` (:issue:`8171`). This applies *only* to ``$status``, other variables are still allowed.
- ``set --query`` now returns an exit status of 255 if given no variable names. This means ``if set -q $foo`` will not enter the if-block if ``$foo`` is empty or unset. To restore the previous behavior, use ``if not set -q foo; or set -q $foo`` - but this is unlikely to be desireable (:issue:`8214`).
- ``set --query`` now returns an exit status of 255 if given no variable names. This means ``if set -q $foo`` will not enter the if-block if ``$foo`` is empty or unset. To restore the previous behavior, use ``if not set -q foo; or set -q $foo`` - but this is unlikely to be desirable (:issue:`8214`).
- ``_`` is now a reserved keyword (:issue:`8342`).
- The special input functions ``delete-or-exit``, ``nextd-or-forward-word`` and ``prevd-or-backward-word`` replace fish functions of the same names (:issue:`8538`).
- Mac OS X 10.9 is no longer supported. The minimum Mac version is now 10.10 "Yosemite."
@@ -710,7 +1305,7 @@ Scripting improvements
- ``commandline`` gained a ``--paging-full-mode`` option to check if the pager is showing all the possible lines (no "7 more rows" message) (:issue:`8485`).
- List expansion correctly reports an error when used with all zero indexes (:issue:`8213`).
- Running ``fish`` with a directory instead of a script as argument (eg ``fish .``) no longer leads to an infinite loop. Instead it errors out immediately (:issue:`8258`)
- Some error messages occuring after fork, like "text file busy" have been replaced by bespoke error messages for fish (like "File is currently open for writing"). This also restores error messages with current glibc versions that removed sys_errlist (:issue:`8234`, :issue:`4183`).
- Some error messages occurring after fork, like "text file busy" have been replaced by bespoke error messages for fish (like "File is currently open for writing"). This also restores error messages with current glibc versions that removed sys_errlist (:issue:`8234`, :issue:`4183`).
- The ``realpath`` builtin now also squashes leading slashes with the ``--no-symlinks`` option (:issue:`8281`).
- When trying to ``cd`` to a dangling (broken) symbolic link, fish will print an error noting that the target is a broken link (:issue:`8264`).
- On MacOS terminals that are not granted permissions to access a folder, ``cd`` would print a spurious "rotten symlink" error, which has been corrected to "permission denied" (:issue:`8264`).
@@ -732,10 +1327,10 @@ Scripting improvements
Interactive improvements
------------------------
- Vi mode cursors are now set properly after :kbd:`Control-C` (:issue:`8125`).
- Vi mode cursors are now set properly after :kbd:`ctrl-c` (:issue:`8125`).
- ``funced`` will try to edit the whole file containing a function definition, if there is one (:issue:`391`).
- Running a command line consisting of just spaces now deletes an ephemeral (starting with space) history item again (:issue:`8232`).
- Command substitutions no longer respect job control, instead running inside fish's own process group (:issue:`8172`). This more closely matches other shells, and improves :kbd:`Control-C` reliability inside a command substitution.
- Command substitutions no longer respect job control, instead running inside fish's own process group (:issue:`8172`). This more closely matches other shells, and improves :kbd:`ctrl-c` reliability inside a command substitution.
- ``history`` and ``__fish_print_help`` now properly support ``less`` before version 530, including the version that ships with macOS. (:issue:`8157`).
- ``help`` now knows which section is in which document again (:issue:`8245`).
- fish's highlighter will now color options (starting with ``-`` or ``--``) with the color given in the new $fish_color_option, up to the first ``--``. It falls back on $fish_color_param, so nothing changes for existing setups (:issue:`8292`).
@@ -748,7 +1343,7 @@ Interactive improvements
- Propagation of universal variables from a fish process that is closing is faster (:issue:`8209`).
- The command line is drawn in the correct place if the prompt ends with a newline (:issue:`8298`).
- ``history`` learned a new subcommand ``clear-session`` to erase all history from the current session (:issue:`5791`).
- Pressing :kbd:`Control-C` in ``fish_key_reader`` will no longer print the incorrect "Press [ctrl-C] again to exit" message (:issue:`8510`).
- Pressing :kbd:`ctrl-c` in ``fish_key_reader`` will no longer print the incorrect "Press [ctrl-C] again to exit" message (:issue:`8510`).
- The default command-not-found handler for Fedora/PackageKit now passes the whole command line, allowing for functionality such as running the suggested command directly (:issue:`8579`).
- When looking for locale information, the Debian configuration is now used when available (:issue:`8557`).
- Pasting text containing quotes from the clipboard trims spaces more appropriately (:issue:`8550`).
@@ -761,8 +1356,8 @@ Interactive improvements
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- :kbd:`Escape` can now bound without breaking arrow key bindings (:issue:`8428`).
- The :kbd:`Alt-H` binding (to open a commands manual page) now also ignores ``command`` (:issue:`8447`).
- :kbd:`escape` can now bound without breaking arrow key bindings (:issue:`8428`).
- The :kbd:`alt-h` binding (to open a commands manual page) now also ignores ``command`` (:issue:`8447`).
Improved prompts
^^^^^^^^^^^^^^^^
@@ -828,7 +1423,7 @@ Improved terminal support
- Vi mode cursors are enabled in Apple Terminal.app (:issue:`8167`).
- Vi cursor shaping and $PWD reporting is now also enabled on foot (:issue:`8422`).
- ``ls`` will use colors also on newer versions of Apple Terminal.app (:issue:`8309`).
- The :kbd:`Delete` and :kbd:`Shift-Tab` keys work more reliably under ``st`` (:issue:`8352`, :issue:`8354`).
- The :kbd:`delete` and :kbd:`shift-tab` keys work more reliably under ``st`` (:issue:`8352`, :issue:`8354`).
Other improvements
------------------
@@ -855,7 +1450,7 @@ This release of fish fixes the following problems identified in fish 3.3.0:
- The prompt and command line are redrawn correctly in response to universal variable changes (:issue:`8088`).
- A superfluous error that was produced when setting the ``PATH`` or ``CDPATH`` environment variables to include colon-delimited components that do not exist was removed (:issue:`8095`).
- The Vi mode indicator in the prompt is repainted correctly after :kbd:`Ctrl-C` cancels the current command (:issue:`8103`).
- The Vi mode indicator in the prompt is repainted correctly after :kbd:`ctrl-c` cancels the current command (:issue:`8103`).
- fish builds correctly on platforms that do not have a ``spawn.h`` header, such as old versions of OS X (:issue:`8097`).
A number of improvements to the documentation, and fixes for completions, are included as well.
@@ -925,15 +1520,15 @@ Interactive improvements
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- Pasting in Vi mode puts text in the right place in normal mode (:issue:`7847`).
- Vi mode's :kbd:`u` is bound to ``undo`` instead of ``history-search-backward``, following GNU readline's behavior. Similarly, :kbd:`Control-R` is bound to ``redo`` instead of ``history-search-backward``, following Vim (:issue:`7908`).
- Vi mode's :kbd:`u` is bound to ``undo`` instead of ``history-search-backward``, following GNU readline's behavior. Similarly, :kbd:`ctrl-r` is bound to ``redo`` instead of ``history-search-backward``, following Vim (:issue:`7908`).
- :kbd:`s` in Vi visual mode now does the same thing as :kbd:`c` (:issue:`8039`).
- The binding for :kbd:`"*y` now uses ``fish_clipboard_copy``, allowing it to support more than just ``xsel``.
- The :kbd:`Control-Space` binding can be correctly customised (:issue:`7922`).
- The binding for :kbd:`",*,y` now uses ``fish_clipboard_copy``, allowing it to support more than just ``xsel``.
- The :kbd:`ctrl-space` binding can be correctly customised (:issue:`7922`).
- ``exit`` works correctly in bindings (:issue:`7967`).
- The :kbd:`F1` binding, which opens the manual page for the current command, now works around a bug in certain ``less`` versions that fail to clear the screen (:issue:`7863`).
- The binding for :kbd:`Alt-S` now toggles whether ``sudo`` is prepended, even when it took the commandline from history instead of only adding it.
- The :kbd:`f1` binding, which opens the manual page for the current command, now works around a bug in certain ``less`` versions that fail to clear the screen (:issue:`7863`).
- The binding for :kbd:`alt-s` now toggles whether ``sudo`` is prepended, even when it took the commandline from history instead of only adding it.
- The new functions ``fish_commandline_prepend`` and ``fish_commandline_append`` allow toggling the presence of a prefix/suffix on the current commandline. (:issue:`7905`).
- ``backward-kill-path-component`` :kbd:`Control-W`) no longer erases parts of two tokens when the cursor is positioned immediately after ``/``. (:issue:`6258`).
- ``backward-kill-path-component`` :kbd:`ctrl-w`) no longer erases parts of two tokens when the cursor is positioned immediately after ``/``. (:issue:`6258`).
Improved prompts
^^^^^^^^^^^^^^^^
@@ -1049,8 +1644,8 @@ Notable improvements and fixes
…h-shell/build (makepkg)>
It is still possible to react to the ``COLUMNS`` variable inside the prompt to implement smarter behavior.
- **fish completes ambiguous completions** after pressing :kbd:`Tab` even when they
have a common prefix, without the user having to press :kbd:`Tab` again
- **fish completes ambiguous completions** after pressing :kbd:`tab` even when they
have a common prefix, without the user having to press :kbd:`tab` again
(:issue:`6924`).
- fish is less aggressive about resetting terminal modes, such as flow control, after every command.
Although flow control remains off by default, enterprising users can now enable it with
@@ -1176,7 +1771,7 @@ Interactive improvements
- The interactive reader now allows ending a line in a logical operators (``&&`` and ``||``) instead of complaining about a missing command. (This was already syntactically valid, but interactive sessions didn't know about it yet).
- The prompt is reprinted after a background job exits (:issue:`1018`).
- fish no longer inserts a space after a completion ending in ``.``, ``,`` or ``-`` is accepted, improving completions for tools that provide dynamic completions (:issue:`6928`).
- If a filename is invalid when first pressing :kbd:`Tab`, but becomes valid, it will be completed properly on the next attempt (:issue:`6863`).
- If a filename is invalid when first pressing :kbd:`tab`, but becomes valid, it will be completed properly on the next attempt (:issue:`6863`).
- ``help string match/replace/<subcommand>`` will show the help for string subcommands (:issue:`6786`).
- ``fish_key_reader`` sets the exit status to 0 when used with ``--help`` or ``--version`` (:issue:`6964`).
- ``fish_key_reader`` and ``fish_indent`` send output from ``--version`` to standard output, matching other fish binaries (:issue:`6964`).
@@ -1213,15 +1808,15 @@ Interactive improvements
When it can't find a command, fish now just executes a function called ``fish_command_not_found``
instead of firing an event, making it easier to replace and reason about.
Previously-defined ``__fish_command_not_found_handler`` functions with an appropriate event listener will still work (:issue:`7293`).
- :kbd:`Control-C` handling has been reimplemented in C++ and is therefore quicker (:issue:`5259`), no longer occasionally prints an "unknown command" error (:issue:`7145`) or overwrites multiline prompts (:issue:`3537`).
- :kbd:`Control-C` no longer kills background jobs for which job control is
- :kbd:`ctrl-c` handling has been reimplemented in C++ and is therefore quicker (:issue:`5259`), no longer occasionally prints an "unknown command" error (:issue:`7145`) or overwrites multiline prompts (:issue:`3537`).
- :kbd:`ctrl-c` no longer kills background jobs for which job control is
disabled, matching POSIX semantics (:issue:`6828`, :issue:`6861`).
- Autosuggestions work properly after :kbd:`Control-C` cancels the current commmand line (:issue:`6937`).
- Autosuggestions work properly after :kbd:`ctrl-c` cancels the current command line (:issue:`6937`).
- History search is now case-insensitive unless the search string contains an uppercase character (:issue:`7273`).
- ``fish_update_completions`` gained a new ``--keep`` option, which improves speed by skipping completions that already exist (:issue:`6775`, :issue:`6796`).
- Aliases containing an embedded backslash appear properly in the output of ``alias`` (:issue:`6910`).
- ``open`` no longer hangs indefinitely on certain systems, as a bug in ``xdg-open`` has been worked around (:issue:`7215`).
- Long command lines no longer add a blank line after execution (:issue:`6826`) and behave better with :kbd:`Backspace` (:issue:`6951`).
- Long command lines no longer add a blank line after execution (:issue:`6826`) and behave better with :kbd:`backspace` (:issue:`6951`).
- ``functions -t`` works like the long option ``--handlers-type``, as documented, instead of producing an error (:issue:`6985`).
- History search now flashes when it found no more results (:issue:`7362`)
- fish now creates the path in the environment variable ``XDG_RUNTIME_DIR`` if it does not exist, before using it for runtime data storage (:issue:`7335`).
@@ -1258,27 +1853,27 @@ Interactive improvements
New or improved bindings
^^^^^^^^^^^^^^^^^^^^^^^^
- As mentioned above, new special input functions ``undo`` (:kbd:`Control+\_` or :kbd:`Control+Z`) and ``redo`` (:kbd:`Alt-/`) can be used to revert changes to the command line or the pager search field (:issue:`6570`).
- :kbd:`Control-Z` is now available for binding (:issue:`7152`).
- Additionally, using the ``cancel`` special input function (bound to :kbd:`Escape` by default) right after fish picked an unambiguous completion will undo that (:issue:`7433`).
- ``fish_clipboard_paste`` (:kbd:`Control+V`) trims indentation from multiline commands, because fish already indents (:issue:`7662`).
- As mentioned above, new special input functions ``undo`` (:kbd:`ctrl-_` or :kbd:`ctrl-z`) and ``redo`` (:kbd:`alt-/`) can be used to revert changes to the command line or the pager search field (:issue:`6570`).
- :kbd:`ctrl-z` is now available for binding (:issue:`7152`).
- Additionally, using the ``cancel`` special input function (bound to :kbd:`escape` by default) right after fish picked an unambiguous completion will undo that (:issue:`7433`).
- ``fish_clipboard_paste`` (:kbd:`ctrl-v`) trims indentation from multiline commands, because fish already indents (:issue:`7662`).
- Vi mode bindings now support ``dh``, ``dl``, ``c0``, ``cf``, ``ct``, ``cF``, ``cT``, ``ch``, ``cl``, ``y0``, ``ci``, ``ca``, ``yi``, ``ya``, ``di``, ``da``, ``d;``, ``d,``, ``o``, ``O`` and Control+left/right keys to navigate by word (:issue:`6648`, :issue:`6755`, :issue:`6769`, :issue:`7442`, :issue:`7516`).
- Vi mode bindings support :kbd:`~` (tilde) to toggle the case of the selected character (:issue:`6908`).
- Functions ``up-or-search`` and ``down-or-search`` (:kbd:`Up` and :kbd:`Down`) can cross empty lines, and don't activate search mode if the search fails, which makes them easier to use to move between lines in some situations.
- Functions ``up-or-search`` and ``down-or-search`` (:kbd:`up` and :kbd:`down`) can cross empty lines, and don't activate search mode if the search fails, which makes them easier to use to move between lines in some situations.
- If history search fails to find a match, the cursor is no longer moved. This is useful when accidentally starting a history search on a multi-line commandline.
- The special input function ``beginning-of-history`` (:kbd:`Page Up`) now moves to the oldest search instead of the youngest - that's ``end-of-history`` (:kbd:`Page Down`).
- The special input function ``beginning-of-history`` (:kbd:`pageup`) now moves to the oldest search instead of the youngest - that's ``end-of-history`` (:kbd:`pagedown`).
- A new special input function ``forward-single-char`` moves one character to the right, and if an autosuggestion is available, only take a single character from it (:issue:`7217`, :issue:`4984`).
- Special input functions can now be joined with ``or`` as a modifier (adding to ``and``), though only some commands set an exit status (:issue:`7217`). This includes ``suppress-autosuggestion`` to reflect whether an autosuggestion was suppressed (:issue:`1419`)
- A new function ``__fish_preview_current_file``, bound to :kbd:`Alt+O`, opens the
- A new function ``__fish_preview_current_file``, bound to :kbd:`alt-o`, opens the
current file at the cursor in a pager (:issue:`6838`, :issue:`6855`).
- ``edit_command_buffer`` (:kbd:`Alt-E` and :kbd:`Alt-V`) passes the cursor position
- ``edit_command_buffer`` (:kbd:`alt-e` and :kbd:`alt-v`) passes the cursor position
to the external editor if the editor is recognized (:issue:`6138`, :issue:`6954`).
- ``__fish_prepend_sudo`` (:kbd:`Alt-S`) now toggles a ``sudo`` prefix (:issue:`7012`) and avoids shifting the cursor (:issue:`6542`).
- ``__fish_prepend_sudo`` (:kbd:`Alt-S`) now uses the previous commandline if the current one is empty,
- ``__fish_prepend_sudo`` (:kbd:`alt-s`) now toggles a ``sudo`` prefix (:issue:`7012`) and avoids shifting the cursor (:issue:`6542`).
- ``__fish_prepend_sudo`` (:kbd:`alt-s`) now uses the previous commandline if the current one is empty,
to simplify rerunning the previous command with ``sudo`` (:issue:`7079`).
- ``__fish_toggle_comment_commandline`` (:kbd:`Alt-#`) now uncomments and presents the last comment
- ``__fish_toggle_comment_commandline`` (:kbd:`alt-#`) now uncomments and presents the last comment
from history if the commandline is empty (:issue:`7137`).
- ``__fish_whatis_current_token`` (:kbd:`Alt-W`) prints descriptions for functions and builtins (:issue:`7191`, :issue:`2083`).
- ``__fish_whatis_current_token`` (:kbd:`alt-w`) prints descriptions for functions and builtins (:issue:`7191`, :issue:`2083`).
- The definition of "word" and "bigword" for movements was refined, fixing (eg) vi mode's behavior with :kbd:`e` on the second-to-last char, and bigword's behavior with single-character words and non-blank non-graphical characters (:issue:`7353`, :issue:`7354`, :issue:`4025`, :issue:`7328`, :issue:`7325`)
- fish's clipboard bindings now also support Windows Subsystem for Linux via PowerShell and clip.exe (:issue:`7455`, :issue:`7458`) and will properly copy newlines in multi-line commands.
- Using the ``*-jump`` special input functions before typing anything else no longer crashes fish.
@@ -1770,7 +2365,7 @@ Interactive improvements
argument.
- Syntax highlighting works correctly with variables as commands
(:issue:`5658`) and redirections to close file descriptors (:issue:`6092`).
- ``help`` works properly on Windows Subsytem for Linux (:issue:`5759`, :issue:`6338`).
- ``help`` works properly on Windows Subsystem for Linux (:issue:`5759`, :issue:`6338`).
- A bug where ``disown`` could crash the shell has been fixed (:issue:`5720`).
- fish will not autosuggest files ending with ``~`` unless there are no
other candidates, as these are generally backup files (:issue:`985`).
@@ -2370,7 +2965,7 @@ Interactive improvements
key both on its own and as part of a control sequence, was applied to
all control characters; this has been reduced to just the escape key.
- Completing a function shows the description properly (:issue:`5206`).
- `commandline` can now be used to set the commandline for the next command, restoring a behavior in 3.4.1 (:issue:`8807`).
- ``commandline`` can now be used to set the commandline for the next command, restoring a behavior in 3.4.1 (:issue:`8807`).
- Added completions for
- ``ansible``, including ``ansible-galaxy``, ``ansible-playbook``
@@ -2712,7 +3307,7 @@ Other significant changes
- Some systems ``su`` implementations do not set the ``USER``
environment variable; it is now reset for root users (:issue:`3916`).
- Under terminals which support it, bracketed paste is enabled,
escaping problematic characters for security and convience (:issue:`3871`).
escaping problematic characters for security and convenience (:issue:`3871`).
Inside single quotes (``'``), single quotes and backslashes in pasted
text are escaped (:issue:`967`). The ``fish_clipboard_paste`` function (bound
to ``C-v`` by default) is still the recommended pasting method where
@@ -2841,9 +3436,9 @@ Other significant changes
- fish no longer prints a warning when it identifies a running instance
of an old version (2.1.0 and earlier). Changes to universal variables
may not propagate between these old versions and 2.5b1.
- Improved compatiblity with Android (:issue:`3585`), MSYS/mingw (:issue:`2360`), and
- Improved compatibility with Android (:issue:`3585`), MSYS/mingw (:issue:`2360`), and
Solaris (:issue:`3456`, :issue:`3340`).
- Like other shells, the ``test`` builting now returns an error for
- Like other shells, the ``test`` built-in now returns an error for
numeric operations on invalid integers (:issue:`3346`, :issue:`3581`).
- ``complete`` no longer recognises ``--authoritative`` and
``--unauthoritative`` options, and they are marked as obsolete.
@@ -3191,8 +3786,8 @@ Other notable fixes and improvements
- Directory autosuggestions will now descend as far as possible if
there is only one child directory (:issue:`2531`)
- Add support for bright colors (:issue:`1464`)
- Allow Ctrl-J (`\cj`) to be bound separately from Ctrl-M
(`\cm`) (:issue:`217`)
- Allow Ctrl-J (``\cj``) to be bound separately from Ctrl-M
(``\cm``) (:issue:`217`)
- psub now has a “-s”/“suffix” option to name the temporary file with
that suffix
- Enable 24-bit colors on select terminals (:issue:`2495`)
@@ -3336,7 +3931,7 @@ Other notable fixes and improvements
- ``type`` has a new ``-q`` option to suppress output (:issue:`1540` and, like
other shells, ``type -a`` now prints all matches for a command
(:issue:`261`).
- Pressing F1 now shows the manual page for the current command
- Pressing :kbd:`f1` now shows the manual page for the current command
(:issue:`1063`).
- ``fish_title`` functions have access to the arguments of the
currently running argument as ``$argv[1]`` (:issue:`1542`).

View File

@@ -1,148 +1,29 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.15)
if(POLICY CMP0066)
cmake_policy(SET CMP0066 OLD)
endif()
if(POLICY CMP0067)
cmake_policy(SET CMP0067 NEW)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(cmake/Mac.cmake)
project(fish)
project(fish LANGUAGES C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# We are C++11.
set(CMAKE_CXX_STANDARD 11)
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
# Generate Xcode schemas (but not for tests).
set(CMAKE_XCODE_GENERATE_SCHEME 1)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to default '${DEFAULT_BUILD_TYPE}'")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
endif()
# Error out when linking statically, it doesn't work.
if (CMAKE_EXE_LINKER_FLAGS MATCHES ".*-static.*")
message(FATAL_ERROR "Fish does not support static linking")
endif()
# Set up standard directories.
include(GNUInstallDirs)
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
# Rationale in https://github.com/ninja-build/ninja/issues/814
if (CMAKE_GENERATOR STREQUAL "Ninja" AND
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)))
add_compile_options(-fdiagnostics-color=always)
endif()
# Set up PCRE2
# This sets an environment variable that needs to be available before the Rust stanzas
include(cmake/PCRE2.cmake)
# Enable a whole bunch of warnings, but turn off:
# - comment because we use a bunch of those, and they're not really all that harmful.
# - address, because that occurs for our mkostemp check (weak-linking requires us to compare `&mkostemp == nullptr`).
add_compile_options(-Wall -Wextra -Wno-comment -Wno-address)
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
add_compile_options(-Wunused-template -Wunused-local-typedef -Wunused-macros)
endif()
# Disable exception handling.
add_compile_options(-fno-exceptions)
# Undefine NDEBUG to keep assert() in release builds.
add_definitions(-UNDEBUG)
# Enable large files on GNU.
add_definitions(-D_LARGEFILE_SOURCE
-D_LARGEFILE64_SOURCE
-D_FILE_OFFSET_BITS=64
-D_ATFILE_SOURCE)
# Hide the CMake Rules directories in Xcode projects.
source_group("CMake Rules" REGULAR_EXPRESSION "^$")
# Put source and header files at top level under targets.
source_group("Source Files" REGULAR_EXPRESSION ".*\\.cpp")
source_group("Header Files" REGULAR_EXPRESSION ".*\\.h")
source_group("Builtins" "builtins/")
# Support folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(cmake/Rust.cmake)
# Work around issue where archive-built libs go in the wrong place.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
set(FISH_IN_TREE_BUILD TRUE)
else()
set(FISH_IN_TREE_BUILD FALSE)
endif()
# NetBSD does weird things with finding libraries,
# making the tests fail by failing to find pcre.
#
# Keep the rpath used to build.
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
# List of sources for builtin functions.
set(FISH_BUILTIN_SRCS
src/builtin.cpp src/builtins/abbr.cpp src/builtins/argparse.cpp
src/builtins/bg.cpp src/builtins/bind.cpp src/builtins/block.cpp
src/builtins/builtin.cpp src/builtins/cd.cpp src/builtins/command.cpp
src/builtins/commandline.cpp src/builtins/complete.cpp src/builtins/contains.cpp
src/builtins/disown.cpp src/builtins/echo.cpp src/builtins/emit.cpp
src/builtins/eval.cpp src/builtins/exit.cpp src/builtins/fg.cpp
src/builtins/function.cpp src/builtins/functions.cpp src/builtins/history.cpp
src/builtins/jobs.cpp src/builtins/math.cpp src/builtins/printf.cpp src/builtins/path.cpp
src/builtins/pwd.cpp src/builtins/random.cpp src/builtins/read.cpp
src/builtins/realpath.cpp src/builtins/return.cpp src/builtins/set.cpp
src/builtins/set_color.cpp src/builtins/source.cpp src/builtins/status.cpp
src/builtins/string.cpp src/builtins/test.cpp src/builtins/type.cpp src/builtins/ulimit.cpp
src/builtins/wait.cpp)
# List of other sources.
set(FISH_SRCS
src/ast.cpp src/abbrs.cpp src/autoload.cpp src/color.cpp src/common.cpp src/complete.cpp
src/env.cpp src/env_dispatch.cpp src/env_universal_common.cpp src/event.cpp
src/exec.cpp src/expand.cpp src/fallback.cpp src/fd_monitor.cpp src/fish_version.cpp
src/flog.cpp src/function.cpp src/future_feature_flags.cpp src/highlight.cpp
src/history.cpp src/history_file.cpp src/input.cpp src/input_common.cpp
src/io.cpp src/iothread.cpp src/job_group.cpp src/kill.cpp
src/null_terminated_array.cpp src/operation_context.cpp src/output.cpp
src/pager.cpp src/parse_execution.cpp src/parse_tree.cpp src/parse_util.cpp
src/parser.cpp src/parser_keywords.cpp src/path.cpp src/postfork.cpp
src/proc.cpp src/re.cpp src/reader.cpp src/redirection.cpp src/screen.cpp
src/signal.cpp src/termsize.cpp src/timer.cpp src/tinyexpr.cpp
src/tokenizer.cpp src/topic_monitor.cpp src/trace.cpp src/utf8.cpp src/util.cpp
src/wait_handle.cpp src/wcstringutil.cpp src/wgetopt.cpp src/wildcard.cpp
src/wutil.cpp src/fds.cpp
)
# Header files are just globbed.
file(GLOB FISH_HEADERS src/*.h)
# Set up config.h
include(cmake/ConfigureChecks.cmake)
include(cmake/gettext.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config_cmake.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Set up standard directories.
include(GNUInstallDirs)
add_definitions(-D_UNICODE=1
-DLOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}"
-DPREFIX=L"${CMAKE_INSTALL_PREFIX}"
-DDATADIR=L"${CMAKE_INSTALL_FULL_DATADIR}"
-DSYSCONFDIR=L"${CMAKE_INSTALL_FULL_SYSCONFDIR}"
-DBINDIR=L"${CMAKE_INSTALL_FULL_BINDIR}"
-DDOCDIR=L"${CMAKE_INSTALL_FULL_DOCDIR}")
# Set up the machinery around FISH-BUILD-VERSION-FILE
# This defines the FBVF variable.
include(Version)
@@ -153,53 +34,46 @@ get_filename_component(REAL_CMAKE_SOURCE_DIR "${CMAKE_SOURCE_DIR}" REALPATH)
add_definitions(-DCMAKE_BINARY_DIR="${REAL_CMAKE_BINARY_DIR}")
add_definitions(-DCMAKE_SOURCE_DIR="${REAL_CMAKE_SOURCE_DIR}")
# Teach fish_version.o to rebuild when FBVF changes.
# The standard C++ include detection machinery misses this.
set_source_files_properties(src/fish_version.cpp
PROPERTIES OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${FBVF})
set(build_types Release RelWithDebInfo Debug "")
if(NOT "${CMAKE_BUILD_TYPE}" IN_LIST build_types)
message(WARNING "Unsupported build type ${CMAKE_BUILD_TYPE}. If this doesn't build, try one of Release, RelWithDebInfo or Debug")
endif()
# Enable thread-safe errno on Solaris (#5611)
add_definitions(-D_REENTRANT)
# Set up PCRE2
include(cmake/PCRE2.cmake)
# Define a function to link dependencies.
function(FISH_LINK_DEPS_AND_SIGN target)
target_link_libraries(${target} fishlib)
codesign_on_mac(${target})
endfunction(FISH_LINK_DEPS_AND_SIGN)
# Define libfish.a.
add_library(fishlib STATIC ${FISH_SRCS} ${FISH_BUILTIN_SRCS})
target_sources(fishlib PRIVATE ${FISH_HEADERS})
target_link_libraries(fishlib
${CURSES_LIBRARY} ${CURSES_EXTRA_LIBRARY} Threads::Threads ${CMAKE_DL_LIBS}
${PCRE2_LIB} ${Intl_LIBRARIES} ${ATOMIC_LIBRARY})
target_include_directories(fishlib PRIVATE
${CURSES_INCLUDE_DIRS})
# Define a function to build and link dependencies.
function(CREATE_TARGET target)
add_custom_target(
${target} ALL
COMMAND
"${CMAKE_COMMAND}" -E
env ${VARS_FOR_CARGO}
${Rust_CARGO}
build --bin ${target}
$<$<CONFIG:Release>:--release>
$<$<CONFIG:RelWithDebInfo>:--profile=release-with-debug>
--target ${Rust_CARGO_TARGET}
--no-default-features
--features=${FISH_CARGO_FEATURES}
${CARGO_FLAGS}
&&
"${CMAKE_COMMAND}" -E
copy "${rust_target_dir}/${rust_profile}/${target}" "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
USES_TERMINAL
)
endfunction(CREATE_TARGET)
# Define fish.
add_executable(fish src/fish.cpp)
fish_link_deps_and_sign(fish)
create_target(fish)
# Define fish_indent.
add_executable(fish_indent
src/fish_indent.cpp src/print_help.cpp)
fish_link_deps_and_sign(fish_indent)
create_target(fish_indent)
# Define fish_key_reader.
add_executable(fish_key_reader
src/fish_key_reader.cpp src/print_help.cpp)
fish_link_deps_and_sign(fish_key_reader)
create_target(fish_key_reader)
# Set up the docs.
include(cmake/Docs.cmake)
# A helper for running tests.
add_executable(fish_test_helper src/fish_test_helper.cpp)
# Set up tests.
include(cmake/Tests.cmake)
@@ -212,29 +86,5 @@ include(cmake/Install.cmake)
# Mac app.
include(cmake/MacApp.cmake)
# ThreadSanitizer likes to muck with signal handlers, which interferes
# with fish_test_helper printing the ignored signal mask.
# Ensure fish_test_helper does not use TSan.
# Note the environment var is CXXFLAGS, but the CMake var is CMAKE_CXX_FLAGS.
if (CMAKE_CXX_FLAGS MATCHES ".*-fsanitize=thread.*")
target_compile_options(fish_test_helper PRIVATE "-fno-sanitize=all")
target_link_libraries(fish_test_helper "-fno-sanitize=all")
endif()
# Lint targets
# This could be implemented as target properties, but the script has the useful feature of only
# checking the currently-staged commands
# The generator expressions below rebuild the command line for the fishlib targets
# CMake does not support the "iquote" flag - https://gitlab.kitware.com/cmake/cmake/issues/15491
set(LINT_ARGS "-D$<JOIN:$<TARGET_PROPERTY:fishlib,COMPILE_DEFINITIONS>, -D>" "-I$<JOIN:$<TARGET_PROPERTY:fishlib,INCLUDE_DIRECTORIES>, -I>")
add_custom_target(lint
COMMAND build_tools/lint.fish -p ${CMAKE_BINARY_DIR} -- ${LINT_ARGS}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
add_custom_target(lint-all
COMMAND build_tools/lint.fish --all -p ${CMAKE_BINARY_DIR} -- ${LINT_ARGS}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
include(FeatureSummary)
feature_summary(WHAT ALL)

View File

@@ -126,4 +126,3 @@ enforcement ladder](https://github.com/mozilla/diversity).
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

View File

@@ -1,21 +1,63 @@
Guidelines For Developers
=========================
####################
Contributing To Fish
####################
This document provides guidelines for making changes to the fish-shell
project. This includes rules for how to format the code, naming
conventions, et cetera.
This document tells you how you can contribute to fish.
Fish is free and open source software, distributed under the terms of the GPLv2.
Contributions are welcome, and there are many ways to contribute!
Whether you want to change some of the core Rust source, enhance or add a completion script or function,
improve the documentation or translate something, this document will tell you how.
Mailing List
============
Send patches to the public mailing list: mailto:~krobelus/fish-shell@lists.sr.ht.
Archives are available at https://lists.sr.ht/~krobelus/fish-shell/.
GitHub
======
Fish is available on Github, at https://github.com/fish-shell/fish-shell.
First, you'll need an account there, and you'll need a git clone of fish.
Fork it on Github and then run::
git clone https://github.com/<USERNAME>/fish-shell.git
This will create a copy of the fish repository in the directory fish-shell in your current working directory.
Also, for most changes you want to run the tests and so you'd get a setup to compile fish.
For that, you'll require:
- Rust - when in doubt, try rustup
- CMake
- PCRE2 (headers and libraries) - optional, this will be downloaded if missing
- gettext (only the msgfmt tool) - optional, for translation support
- Sphinx - optional, to build the documentation
Of course not everything is required always - if you just want to contribute something to the documentation you'll just need Sphinx,
and if the change is very simple and obvious you can just send it in. Use your judgement!
Once you have your changes, open a pull request on https://github.com/fish-shell/fish-shell/pulls.
Guidelines
==========
In short:
- Be conservative in what you need (``C++11``, few dependencies)
- Use automated tools to help you (including ``make test``, ``build_tools/style.fish`` and ``make lint``)
- Be conservative in what you need (keep to the agreed minimum supported Rust version, limit new dependencies)
- Use automated tools to help you (``build_tools/check.sh``)
Contributing completions
------------------------
========================
Completion scripts are the most common contribution to fish, and they are very welcome.
In general, we'll take all well-written completion scripts for a command that is publically available.
In general, we'll take all well-written completion scripts for a command that is publicly available.
This means no private tools or personal scripts, and we do reserve the right to reject for other reasons.
Before you try to contribute them to fish, consider if the authors of the tool you are completing want to maintain the script instead.
@@ -42,57 +84,21 @@ Put your completion script into share/completions/name-of-command.fish. If you h
If you want to add tests, you probably want to add a littlecheck test. See below for details.
Contributing to fish's C++ core
-------------------------------
Contributing documentation
==========================
Fish uses C++11. Newer C++ features should not be used to make it possible to use on older systems.
The documentation is stored in ``doc_src/``, and written in ReStructured Text and built with Sphinx.
It does not use exceptions, they are disabled at build time with ``-fno-exceptions``.
To build it locally, run from the main fish-shell directory::
Don't introduce new dependencies unless absolutely necessary, and if you do,
please make it optional with graceful failure if possible.
Add any new dependencies to the README.rst under the *Running* and/or *Building* sections.
sphinx-build -j 8 -b html -n doc_src/ /tmp/fish-doc/
Linters
-------
which will build the docs as html in /tmp/fish-doc. You can open it in a browser and see that it looks okay.
Automated analysis tools like cppcheck can point out
potential bugs or code that is extremely hard to understand. They also
help ensure the code has a consistent style and that it avoids patterns
that tend to confuse people.
To make linting the code easy there are two make targets: ``lint``,
to lint any modified but not committed ``*.cpp`` files, and
``lint-all`` to lint all files.
Fish has custom cppcheck rules in the file ``.cppcheck.rule``. These
help catch mistakes such as using ``wcwidth()`` rather than
``fish_wcwidth()``. Please add a new rule if you find similar mistakes
being made.
Suppressing Lint Warnings
~~~~~~~~~~~~~~~~~~~~~~~~~
Once in a while the lint tools emit a false positive warning. For
example, cppcheck might suggest a memory leak is present when that is
not the case. To suppress that cppcheck warning you should insert a line
like the following immediately prior to the line cppcheck warned about:
::
// cppcheck-suppress memleak // addr not really leaked
The explanatory portion of the suppression comment is optional. For
other types of warnings replace “memleak” with the value inside the
parenthesis (e.g., “nullPointerRedundantCheck”) from a warning like the
following:
::
[src/complete.cpp:1727]: warning (nullPointerRedundantCheck): Either the condition 'cmd_node' is redundant or there is possible null pointer dereference: cmd_node.
The builtins and various functions shipped with fish are documented in doc_src/cmds/.
Code Style
----------
==========
To ensure your changes conform to the style rules run
@@ -102,9 +108,9 @@ To ensure your changes conform to the style rules run
before committing your change. That will run our autoformatters:
- ``git-clang-format`` for c++
- ``rustfmt`` for Rust
- ``fish_indent`` (shipped with fish) for fish script
- ``black`` for python
- ``ruff format`` for python
If youve already committed your changes thats okay since it will then
check the files in the most recent commit. This can be useful after
@@ -122,6 +128,20 @@ If you want to check the style of the entire code base run
That command will refuse to restyle any files if you have uncommitted
changes.
Fish Script Style Guide
-----------------------
1. All fish scripts, such as those in the *share/functions* and *tests*
directories, should be formatted using the ``fish_indent`` command.
2. Function names should be in all lowercase with words separated by
underscores. Private functions should begin with an underscore. The
first word should be ``fish`` if the function is unique to fish.
3. The first word of global variable names should generally be ``fish``
for public vars or ``_fish`` for private vars to minimize the
possibility of name clashes with user defined vars.
Configuring Your Editor for Fish Scripts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -158,65 +178,13 @@ made to run fish_indent via e.g.
(add-hook 'fish-mode-hook (lambda ()
(add-hook 'before-save-hook 'fish_indent-before-save)))
Fish Script Style Guide
-----------------------
Rust Style Guide
----------------
1. All fish scripts, such as those in the *share/functions* and *tests*
directories, should be formatted using the ``fish_indent`` command.
2. Function names should be in all lowercase with words separated by
underscores. Private functions should begin with an underscore. The
first word should be ``fish`` if the function is unique to fish.
3. The first word of global variable names should generally be ``fish``
for public vars or ``_fish`` for private vars to minimize the
possibility of name clashes with user defined vars.
C++ Style Guide
---------------
1. The `Google C++ Style
Guide <https://google.github.io/styleguide/cppguide.html>`__ forms
the basis of the fish C++ style guide. There are two major deviations
for the fish project. First, a four, rather than two, space indent.
Second, line lengths up to 100, rather than 80, characters.
2. The ``clang-format`` command is authoritative with respect to
indentation, whitespace around operators, etc.
3. All names in code should be ``small_snake_case``. No Hungarian
notation is used. The names for classes and structs should be
followed by ``_t``.
4. Always attach braces to the surrounding context.
5. Indent with spaces, not tabs and use four spaces per indent.
6. Document the purpose of a function or class with doxygen-style
comment blocks. e.g.:
::
/**
* Sum numbers in a vector.
*
* @param values Container whose values are summed.
* @return sum of `values`, or 0.0 if `values` is empty.
*/
double sum(std::vector<double> & const values) {
...
}
*/
or
::
/// brief description of somefunction()
void somefunction() {
Use ``cargo fmt`` and ``cargo clippy``. Clippy warnings can be turned off if there's a good reason to.
Testing
-------
=======
The source code for fish includes a large collection of tests. If you
are making any changes to fish, running these tests is a good way to make
@@ -230,28 +198,41 @@ regressions in the future (i.e., we dont reintroduce the bug).
The tests can be found in three places:
- src/fish_tests.cpp for tests to the core C++ code
- src/tests for unit tests.
- tests/checks for script tests, run by `littlecheck <https://github.com/ridiculousfish/littlecheck>`__
- tests/pexpects for interactive tests using `pexpect <https://pexpect.readthedocs.io/en/stable/>`__
When in doubt, the bulk of the tests should be added as a littlecheck test in tests/checks, as they are the easiest to modify and run, and much faster and more dependable than pexpect tests. The syntax is fairly self-explanatory. It's a fish script with the expected output in ``# CHECK:`` or ``# CHECKERR:`` (for stderr) comments.
If your littlecheck test has a specific dependency, use ``# REQUIRE: ...`` with a posix sh script.
fish_tests.cpp is mostly useful for unit tests - if you wish to test that a function does the correct thing for given input, use it.
The pexpects are written in python and can simulate input and output to/from a terminal, so they are needed for anything that needs actual interactivity. The runner is in tests/pexpect_helper.py, in case you need to modify something there.
The pexpects are written in python and can simulate input and output to/from a terminal, so they are needed for anything that needs actual interactivity. The runner is in build_tools/pexpect_helper.py, in case you need to modify something there.
These tests can be run via the tests/test_driver.py python script, which will set up the environment.
It sets up a temporary $HOME and also uses it as the current directory, so you do not need to create a temporary directory in them.
If you need a command to do something weird to test something, maybe add it to the ``fish_test_helper`` binary (in tests/fish_test_helper.c), or see if it can already do it.
Local testing
~~~~~~~~~~~~~
-------------
The tests can be run on your local computer on all operating systems.
::
cmake path/to/fish-shell
make test
make fish_run_tests
Or you can run them on a fish, without involving cmake::
cargo build
cargo test # for the unit tests
tests/test_driver.py target/debug # for the script and interactive tests
Here, the first argument to test_driver.py refers to a directory with ``fish``, ``fish_indent`` and ``fish_key_reader`` in it.
In this example we're in the root of the git repo and have run ``cargo build`` without ``--release``, so it's a debug build.
Git hooks
~~~~~~~~~
---------
Since developers sometimes forget to run the tests, it can be helpful to
use git hooks (see githooks(5)) to automate it.
@@ -269,181 +250,165 @@ One possibility is a pre-push hook script like this one:
# Git gives us lines like "refs/heads/frombranch SOMESHA1 refs/heads/tobranch SOMESHA1"
# We're only interested in the branches
isprotected=false
while read from _ to _; do
if [ "x$to" = "xrefs/heads/$protected_branch" ]; then
isprotected=1
if [ "$to" = "refs/heads/$protected_branch" ]; then
isprotected=true
fi
done
if [ "x$isprotected" = x1 ]; then
echo "Running tests before push to master"
make test
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Tests failed for a push to master, we can't let you do that" >&2
exit 1
fi
if "$isprotected"; then
echo "Running checks before push to master"
build_tools/check.sh
fi
exit 0
This will check if the push is to the master branch and, if it is, only
allow the push if running ``make test`` succeeds. In some circumstances
allow the push if running ``build_tools/check.sh`` succeeds. In some circumstances
it may be advisable to circumvent this check with
``git push --no-verify``, but usually that isnt necessary.
To install the hook, place the code in a new file
``.git/hooks/pre-push`` and make it executable.
Coverity Scan
~~~~~~~~~~~~~
Contributing Translations
=========================
We use Coveritys static analysis tool which offers free access to open
source projects. While access to the tool itself is restricted,
fish-shell organization members should know that they can login
`here <https://scan.coverity.com/projects/fish-shell-fish-shell?tab=overview>`__
with their GitHub account. Currently, tests are triggered upon merging
the ``master`` branch into ``coverity_scan_master``. Even if you are not
a fish developer, you can keep an eye on our statistics there.
Fish uses GNU gettext to translate messages from English to other languages.
We use custom tools for extracting messages from source files and to localize at runtime.
This means that we do not have a runtime dependency on the gettext library.
It also means that some features are not supported, such as message context and plurals.
We also expect all files to be UTF-8-encoded.
In practice, this should not matter much for contributing translations.
Installing the Required Tools
-----------------------------
Translation sources are
stored in the ``po`` directory, named ``ll_CC.po``, where ``ll`` is the
two (or possibly three) letter ISO 639-1 language code of the target language
(e.g. ``pt`` for Portuguese). ``CC`` is an ISO 3166 country/territory code,
(e.g. ``BR`` for Brazil).
An example for a valid name is ``pt_BR.po``, indicating Brazilian Portuguese.
These are the files you will interact with when adding translations.
Installing the Linting Tools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adding translations for a new language
--------------------------------------
To install the lint checkers on Mac OS X using Homebrew:
Creating new translations requires the Gettext tools.
More specifically, you will need ``msguniq`` and ``msgmerge`` for creating translations for a new
language.
To create a new translation, run::
::
build_tools/update_translations.fish po/ll_CC.po
brew install cppcheck
This will create a new PO file containing all messages available for translation.
If the file already exists, it will be updated.
To install the lint checkers on Debian-based Linux distributions:
After modifying a PO file, you can recompile fish, and it will integrate the modifications you made.
This requires that the ``msgfmt`` utility is installed (comes as part of ``gettext``).
It is important that the ``localize-messages`` cargo feature is enabled, which it is by default.
You can explicitly enable it using::
::
cargo build --features=localize-messages
sudo apt-get install clang
sudo apt-get install cppcheck
Use environment variables to tell fish which language to use, e.g.::
Installing the Formatting Tools
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LANG=pt_BR.utf8 fish
Mac OS X:
or within the running fish shell::
::
set LANG pt_BR.utf8
brew install clang-format
For more options regarding how to choose languages, see
`the corresponding gettext documentation
<https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html>`__.
One neat thing you can do is set a list of languages to check for translations in the order defined
using the ``LANGUAGE`` variable, e.g.::
Debian-based:
set LANGUAGE pt_BR de_DE
::
to try to translate messages to Portuguese, if that fails try German, and if that fails too you will
see the English version defined in the source code.
sudo apt-get install clang-format
Modifying existing translations
-------------------------------
Message Translations
--------------------
If you want to work on translations for a language which already has a corresponding ``po`` file, it
is sufficient to edit this file. No other changes are necessary.
Fish uses the GNU gettext library to translate messages from English to
other languages.
After recompiling fish, you should be able to see your translations in action. See the previous
section for details.
Editing PO files
----------------
Many tools are available for editing translation files, including
command-line and graphical user interface programs. For simple use, you can use your text editor.
Open up the PO file, for example ``po/sv.po``, and you'll see something like::
msgid "%s: No suitable job\n"
msgstr ""
The ``msgid`` here is the "name" of the string to translate, typically the English string to translate.
The second line (``msgstr``) is where your translation goes.
For example::
msgid "%s: No suitable job\n"
msgstr "%s: Inget passande jobb\n"
Any ``%s`` or ``%d`` are placeholders that fish will use for formatting at runtime. It is important that they match - the translated string should have the same placeholders in the same order.
Also any escaped characters, like that ``\n`` newline at the end, should be kept so the translation has the same behavior.
Our tests run ``msgfmt --check-format /path/to/file``, so they would catch mismatched placeholders - otherwise fish would crash at runtime when the string is about to be used.
Be cautious about blindly updating an existing translation file.
``msgid`` strings should never be updated manually, only by running the appropriate script.
Modifications to strings in source files
----------------------------------------
If a string changes in the sources, the old translations will no longer work.
They will be preserved in the PO files, but commented-out (starting with ``#~``).
If you add/remove/change a translatable strings in a source file,
run ``build_tools/update_translations.fish`` to propagate this to all translation files (``po/*.po``).
This is only relevant for developers modifying the source files of fish or fish scripts.
Setting Code Up For Translations
--------------------------------
All non-debug messages output for user consumption should be marked for
translation. In C++, this requires the use of the ``_`` (underscore)
macro:
translation. In Rust, this requires the use of the ``wgettext!`` or ``wgettext_fmt!``
macros:
::
streams.out.append_format(_(L"%ls: There are no jobs\n"), argv[0]);
streams.out.append(wgettext_fmt!("%s: There are no jobs\n", argv[0]));
All messages in fish script must be enclosed in single or double quote
characters. They must also be translated via a subcommand. This means
characters for our message extraction script to find them.
They must also be translated via a command substitution. This means
that the following are **not** valid:
::
echo (_ hello)
_ "goodbye"
echo (_ hello)
_ "goodbye"
Above should be written like this instead:
::
echo (_ "hello")
echo (_ "goodbye")
echo (_ "hello")
echo (_ "goodbye")
Note that you can use either single or double quotes to enclose the
You can use either single or double quotes to enclose the
message to be translated. You can also optionally include spaces after
the opening parentheses and once again before the closing parentheses.
Creating and updating translations requires the Gettext tools, including
``xgettext``, ``msgfmt`` and ``msgmerge``. Translation sources are
stored in the ``po`` directory, named ``LANG.po``, where ``LANG`` is the
two letter ISO 639-1 language code of the target language (eg ``de`` for
German).
To create a new translation, for example for German:
* generate a ``messages.pot`` file by running ``build_tools/fish_xgettext.fish`` from
the source tree
* copy ``messages.pot`` to ``po/LANG.po``
To update a translation:
* generate a ``messages.pot`` file by running
``build_tools/fish_xgettext.fish`` from the source tree
* update the existing translation by running
``msgmerge --update --no-fuzzy-matching po/LANG.po messages.pot``
Many tools are available for editing translation files, including
command-line and graphical user interface programs.
Be cautious about blindly updating an existing translation file. Trivial
changes to an existing message (eg changing the punctuation) will cause
existing translations to be removed, since the tools do literal string
matching. Therefore, in general, you need to carefully review any
recommended deletions.
Read the `translations
wiki <https://github.com/fish-shell/fish-shell/wiki/Translations>`__ for
more information.
the opening parentheses or before the closing parentheses.
Versioning
----------
==========
The fish version is constructed by the *build_tools/git_version_gen.sh*
script. For developers the version is the branch name plus the output of
``git describe --always --dirty``. Normally the main part of the version
will be the closest annotated tag. Which itself is usually the most
recent release number (e.g., ``2.6.0``).
Include What You Use
--------------------
You should not depend on symbols being visible to a ``*.cpp`` module
from ``#include`` statements inside another header file. In other words
if your module does ``#include "common.h"`` and that header does
``#include "signal.h"`` your module should not assume the sub-include is
present. It should instead directly ``#include "signal.h"`` if it needs
any symbol from that header. That makes the actual dependencies much
clearer. It also makes it easy to modify the headers included by a
specific header file without having to worry that will break any module
(or header) that includes a particular header.
To help enforce this rule the ``make lint`` (and ``make lint-all``)
command will run the
`include-what-you-use <https://include-what-you-use.org/>`__ tool. You
can find the IWYU project on
`github <https://github.com/include-what-you-use/include-what-you-use>`__.
To install the tool on OS X youll need to add a
`formula <https://github.com/jasonmp85/homebrew-iwyu>`__ then install
it:
::
brew tap jasonmp85/iwyu
brew install iwyu
On Ubuntu you can install it via ``apt-get``:
::
sudo apt-get install iwyu

View File

@@ -1,7 +1,7 @@
Fish is a smart and user-friendly command line shell.
Copyright (C) 2005-2009 Axel Liljencrantz
Copyright (C) 2009-2023 fish-shell contributors
Copyright (C) 2009- fish-shell contributors
fish is free software.
@@ -9,9 +9,8 @@ Most of fish is licensed under the GNU General Public License version 2, and
you can redistribute it and/or modify it under the terms of the GNU GPL as
published by the Free Software Foundation.
fish also includes software licensed under the CMake license, the Python
Software Foundation License version 2, the OpenBSD license, the ISC license,
the NetBSD license, and the MIT license.
fish also includes software licensed under the Python Software Foundation License version 2, the MIT
license, and the GNU Library General Public License version 2.
Full licensing information is contained in doc_src/license.rst.

792
Cargo.lock generated Normal file
View File

@@ -0,0 +1,792 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "allocator-api2"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "cc"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7"
dependencies = [
"jobserver",
"libc",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "cpufeatures"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "fish"
version = "4.1.0-snapshot"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"errno",
"fish-build-helper",
"fish-build-man-pages",
"fish-gettext-extraction",
"fish-gettext-maps",
"fish-gettext-mo-file-parser",
"fish-printf",
"libc",
"lru",
"macro_rules_attribute",
"nix",
"num-traits",
"once_cell",
"pcre2",
"phf 0.12.1",
"phf_codegen 0.12.1",
"portable-atomic",
"rand",
"rsconf",
"rust-embed",
"serial_test",
"terminfo",
"unix_path",
"widestring",
]
[[package]]
name = "fish-build-helper"
version = "0.0.0"
dependencies = [
"rsconf",
]
[[package]]
name = "fish-build-man-pages"
version = "0.0.0"
dependencies = [
"fish-build-helper",
"rsconf",
]
[[package]]
name = "fish-gettext-extraction"
version = "0.0.0"
dependencies = [
"proc-macro2",
]
[[package]]
name = "fish-gettext-maps"
version = "0.0.0"
dependencies = [
"fish-build-helper",
"fish-gettext-mo-file-parser",
"phf 0.12.1",
"phf_codegen 0.12.1",
"rsconf",
]
[[package]]
name = "fish-gettext-mo-file-parser"
version = "0.0.0"
[[package]]
name = "fish-printf"
version = "0.2.1"
dependencies = [
"libc",
"unicode-segmentation",
"unicode-width",
"widestring",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foldhash"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
dependencies = [
"allocator-api2",
"equivalent",
"foldhash",
]
[[package]]
name = "jobserver"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "lru"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "227748d55f2f0ab4735d87fd623798cb6b664512fe979705f829c9f81c934465"
dependencies = [
"hashbrown",
]
[[package]]
name = "macro_rules_attribute"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65049d7923698040cd0b1ddcced9b0eb14dd22c5f86ae59c3740eab64a676520"
dependencies = [
"macro_rules_attribute-proc_macro",
"paste",
]
[[package]]
name = "macro_rules_attribute-proc_macro"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670fdfda89751bc4a84ac13eaa63e205cf0fd22b4c9a5fbfa085b63c1f1d3a30"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nix"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "pcre2"
version = "0.2.9"
source = "git+https://github.com/fish-shell/rust-pcre2?tag=0.2.9-utf32#85b7afba1a9d9bd445779800e5bcafeb732e4421"
dependencies = [
"libc",
"log",
"pcre2-sys",
]
[[package]]
name = "pcre2-sys"
version = "0.2.9"
source = "git+https://github.com/fish-shell/rust-pcre2?tag=0.2.9-utf32#85b7afba1a9d9bd445779800e5bcafeb732e4421"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "phf"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
dependencies = [
"phf_shared 0.11.3",
]
[[package]]
name = "phf"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7"
dependencies = [
"phf_shared 0.12.1",
]
[[package]]
name = "phf_codegen"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
dependencies = [
"phf_generator 0.11.3",
"phf_shared 0.11.3",
]
[[package]]
name = "phf_codegen"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbdcb6f01d193b17f0b9c3360fa7e0e620991b193ff08702f78b3ce365d7e61"
dependencies = [
"phf_generator 0.12.1",
"phf_shared 0.12.1",
]
[[package]]
name = "phf_generator"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [
"phf_shared 0.11.3",
"rand",
]
[[package]]
name = "phf_generator"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cbb1126afed61dd6368748dae63b1ee7dc480191c6262a3b4ff1e29d86a6c5b"
dependencies = [
"fastrand",
"phf_shared 0.12.1",
]
[[package]]
name = "phf_shared"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5"
dependencies = [
"siphasher",
]
[[package]]
name = "phf_shared"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981"
dependencies = [
"siphasher",
]
[[package]]
name = "pkg-config"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "portable-atomic"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "redox_syscall"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
dependencies = [
"bitflags",
]
[[package]]
name = "rsconf"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd2af859f1af0401e7fc7577739c87b0d239d8a5da400d717183bca92336bcdc"
dependencies = [
"cc",
]
[[package]]
name = "rust-embed"
version = "8.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "025908b8682a26ba8d12f6f2d66b987584a4a87bc024abc5bbc12553a8cd178a"
dependencies = [
"rust-embed-impl",
"rust-embed-utils",
"walkdir",
]
[[package]]
name = "rust-embed-impl"
version = "8.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6065f1a4392b71819ec1ea1df1120673418bf386f50de1d6f54204d836d4349c"
dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn",
"walkdir",
]
[[package]]
name = "rust-embed-utils"
version = "8.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6cc0c81648b20b70c491ff8cce00c1c3b223bb8ed2b5d41f0e54c6c4c0a3594"
dependencies = [
"sha2",
"walkdir",
]
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "scc"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28e1c91382686d21b5ac7959341fcb9780fa7c03773646995a87c950fa7be640"
dependencies = [
"sdd",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "sdd"
version = "3.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478f121bb72bbf63c52c93011ea1791dca40140dfe13f8336c4c5ac952c33aa9"
[[package]]
name = "serial_test"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9"
dependencies = [
"once_cell",
"parking_lot",
"scc",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "siphasher"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "syn"
version = "2.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "terminfo"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4ea810f0692f9f51b382fff5893887bb4580f5fa246fde546e0b13e7fcee662"
dependencies = [
"fnv",
"nom",
"phf 0.11.3",
"phf_codegen 0.11.3",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-width"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
[[package]]
name = "unix_path"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8e291873ae77c4c8d9c9b34d0bee68a35b048fb39c263a5155e0e353783eaf"
dependencies = [
"unix_str",
]
[[package]]
name = "unix_str"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ace0b4755d0a2959962769239d56267f8a024fef2d9b32666b3dcd0946b0906"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "widestring"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd7cf3379ca1aac9eea11fba24fd7e315d621f8dfe35c8d7d2be8b793726e07d"
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

169
Cargo.toml Normal file
View File

@@ -0,0 +1,169 @@
[workspace]
resolver = "2"
members = ["crates/*"]
[workspace.package]
# To build revisions that use Corrosion (those before 2024-01), use CMake 3.19, Rustc 1.78 and Rustup 1.27.
rust-version = "1.70"
edition = "2021"
repository = "https://github.com/fish-shell/fish-shell"
[workspace.dependencies]
bitflags = "2.5.0"
cc = "1.0.94"
cfg-if = "1.0.3"
errno = "0.3.0"
fish-build-helper = { path = "crates/build-helper" }
fish-build-man-pages = { path = "crates/build-man-pages" }
fish-gettext-extraction = { path = "crates/gettext-extraction" }
fish-gettext-maps = { path = "crates/gettext-maps" }
fish-gettext-mo-file-parser = { path = "crates/gettext-mo-file-parser" }
fish-printf = { path = "crates/printf", features = ["widestring"] }
libc = "0.2.155"
# lru pulls in hashbrown by default, which uses a faster (though less DoS resistant) hashing algo.
# disabling default features uses the stdlib instead, but it doubles the time to rewrite the history
# files as of 22 April 2024.
lru = "0.13.0"
nix = { version = "0.30.1", default-features = false, features = [
"event",
"inotify",
"resource",
"fs",
] }
num-traits = "0.2.19"
once_cell = "1.19.0"
pcre2 = { git = "https://github.com/fish-shell/rust-pcre2", tag = "0.2.9-utf32", default-features = false, features = [
"utf32",
] }
phf = { version = "0.12", default-features = false }
phf_codegen = { version = "0.12" }
portable-atomic = { version = "1", default-features = false, features = [
"fallback",
] }
proc-macro2 = "1.0"
# Don't use the "getrandom" feature as it requires "getentropy" which was not
# available on macOS < 10.12. We can enable "getrandom" when we raise the
# minimum supported version to 10.12.
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
rsconf = "0.2.2"
rust-embed = { version = "8.7.2", features = ["deterministic-timestamps"] }
serial_test = { version = "3", default-features = false }
# We need 0.9.0 specifically for some crash fixes.
terminfo = "0.9.0"
widestring = "1.2.0"
unicode-segmentation = "1.12.0"
unicode-width = "0.2.0"
unix_path = "1.0.1"
[profile.release]
overflow-checks = true
lto = true
[profile.release-with-debug]
inherits = "release"
debug = true
[package]
name = "fish"
version = "4.1.0-snapshot"
edition.workspace = true
rust-version.workspace = true
default-run = "fish"
# see doc_src/license.rst for details
# don't forget to update COPYING and debian/copyright too
license = "GPL-2.0-only AND LGPL-2.0-or-later AND MIT AND PSF-2.0"
homepage = "https://fishshell.com"
readme = "README.rst"
[dependencies]
bitflags.workspace = true
cfg-if.workspace = true
errno.workspace = true
fish-build-helper.workspace = true
fish-build-man-pages = { workspace = true, optional = true }
fish-gettext-extraction = { workspace = true, optional = true }
fish-gettext-maps = { workspace = true, optional = true }
fish-printf.workspace = true
libc.workspace = true
lru.workspace = true
macro_rules_attribute = "0.2.2"
nix.workspace = true
num-traits.workspace = true
once_cell.workspace = true
pcre2.workspace = true
phf = { workspace = true, optional = true }
rand.workspace = true
terminfo.workspace = true
widestring.workspace = true
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
portable-atomic.workspace = true
[target.'cfg(windows)'.dependencies]
rust-embed = { workspace = true, optional = true, features = ["deterministic-timestamps", "debug-embed"] }
[target.'cfg(not(windows))'.dependencies]
rust-embed = { workspace = true, optional = true, features = ["deterministic-timestamps"] }
[dev-dependencies]
serial_test.workspace = true
[build-dependencies]
cc.workspace = true
fish-build-helper.workspace = true
fish-gettext-mo-file-parser.workspace = true
phf_codegen = { workspace = true, optional = true }
rsconf.workspace = true
[target.'cfg(windows)'.build-dependencies]
unix_path.workspace = true
[lib]
crate-type = ["rlib"]
path = "src/lib.rs"
[[bin]]
name = "fish"
path = "src/bin/fish.rs"
[[bin]]
name = "fish_indent"
path = "src/bin/fish_indent.rs"
[[bin]]
name = "fish_key_reader"
path = "src/bin/fish_key_reader.rs"
[features]
default = ["embed-data", "localize-messages"]
benchmark = []
embed-data = ["dep:rust-embed", "dep:fish-build-man-pages"]
# Enable gettext localization at runtime. Requires the `msgfmt` tool to generate catalog data at
# build time.
localize-messages = ["dep:phf", "dep:fish-gettext-maps"]
# This feature is used to enable extracting messages from the source code for localization.
# It only needs to be enabled if updating these messages (and the corresponding PO files) is
# desired. This happens when running tests via `build_tools/check.sh` and when calling
# `build_tools/update_translations.fish`, so there should not be a need to enable it manually.
gettext-extract = ["dep:fish-gettext-extraction"]
# The following features are auto-detected by the build-script and should not be enabled manually.
asan = []
tsan = []
[workspace.lints]
rust.non_camel_case_types = "allow"
rust.non_upper_case_globals = "allow"
rust.unknown_lints = "allow"
rust.unstable_name_collisions = "allow"
clippy.manual_range_contains = "allow"
clippy.needless_return = "allow"
clippy.needless_lifetimes = "allow"
# We do not want to use the e?print(ln)?! macros.
# These lints flag their use.
# In the future, they might change to flag other methods of printing.
clippy.print_stdout = "deny"
clippy.print_stderr = "deny"
[lints]
workspace = true

View File

@@ -3,7 +3,7 @@ FROM centos:latest
# Build dependency
RUN yum update -y &&\
yum install -y epel-release &&\
yum install -y clang cmake3 gcc-c++ make ncurses-devel &&\
yum install -y clang cmake3 gcc-c++ make &&\
yum clean all
# Test dependency
@@ -16,4 +16,3 @@ WORKDIR /src
RUN cmake3 . &&\
make &&\
make install

View File

@@ -55,7 +55,11 @@ clean:
.PHONY: test
test: build/fish
$(CMAKE) --build build --target test
$(CMAKE) --build build --target fish_run_tests
.PHONY: fish_run_tests
fish_run_tests: build/fish
$(CMAKE) --build build --target fish_run_tests
.PHONY: install
install: build/fish

View File

@@ -3,7 +3,7 @@
:alt: Cirrus CI Build Status
`fish <https://fishshell.com/>`__ - the friendly interactive shell |Build Status| |Cirrus CI|
=================================================================================
=============================================================================================
fish is a smart and user-friendly command line shell for macOS, Linux,
and the rest of the family. fish includes features like syntax
@@ -47,12 +47,12 @@ Linux/CentOS are available from the `openSUSE Build
Service <https://software.opensuse.org/download.html?project=shells%3Afish&package=fish>`__.
Packages for Ubuntu are available from the `fish
PPA <https://launchpad.net/~fish-shell/+archive/ubuntu/release-3>`__,
PPA <https://launchpad.net/~fish-shell/+archive/ubuntu/release-4>`__,
and can be installed using the following commands:
::
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt-add-repository ppa:fish-shell/release-4
sudo apt update
sudo apt install fish
@@ -62,12 +62,12 @@ Instructions for other distributions may be found at
Windows
~~~~~~~
- On Windows 10, fish can be installed under the WSL Windows Subsystem
- On Windows 10/11, fish can be installed under the WSL Windows Subsystem
for Linux with the instructions for the appropriate distribution
listed above under “Packages for Linux”, or from source with the
instructions below.
- Fish can also be installed on all versions of Windows using
`Cygwin <https://cygwin.com/>`__ (from the **Shells** category).
`Cygwin <https://cygwin.com/>`__ or `MSYS2 <https://github.com/Berrysoft/fish-msys2>`__.
Building from source
~~~~~~~~~~~~~~~~~~~~
@@ -76,7 +76,7 @@ If packages are not available for your platform, GPG-signed tarballs are
available from `fishshell.com <https://fishshell.com/>`__ and
`fish-shell on
GitHub <https://github.com/fish-shell/fish-shell/releases>`__. See the
`Building <#building>`__ section for instructions.
`Building <#building>`_ section for instructions.
Running fish
------------
@@ -88,20 +88,16 @@ Dependencies
Running fish requires:
- curses or ncurses (preinstalled on most \*nix systems)
- some common \*nix system utilities (currently ``mktemp``), in
addition to the basic POSIX utilities (``cat``, ``cut``, ``dirname``,
``ls``, ``mkdir``, ``mkfifo``, ``rm``, ``sort``, ``tee``, ``tr``,
``file``, ``ls``, ``mkdir``, ``mkfifo``, ``rm``, ``sh``, ``sort``, ``tee``, ``tr``,
``uname`` and ``sed`` at least, but the full coreutils plus ``find`` and
``awk`` is preferred)
- The gettext library, if compiled with
translation support
The following optional features also have specific requirements:
- builtin commands that have the ``--help`` option or print usage
messages require ``nroff`` or ``mandoc`` for
display
messages require ``man`` for display
- automated completion generation from manual pages requires Python 3.5+
- the ``fish_config`` web configuration tool requires Python 3.5+ and a web browser
- system clipboard integration (with the default Ctrl-V and Ctrl-X
@@ -112,32 +108,6 @@ The following optional features also have specific requirements:
- ``colorls`` is used, if installed, to add color when running ``ls`` on platforms
that do not have color support (such as OpenBSD)
Switching to fish
~~~~~~~~~~~~~~~~~
If you wish to use fish as your default shell, use the following
command:
::
chsh -s /usr/local/bin/fish
``chsh`` will prompt you for your password and change your default
shell. (Substitute ``/usr/local/bin/fish`` with whatever path fish was
installed to, if it differs.) Log out, then log in again for the changes
to take effect.
Use the following command if fish isnt already added to ``/etc/shells``
to permit fish to be your login shell:
::
echo /usr/local/bin/fish | sudo tee -a /etc/shells
To switch your default shell back, you can run ``chsh -s /bin/bash``
(substituting ``/bin/bash`` with ``/bin/tcsh`` or ``/bin/zsh`` as
appropriate).
Building
--------
@@ -148,19 +118,25 @@ Dependencies
Compiling fish requires:
- a C++11 compiler (g++ 4.8 or later, or clang 3.3 or later)
- CMake (version 3.5 or later)
- a curses implementation such as ncurses (headers and libraries)
- Rust (version 1.70 or later)
- CMake (version 3.15 or later)
- a C compiler (for system feature detection and the test helper binary)
- PCRE2 (headers and libraries) - optional, this will be downloaded if missing
- gettext (headers and libraries) - optional, for translation support
- gettext (only the msgfmt tool) - optional, for translation support
- an Internet connection, as other dependencies will be downloaded automatically
Sphinx is also optionally required to build the documentation from a
cloned git repository.
Additionally, running the test suite requires Python 3.5+ and the pexpect package.
Additionally, running the full test suite requires diff, git, Python 3.5+, pexpect, less, tmux and wget.
Building from source (all platforms) - Makefile generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Building from source with CMake
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rather than building from source, consider using a packaged build for your platform. Using the
steps below makes fish difficult to uninstall or upgrade. Release packages are available from the
links above, and up-to-date `development builds of fish are available for many platforms
<https://github.com/fish-shell/fish-shell/wiki/Development-builds>`__
To install into ``/usr/local``, run:
@@ -168,64 +144,54 @@ To install into ``/usr/local``, run:
mkdir build; cd build
cmake ..
make
sudo make install
cmake --build .
sudo cmake --install .
The install directory can be changed using the
``-DCMAKE_INSTALL_PREFIX`` parameter for ``cmake``.
Building from source (macOS) - Xcode
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CMake Build options
~~~~~~~~~~~~~~~~~~~
Note: The minimum supported macOS version is 10.10 "Yosemite".
In addition to the normal CMake build options (like ``CMAKE_INSTALL_PREFIX``), fish's CMake build has some other options available to customize it.
.. code:: bash
mkdir build; cd build
cmake .. -G Xcode
An Xcode project will now be available in the ``build`` subdirectory.
You can open it with Xcode, or run the following to build and install in
``/usr/local``:
.. code:: bash
xcodebuild
xcodebuild -scheme install
The install directory can be changed using the
``-DCMAKE_INSTALL_PREFIX`` parameter for ``cmake``.
Build options
~~~~~~~~~~~~~
In addition to the normal cmake build options (like ``CMAKE_INSTALL_PREFIX``), fish has some other options available to customize it.
- BUILD_DOCS=ON|OFF - whether to build the documentation. This is automatically set to OFF when sphinx isn't installed.
- Rust_COMPILER=path - the path to rustc. If not set, cmake will check $PATH and ~/.cargo/bin
- Rust_CARGO=path - the path to cargo. If not set, cmake will check $PATH and ~/.cargo/bin
- Rust_CARGO_TARGET=target - the target to pass to cargo. Set this for cross-compilation.
- BUILD_DOCS=ON|OFF - whether to build the documentation. This is automatically set to OFF when Sphinx isn't installed.
- INSTALL_DOCS=ON|OFF - whether to install the docs. This is automatically set to on when BUILD_DOCS is or prebuilt documentation is available (like when building in-tree from a tarball).
- FISH_USE_SYSTEM_PCRE2=ON|OFF - whether to use an installed pcre2. This is normally autodetected.
- MAC_CODESIGN_ID=String|OFF - the codesign ID to use on Mac, or "OFF" to disable codesigning.
- WITH_GETTEXT=ON|OFF - whether to build with gettext support for translations.
- WITH_GETTEXT=ON|OFF - whether to include translations.
- extra_functionsdir, extra_completionsdir and extra_confdir - to compile in an additional directory to be searched for functions, completions and configuration snippets
Note that fish does *not* support static linking and will attempt to error out if it detects it.
Building fish with embedded data (experimental)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Help, it didnt build!
~~~~~~~~~~~~~~~~~~~~~~
You can also build fish with the data files embedded.
If fish reports that it could not find curses, try installing a curses
development package and build again.
This will include all the datafiles like the included functions or web configuration tool in the main ``fish`` binary.
On Debian or Ubuntu you want:
Fish will then read these right from its own binary, and print them out when needed. Some files, like the webconfig tool and the manpage completion generator, will be extracted to a temporary directory on-demand. You can list the files with ``status list-files`` and print one with ``status get-file path/to/file`` (e.g. ``status get-file functions/fish_prompt.fish`` to get the default prompt).
::
To install fish with embedded files, just use ``cargo``, like::
sudo apt install build-essential cmake ncurses-dev libncurses5-dev libpcre2-dev gettext
cargo install --path /path/to/fish # if you have a git clone
cargo install --git https://github.com/fish-shell/fish-shell --tag "$(curl -s https://api.github.com/repos/fish-shell/fish-shell/releases/latest | jq -r .tag_name)" # to build the latest release
cargo install --git https://github.com/fish-shell/fish-shell # to build the latest development snapshot
On RedHat, CentOS, or Amazon EC2:
This will place the standalone binaries in ``~/.cargo/bin/``, but you can place them wherever you want.
::
This build won't have the HTML docs (``help`` will open the online version).
It will try to build the man pages with sphinx-build. If that is not available and you would like to include man pages, you need to install it and retrigger the build script, e.g. by setting FISH_BUILD_DOCS=1::
sudo yum install ncurses-devel
FISH_BUILD_DOCS=1 cargo install --path .
Setting it to "0" disables the inclusion of man pages.
To disable translations, disable the ``localize-messages`` feature by passing ``--no-default-features --features=embed-data`` to cargo.
You can also link this build statically (but not against glibc) and move it to other computers.
Contributing Changes to the Code
--------------------------------
@@ -237,8 +203,8 @@ Contact Us
Questions, comments, rants and raves can be posted to the official fish
mailing list at https://lists.sourceforge.net/lists/listinfo/fish-users
or join us on our `gitter.im
channel <https://gitter.im/fish-shell/fish-shell>`__. Or use the `fish tag
or join us on our `matrix
channel <https://matrix.to/#/#fish-shell:matrix.org>`__. Or use the `fish tag
on Unix & Linux Stackexchange <https://unix.stackexchange.com/questions/tagged/fish>`__.
There is also a fish tag on Stackoverflow, but it is typically a poor fit.

35
SECURITY.md Normal file
View File

@@ -0,0 +1,35 @@
# Security Reporting
If you wish to report a security vulnerability privately, we appreciate your diligence. Please follow the guidelines below to submit your report.
## Reporting
To report a security vulnerability, please provide the following information:
1. **PROJECT**
- Include the URL of the project repository - Example: <https://github.com/fish-shell/fish-shell>
2. **PUBLIC**
- Indicate whether this vulnerability has already been publicly discussed or disclosed.
- If so, provide relevant links.
3. **DESCRIPTION**
- Provide a detailed description of the security vulnerability.
- Include as much information as possible to help us understand and address the issue.
Send this information, along with any additional relevant details, to <rf@fishshell.com>.
## Confidentiality
We kindly ask you to keep the report confidential until a public announcement is made.
## Notes
- Vulnerabilities will be handled on a best-effort basis.
- You may request an advance copy of the patched release, but we cannot guarantee early access before the public release.
- You will be notified via email simultaneously with the public announcement.
- We will respond within a few weeks to confirm whether your report has been accepted or rejected.
Thank you for helping to improve the security of our project!

View File

@@ -3,6 +3,5 @@
# so it's best to build two fishes, check out one version of the repo,
# and then run this script with both.
set -l dir (dirname (status current-filename))
for i in (seq 1 10)
echo $dir/../../**
end
# No repetitions, this is plenty slow enough.
echo $dir/../../**

View File

@@ -0,0 +1,11 @@
set -l compdir (status dirname)/../../share/completions
cd $compdir
for file in *.fish
set -l bname (string replace -r '.fish$' '' -- $file)
if type -q $bname
source $file >/dev/null
if test $status -gt 0
echo FAILING FILE $file
end
end
end

View File

@@ -0,0 +1,6 @@
set -l path (status dirname)
set -l fish (status fish-path)
for f in (seq 100)
echo $fish -n $path/aliases.fish
$fish -n $path/aliases.fish
end

View File

@@ -0,0 +1 @@
printf (string repeat -n 200 \\x7f)%s\n (string repeat -n 2000 aaa\n)

View File

@@ -0,0 +1,5 @@
for i in (seq 100000)
printf '%f\n' $i.$i
end
exit 0

View File

@@ -0,0 +1,7 @@
set -l tmp (mktemp)
string repeat -n 2000 >$tmp
for i in (seq 1000)
cat $tmp | read -l foo
end
true

View File

@@ -0,0 +1,3 @@
for abc in (seq 100000)
set -l def
end

View File

@@ -0,0 +1,3 @@
for i in (string repeat -n 100 \n)
string repeat -n 50000 a\n
end

View File

@@ -0,0 +1,3 @@
for i in (seq 100000)
string match '*o' fooooooo
end

View File

@@ -0,0 +1,3 @@
for i in (seq 100000)
string match -r '^.*$' fooooooo
end | string match -re o

View File

@@ -1,6 +1,6 @@
#!/bin/sh
if [ "$#" -gt 2 -o "$#" -eq 0 ]; then
if [ "$#" -gt 2 ] || [ "$#" -eq 0 ]; then
echo "Usage: driver.sh /path/to/fish [/path/to/other/fish]"
exit 1
fi

309
build.rs Normal file
View File

@@ -0,0 +1,309 @@
#![allow(clippy::uninlined_format_args)]
use fish_build_helper::{env_var, fish_build_dir, workspace_root};
use rsconf::Target;
use std::env;
use std::path::{Path, PathBuf};
fn canonicalize<P: AsRef<Path>>(path: P) -> PathBuf {
std::fs::canonicalize(path).unwrap()
}
fn main() {
setup_paths();
// Add our default to enable tools that don't go through CMake, like "cargo test" and the
// language server.
rsconf::set_env_value(
"FISH_RESOLVED_BUILD_DIR",
// If set by CMake, this might include symlinks. Since we want to compare this to the
// dir fish is executed in we need to canonicalize it.
canonicalize(fish_build_dir()).to_str().unwrap(),
);
// We need to canonicalize (i.e. realpath) the manifest dir because we want to be able to
// compare it directly as a string at runtime.
rsconf::set_env_value(
"CARGO_MANIFEST_DIR",
canonicalize(workspace_root()).to_str().unwrap(),
);
// Some build info
rsconf::set_env_value("BUILD_TARGET_TRIPLE", &env_var("TARGET").unwrap());
rsconf::set_env_value("BUILD_HOST_TRIPLE", &env_var("HOST").unwrap());
rsconf::set_env_value("BUILD_PROFILE", &env_var("PROFILE").unwrap());
let version = &get_version(&env::current_dir().unwrap());
// Per https://doc.rust-lang.org/cargo/reference/build-scripts.html#inputs-to-the-build-script,
// the source directory is the current working directory of the build script
rsconf::set_env_value("FISH_BUILD_VERSION", version);
std::env::set_var("FISH_BUILD_VERSION", version);
// These are necessary if built with embedded functions,
// but only in release builds (because rust-embed in debug builds reads from the filesystem).
#[cfg(feature = "embed-data")]
#[cfg(any(windows, not(debug_assertions)))]
rsconf::rebuild_if_path_changed("share");
#[cfg(feature = "gettext-extract")]
rsconf::rebuild_if_env_changed("FISH_GETTEXT_EXTRACTION_FILE");
let build = cc::Build::new();
let mut target = Target::new_from(build).unwrap();
// Keep verbose mode on until we've ironed out rust build script stuff
target.set_verbose(true);
detect_cfgs(&mut target);
#[cfg(all(target_env = "gnu", target_feature = "crt-static"))]
compile_error!("Statically linking against glibc has unavoidable crashes and is unsupported. Use dynamic linking or link statically against musl.");
}
/// Check target system support for certain functionality dynamically when the build is invoked,
/// without their having to be explicitly enabled in the `cargo build --features xxx` invocation.
///
/// We are using [`rsconf::enable_cfg()`] instead of [`rsconf::enable_feature()`] as rust features
/// should be used for things that a user can/would reasonably enable or disable to tweak or coerce
/// behavior, but here we are testing for whether or not things are supported altogether.
///
/// This can be used to enable features that we check for and conditionally compile according to in
/// our own codebase, but [can't be used to pull in dependencies](0) even if they're gated (in
/// `Cargo.toml`) behind a feature we just enabled.
///
/// [0]: https://github.com/rust-lang/cargo/issues/5499
#[rustfmt::skip]
fn detect_cfgs(target: &mut Target) {
for (name, handler) in [
// Ignore the first entry, it just sets up the type inference. Model new entries after the
// second line.
("", &(|_: &Target| false) as &dyn Fn(&Target) -> bool),
("apple", &detect_apple),
("bsd", &detect_bsd),
("cygwin", &detect_cygwin),
("small_main_stack", &has_small_stack),
// See if libc supports the thread-safe localeconv_l(3) alternative to localeconv(3).
("localeconv_l", &|target| {
target.has_symbol("localeconv_l")
}),
("FISH_USE_POSIX_SPAWN", &|target| {
target.has_header("spawn.h")
}),
("HAVE_PIPE2", &|target| {
target.has_symbol("pipe2")
}),
("HAVE_EVENTFD", &|target| {
// FIXME: NetBSD 10 has eventfd, but the libc crate does not expose it.
if cfg!(target_os = "netbsd") {
false
} else {
target.has_header("sys/eventfd.h")
}
}),
("HAVE_WAITSTATUS_SIGNAL_RET", &|target| {
target.r#if("WEXITSTATUS(0x007f) == 0x7f", &["sys/wait.h"])
}),
] {
rsconf::declare_cfg(name, handler(target))
}
}
fn detect_apple(_: &Target) -> bool {
cfg!(any(target_os = "ios", target_os = "macos"))
}
fn detect_cygwin(_: &Target) -> bool {
// Cygwin target is usually cross-compiled.
env_var("CARGO_CFG_TARGET_OS").unwrap() == "cygwin"
}
/// Detect if we're being compiled for a BSD-derived OS, allowing targeting code conditionally with
/// `#[cfg(bsd)]`.
///
/// Rust offers fine-grained conditional compilation per-os for the popular operating systems, but
/// doesn't necessarily include less-popular forks nor does it group them into families more
/// specific than "windows" vs "unix" so we can conditionally compile code for BSD systems.
fn detect_bsd(_: &Target) -> bool {
// Instead of using `uname`, we can inspect the TARGET env variable set by Cargo. This lets us
// support cross-compilation scenarios.
let mut target = env_var("TARGET").unwrap();
if !target.chars().all(|c| c.is_ascii_lowercase()) {
target = target.to_ascii_lowercase();
}
#[allow(clippy::let_and_return)] // for old clippy
let is_bsd = target.ends_with("bsd") || target.ends_with("dragonfly");
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
))]
assert!(is_bsd, "Target incorrectly detected as not BSD!");
is_bsd
}
/// Rust sets the stack size of newly created threads to a sane value, but is at at the mercy of the
/// OS when it comes to the size of the main stack. Some platforms we support default to a tiny
/// 0.5 MiB main stack, which is insufficient for fish's MAX_EVAL_DEPTH/MAX_STACK_DEPTH values.
///
/// 0.5 MiB is small enough that we'd have to drastically reduce MAX_STACK_DEPTH to less than 10, so
/// we instead use a workaround to increase the main thread size.
fn has_small_stack(_: &Target) -> bool {
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "netbsd")))]
return false;
// NetBSD 10 also needs this but can't find pthread_get_stacksize_np.
#[cfg(target_os = "netbsd")]
return true;
#[cfg(any(target_os = "ios", target_os = "macos"))]
{
use core::ffi;
extern "C" {
fn pthread_get_stacksize_np(thread: *const ffi::c_void) -> usize;
fn pthread_self() -> *const ffi::c_void;
}
// build.rs is executed on the main thread, so we are getting the main thread's stack size.
// Modern macOS versions default to an 8 MiB main stack but legacy OS X have a 0.5 MiB one.
let stack_size = unsafe { pthread_get_stacksize_np(pthread_self()) };
const TWO_MIB: usize = 2 * 1024 * 1024 - 1;
stack_size <= TWO_MIB
}
}
fn setup_paths() {
#[cfg(windows)]
use unix_path::{Path, PathBuf};
fn overridable_path(env_var_name: &str, f: impl FnOnce(Option<String>) -> PathBuf) -> PathBuf {
rsconf::rebuild_if_env_changed(env_var_name);
let path = f(env_var(env_var_name));
rsconf::set_env_value(env_var_name, path.to_str().unwrap());
path
}
fn join_if_relative(parent_if_relative: &Path, path: String) -> PathBuf {
let path = PathBuf::from(path);
if path.is_relative() {
parent_if_relative.join(path)
} else {
path
}
}
let prefix = overridable_path("PREFIX", |env_prefix| {
PathBuf::from(env_prefix.unwrap_or("/usr/local".to_string()))
});
let datadir = join_if_relative(&prefix, env_var("DATADIR").unwrap_or("share/".to_string()));
rsconf::rebuild_if_env_changed("DATADIR");
#[cfg(not(feature = "embed-data"))]
rsconf::set_env_value("DATADIR", datadir.to_str().unwrap());
overridable_path("SYSCONFDIR", |env_sysconfdir| {
join_if_relative(
&datadir,
env_sysconfdir.unwrap_or(
// Embedded builds use "/etc," not "./share/etc".
if cfg!(feature = "embed-data") {
"/etc/"
} else {
"etc/"
}
.to_string(),
),
)
});
#[cfg(not(feature = "embed-data"))]
{
overridable_path("BINDIR", |env_bindir| {
join_if_relative(&prefix, env_bindir.unwrap_or("bin/".to_string()))
});
overridable_path("LOCALEDIR", |env_localedir| {
join_if_relative(&datadir, env_localedir.unwrap_or("locale/".to_string()))
});
overridable_path("DOCDIR", |env_docdir| {
join_if_relative(&datadir, env_docdir.unwrap_or("doc/fish".to_string()))
});
}
}
fn get_version(src_dir: &Path) -> String {
use std::fs::read_to_string;
use std::process::Command;
if let Some(var) = env_var("FISH_BUILD_VERSION") {
return var;
}
let path = src_dir.join("version");
if let Ok(strver) = read_to_string(path) {
return strver;
}
let args = &["describe", "--always", "--dirty=-dirty"];
if let Ok(output) = Command::new("git").args(args).output() {
let rev = String::from_utf8_lossy(&output.stdout).trim().to_string();
if !rev.is_empty() {
// If it contains a ".", we have a proper version like "3.7",
// or "23.2.1-1234-gfab1234"
if rev.contains('.') {
return rev;
}
// If it doesn't, we probably got *just* the commit SHA,
// like "f1242abcdef".
// So we prepend the crate version so it at least looks like
// "3.8-gf1242abcdef"
// This lacks the commit *distance*, but that can't be helped without
// tags.
let version = env!("CARGO_PKG_VERSION").to_owned();
return version + "-g" + &rev;
}
}
// git did not tell us a SHA either because it isn't installed,
// or because it refused (safe.directory applies to `git describe`!)
// So we read the SHA ourselves.
fn get_git_hash() -> Result<String, Box<dyn std::error::Error>> {
let workspace_root = workspace_root();
let gitdir = workspace_root.join(".git");
let jjdir = workspace_root.join(".jj");
let commit_id = if gitdir.exists() {
// .git/HEAD contains ref: refs/heads/branch
let headpath = gitdir.join("HEAD");
let headstr = read_to_string(headpath)?;
let headref = headstr.split(' ').nth(1).unwrap().trim();
// .git/refs/heads/branch contains the SHA
let refpath = gitdir.join(headref);
// Shorten to 9 characters (what git describe does currently)
read_to_string(refpath)?
} else if jjdir.exists() {
let output = Command::new("jj")
.args([
"log",
"--revisions",
"@",
"--no-graph",
"--ignore-working-copy",
"--template",
"commit_id",
])
.output()
.unwrap();
String::from_utf8_lossy(&output.stdout).to_string()
} else {
return Err("did not find either of .git or .jj".into());
};
let refstr = &commit_id[0..9];
let refstr = refstr.trim();
let version = env!("CARGO_PKG_VERSION").to_owned();
Ok(version + "-g" + refstr)
}
get_git_hash().expect("Could not get a version. Either set $FISH_BUILD_VERSION or install git.")
}

70
build_tools/check.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/bin/sh
{
set -ex
lint=true
if [ "$FISH_CHECK_LINT" = false ]; then
lint=false
fi
cargo_args=$FISH_CHECK_CARGO_ARGS
target_triple=$FISH_CHECK_TARGET_TRIPLE
if [ -n "$target_triple" ]; then
cargo_args="$cargo_args --target=$FISH_CHECK_TARGET_TRIPLE"
fi
cargo() {
subcmd=$1
shift
# shellcheck disable=2086
command cargo "$subcmd" $cargo_args "$@"
}
cleanup () {
if [ -n "$template_file" ] && [ -e "$template_file" ]; then
rm "$template_file"
fi
}
trap cleanup EXIT INT TERM HUP
if $lint; then
export RUSTFLAGS="--deny=warnings ${RUSTFLAGS}"
export RUSTDOCFLAGS="--deny=warnings ${RUSTDOCFLAGS}"
fi
workspace_root="$(dirname "$0")/.."
target_dir=${CARGO_TARGET_DIR:-$workspace_root/target}
if [ -n "$target_triple" ]; then
target_dir="$target_dir/$target_triple"
fi
# The directory containing the binaries produced by cargo/rustc.
# Currently, all builds are debug builds.
build_dir="$target_dir/debug"
if [ -n "$FISH_TEST_MAX_CONCURRENCY" ]; then
export RUST_TEST_THREADS="$FISH_TEST_MAX_CONCURRENCY"
export CARGO_BUILD_JOBS="$FISH_TEST_MAX_CONCURRENCY"
fi
template_file=$(mktemp)
(
export FISH_GETTEXT_EXTRACTION_FILE="$template_file"
cargo build --workspace --all-targets --features=gettext-extract
)
if $lint; then
PATH="$build_dir:$PATH" "$workspace_root/build_tools/style.fish" --all --check
for features in "" --no-default-features; do
cargo clippy --workspace --all-targets $features
done
fi
cargo test --no-default-features --workspace --all-targets
cargo test --doc --workspace
if $lint; then
cargo doc --workspace
fi
FISH_GETTEXT_EXTRACTION_FILE=$template_file "$workspace_root/tests/test_driver.py" "$build_dir"
exit
}

View File

@@ -1,26 +0,0 @@
<?xml version="1.0"?>
<![CDATA[
<!-- Sadly we can't enable the following two rules since doing so causes false
positives in standard header files rather than just project specific
source files. If we can find a way to enable these rules by also
excluding system include files we should do so.
<rule version="1">
<pattern> wcwidth \(</pattern>
<message>
<id>wcwidthForbidden</id>
<severity>warning</severity>
<summary>Always use fish_wcwidth rather than wcwidth.</summary>
</message>
</rule>
<rule version="1">
<pattern> wcswidth \(</pattern>
<message>
<id>wcswidthForbidden</id>
<severity>warning</severity>
<summary>Always use fish_wcswidth rather than wcswidth.</summary>
</message>
</rule>
<--!>
]]>

View File

@@ -1,7 +0,0 @@
#!/bin/sh
cppcheck --std=c++11 --quiet \
--suppressions-list=build_tools/cppcheck.suppressions --inline-suppr \
--rule-file=build_tools/cppcheck.rules \
--force \
${@:---enable=all ./src/}

View File

@@ -1,15 +0,0 @@
// suppress all instances of varFuncNullUB: "Passing NULL after the last typed
// argument to a variadic function leads to undefined behaviour." That's
// because all the places we do this are valid and won't cause problems even
// on a ILP64 platform because we're careful about using NULL rather than 0.
varFuncNullUB
// Suppress the warning about unmatched suppressions. At the moment these
// warnings are emitted even when removing the suppression comment results in
// the warning being suppressed. In other words this unmatchedSuppression
// warnings are false positives.
unmatchedSuppression
// Suppress this one because it reports assert(condition && "message"), which we use all over the place
incorrectStringBooleanError
// This is of very little use and pops up *everywhere*.
useStlAlgorithm

15
build_tools/diff_profiles.fish Normal file → Executable file
View File

@@ -5,6 +5,13 @@
#
# Usage: ./diff_profiles.fish profile1.log profile2.log > profile_diff.log
if test (count $argv) -ne 2
echo "Incorrect number of arguments."
echo "Usage: "(status filename)" profile1.log profile2.log"
exit 1
end
set -l profile1 (cat $argv[1])
set -l profile2 (cat $argv[2])
@@ -15,13 +22,13 @@ while set -l next_line_no (math $line_no + 1) && set -q profile1[$next_line_no]
set -l line1 $profile1[$line_no]
set -l line2 $profile2[$line_no]
if not string match -qr '^\d+\t\d+' $line1
if not string match -qr '^\s*\d+\s+\d+' $line1
echo $line1
continue
end
set -l results1 (string match -r '^(\d+)\t(\d+)\s+(.*)' $line1)
set -l results2 (string match -r '^(\d+)\t(\d+)\s+(.*)' $line2)
set -l results1 (string match -r '^\s*(\d+)\s+(\d+)\s+(.*)' $line1)
set -l results2 (string match -r '^\s*(\d+)\s+(\d+)\s+(.*)' $line2)
# times from both files
set -l time1 $results1[2..3]
@@ -42,5 +49,5 @@ while set -l next_line_no (math $line_no + 1) && set -q profile1[$next_line_no]
set diff[1] (math $time1[1] - $time2[1])
set diff[2] (math $time1[2] - $time2[2])
echo $diff[1] $diff[2] $remainder1
printf '%10d %10d %s\n' $diff[1] $diff[2] $remainder1
end

View File

@@ -1,110 +0,0 @@
#!/usr/bin/env fish
# Finds global variables by parsing the output of 'nm'
# for object files in this directory.
# This was written for macOS nm.
set -l FISH_SOURCE_DIR $argv[1]
if not test -d "$FISH_SOURCE_DIR"
echo "FISH_SOURCE_DIR not given"
exit 1
end
set -g whitelist \
# unclear what this is \
l_constinit \
# hacks to work around missing ncurses strings on mac \
sitm_esc ritm_esc dim_esc
# In our nm regex, we are interested in data (dD) and bss (bB) segments.
set -g nm_regex '^([^ ]+) ([dDbB])'
set -l total_globals 0
set -l boring_files \
fish_key_reader.cpp.o \
fish_tests.cpp.o \
fish_indent.cpp.o
# return if we should ignore the given symbol name
function should_ignore
set -l symname $argv[1]
string match -q '*guard variable for*' $symname
and return 0
contains $symname $whitelist
and return 0
return 1
end
# echo a cleaned-up symbol name, e.g. replacing template gunk
function cleanup_syname
set -l symname $argv[1]
set symname (string replace --all 'std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >' 'wcstring' $symname)
set symname (string replace --all 'std::__1::vector<wcstring, std::__1::allocator<wcstring > >' 'wcstring_list_t' $symname)
echo $symname
end
# Output the declaration for a symbol name in a given file.
function print_decl -a FISH_SOURCE_DIR objfile symname
set -l varname (string split '::' $symname)[-1]
set -l srcfile (basename $objfile .o)
set -l srcpath $FISH_SOURCE_DIR/src/$srcfile
# A leading underscore indicates a global, strip it.
set varname (string replace --regex '^_' '' $varname)
if not test -f "$srcpath"
echo "Could not find $srcpath"
end
# Guess the variable as the first usage of the name.
# Strip everything after the first =.
set -l vardecl (egrep -m 1 " $varname\\b" $srcpath | cut -f -1 -d '=' | string trim)
if test -z "$vardecl"
echo "COULD_NOT_FIND_$varname"
return 1
end
echo $vardecl
return 0
end
# Return if a variable declaration is "thread safe".
function decl_is_threadsafe
set -l vardecl $argv[1]
# decls starting with 'const ' or containing ' const ' are assumed safe.
string match -q --regex '(^|\\*| )const ' $vardecl
and return 0
# Ordinary types indicating a safe variable.
set -l safes relaxed_atomic_bool_t std::mutex std::condition_variable std::once_flag sig_atomic_t
for safe in $safes
string match -q "*$safe*" $vardecl
and return 0
end
# Template types indicate a safe variable.
set safes owning_lock mainthread_t std::atomic relaxed_atomic_t latch_t
for safe in $safes
string match -q "*$safe<*" $vardecl
and return 0
end
end
for file in ./**.o
set -l filename (basename $file)
# Skip boring files.
contains $filename $boring_files
and continue
for line in (nm -p -P -U $file | egrep $nm_regex)
set -l matches (string match --regex $nm_regex -- $line)
or continue
set -l symname (cleanup_syname (echo $matches[2] | c++filt))
should_ignore $symname
and continue
set -l vardecl (print_decl $FISH_SOURCE_DIR $filename $symname)
decl_is_threadsafe $vardecl
and continue
echo $filename $symname $matches[3] ":" $vardecl
set total_globals (math $total_globals + 1)
end
end
echo "Total: $total_globals"

View File

@@ -1,63 +0,0 @@
#!/usr/bin/env python3
# Finds potential ODR violations due to weak symbols.
# For example, if you have two different structs with the same name in different files,
# their inline constructors may collide.
# This works only on Linux. It is designed to be run from the cmake build directory.
# clang seems more willing to emit non-inlined ctors. Of course perform a Debug build.
import re
import subprocess
output = subprocess.check_output(
"nm --radix=d -g --demangle -l --print-size CMakeFiles/fishlib.dir/src/*.o",
shell=True,
universal_newlines=True,
)
files_by_name = {} # Symbol to set of paths
sizes_by_name = {} # Symbol to set of int sizes
for line in output.split("\n"):
# Keep only weak symbols with default values (e.g. emitted inline functions).
# Example line: "0000000000000000 0000000000000107 W symbol_name"
# First number is offset, second is size.
# Note this is decimal because of radix=d.
m = re.match(r"\d+ (\d+) W (.*)\t(.*)", line)
if not m:
continue
size, name, filename = m.groups()
files_by_name.setdefault(name, set()).add(filename)
sizes_by_name.setdefault(name, set()).add(int(size))
odr_violations = 0
for name, sizes in sizes_by_name.items():
if len(sizes) == 1:
continue
files = files_by_name[name]
# Ignore symbols that only appear in one file.
# These are typically headers - unclear why they get different sizes but it appears benign.
if len(files) == 1:
continue
# Multiple sizes for this symbol name.
odr_violations += 1
print("Multiple sizes for symbol: " + name)
print("\t%s" % ", ".join([str(x) for x in sizes]))
print("\tFound in files:")
for filename in files:
print("\t\t%s" % filename)
if odr_violations == 0:
print("No ODR violations found, hooray\n")
# Show potential weak symbols.
suspicious_odrs = 0
for (name, files) in files_by_name.items():
if len(files) != 1:
continue
(filename,) = files
if ".cpp" in filename:
if suspicious_odrs == 0:
print("Some suspicious singles:")
suspicious_odrs += 1
print("\t%s" % name)
print("\t\tIn file %s" % filename)

View File

@@ -1,60 +1,147 @@
#!/usr/bin/env fish
#
# Tool to generate messages.pot
# Extended to replace the old Makefile rule which did not port easily to CMake
# Tool to generate gettext messages template file.
# Writes to stdout.
# Intended to be called from `update_translations.fish`.
# This script was originally motivated to work around a quirk (or bug depending on your viewpoint)
# of the xgettext command. See https://lists.gnu.org/archive/html/bug-gettext/2014-11/msg00006.html.
# However, it turns out that even if that quirk did not exist we would still need something like
# this script to properly extract descriptions. That's because we need to normalize the strings to
# a format that xgettext will handle correctly. Also, `xgettext -LShell` doesn't correctly extract
# all the strings we want translated. So we extract and normalize all such strings into a format
# that `xgettext` can handle.
argparse use-existing-template= -- $argv
or exit $status
# Start with the C++ source
xgettext -k -k_ -kN_ -LC++ --no-wrap -o messages.pot src/*.cpp src/*.h
begin
# Write header. This is required by msguniq.
# Note that this results in the file being overwritten.
# This is desired behavior, to get rid of the results of prior invocations
# of this script.
begin
echo 'msgid ""'
echo 'msgstr ""'
echo '"Content-Type: text/plain; charset=UTF-8\n"'
echo ""
end
# This regex handles descriptions for `complete` and `function` statements. These messages are not
# particularly important to translate. Hence the "implicit" label.
set -l implicit_regex '(?:^| +)(?:complete|function).*? (?:-d|--description) (([\'"]).+?(?<!\\\\)\\2).*'
set -g workspace_root (path resolve (status dirname)/..)
# This regex handles explicit requests to translate a message. These are more important to translate
# than messages which should be implicitly translated.
set -l explicit_regex '.*\( *_ (([\'"]).+?(?<!\\\\)\\2) *\).*'
set -l rust_extraction_file
if set -l --query _flag_use_existing_template
set rust_extraction_file $_flag_use_existing_template
else
set rust_extraction_file (mktemp)
# We need to build to ensure that the proc macro for extracting strings runs.
FISH_GETTEXT_EXTRACTION_FILE=$rust_extraction_file cargo check --no-default-features --features=gettext-extract
or exit 1
end
# Create temporary directory for these operations. OS X `mktemp` is somewhat restricted, so this block
# works around that - based on share/functions/funced.fish.
set -q TMPDIR
or set -l TMPDIR /tmp
set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX)
or exit 1
function mark_section
set -l section_name $argv[1]
echo 'msgid "fish-section-'$section_name'"'
echo 'msgstr ""'
echo ''
end
mkdir -p $tmpdir/implicit/share/completions $tmpdir/implicit/share/functions
mkdir -p $tmpdir/explicit/share/completions $tmpdir/explicit/share/functions
mark_section tier1-from-rust
for f in share/config.fish share/completions/*.fish share/functions/*.fish
# Extract explicit attempts to translate a message. That is, those that are of the form
# `(_ "message")`.
string replace --filter --regex $explicit_regex 'echo $1' <$f | fish >$tmpdir/explicit/$f.tmp 2>/dev/null
while read description
echo 'N_ "'(string replace --all '"' '\\"' -- $description)'"'
end <$tmpdir/explicit/$f.tmp >$tmpdir/explicit/$f
rm $tmpdir/explicit/$f.tmp
# Get rid of duplicates and sort.
msguniq --no-wrap --sort-output $rust_extraction_file
or exit 1
# Handle `complete` / `function` description messages. The `| fish` is subtle. It basically
# avoids the need to use `source` with a command substitution that could affect the current
# shell.
string replace --filter --regex $implicit_regex 'echo $1' <$f | fish >$tmpdir/implicit/$f.tmp 2>/dev/null
while read description
# We don't use `string escape` as shown in the next comment because it produces output that
# is not parsed correctly by xgettext. Instead just escape double-quotes and quote the
# resulting string.
echo 'N_ "'(string replace --all '"' '\\"' -- $description)'"'
end <$tmpdir/implicit/$f.tmp >$tmpdir/implicit/$f
rm $tmpdir/implicit/$f.tmp
end
if not set -l --query _flag_use_existing_template
rm $rust_extraction_file
end
xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot $tmpdir/explicit/share/*/*.fish
xgettext -j -k -kN_ -LShell --from-code=UTF-8 -cDescription --no-wrap -o messages.pot $tmpdir/implicit/share/*/*.fish
function extract_fish_script_messages_impl
set -l regex $argv[1]
set -e argv[1]
# Using xgettext causes more trouble than it helps.
# This is due to handling of escaping in fish differing from formats xgettext understands
# (e.g. POSIX shell strings).
# We work around this issue by manually writing the file content.
rm -r $tmpdir
# Steps:
# 1. We extract strings to be translated from the relevant files and drop the rest. This step
# depends on the regex matching the entire line, and the first capture group matching the
# string.
# 2. We unescape. This gets rid of some escaping necessary in fish strings.
# 3. The resulting strings are sorted alphabetically. This step is optional. Not sorting would
# result in strings from the same file appearing together. Removing duplicates is also
# optional, since msguniq takes care of that later on as well.
# 4. Single backslashes are replaced by double backslashes. This results in the backslashes
# being interpreted as literal backslashes by gettext tooling.
# 5. Double quotes are escaped, such that they are not interpreted as the start or end of
# a msgid.
# 6. We transform the string into the format expected in a PO file.
cat $argv |
string replace --filter --regex $regex '$1' |
string unescape |
sort -u |
sed -E -e 's_\\\\_\\\\\\\\_g' -e 's_"_\\\\"_g' -e 's_^(.*)$_msgid "\1"\nmsgstr ""\n_'
end
function extract_fish_script_messages
set -l tier $argv[1]
set -e argv[1]
if not set -q argv[1]
return
end
# This regex handles explicit requests to translate a message. These are more important to translate
# than messages which should be implicitly translated.
set -l explicit_regex '.*\( *_ (([\'"]).+?(?<!\\\\)\\2) *\).*'
mark_section "$tier-from-script-explicitly-added"
extract_fish_script_messages_impl $explicit_regex $argv
# This regex handles descriptions for `complete` and `function` statements. These messages are not
# particularly important to translate. Hence the "implicit" label.
set -l implicit_regex '^(?:\s|and |or )*(?:complete|function).*? (?:-d|--description) (([\'"]).+?(?<!\\\\)\\2).*'
mark_section "$tier-from-script-implicitly-added"
extract_fish_script_messages_impl $implicit_regex $argv
end
set -g share_dir $workspace_root/share
set -l tier1 $share_dir/config.fish
set -l tier2
set -l tier3
for file in $share_dir/completions/*.fish $share_dir/functions/*.fish
# set -l tier (string match -r '^# localization: .*' <$file)
set -l tier (string replace -rf -m1 \
'^# localization: (.*)$' '$1' <$file)
if set -q tier[1]
switch "$tier"
case tier1 tier2 tier3
set -a $tier $file
case 'skip*'
case '*'
echo >&2 "$file:1 unexpected localization tier: $tier"
exit 1
end
continue
end
set -l dirname (path basename (path dirname $file))
set -l command_name (path basename --no-extension $file)
if test $dirname = functions &&
string match -q -- 'fish_*' $command_name
set -a tier1 $file
continue
end
if test $dirname != completions
echo >&2 "$file:1 missing localization tier for function file"
exit 1
end
if test -e $workspace_root/doc_src/cmds/$command_name.rst
set -a tier1 $file
else
set -a tier3 $file
end
end
extract_fish_script_messages tier1 $tier1
extract_fish_script_messages tier2 $tier2
extract_fish_script_messages tier3 $tier3
end |
# At this point, all extracted strings have been written to stdout,
# starting with the ones taken from the Rust sources,
# followed by strings explicitly marked for translation in fish scripts,
# and finally the strings from fish scripts which get translated implicitly.
# Because we do not eliminate duplicates across these categories,
# we do it here, since other gettext tools expect no duplicates.
msguniq --no-wrap

View File

@@ -47,24 +47,24 @@ then
# HACK: Git failed, so we keep the current version file.
# This helps in case you built fish as a normal user
# and then try to `sudo make install` it.
date +%s > ${OUTPUT_DIR}fish-build-version-witness.txt
date +%s > "${OUTPUT_DIR}"fish-build-version-witness.txt
exit 0
fi
if test -r "$FBVF"
then
VC=$(grep -v '^#' "$FBVF" | tr -d '"' | sed -e 's/^FISH_BUILD_VERSION=//')
VC=$(cat "$FBVF")
else
VC="unset"
fi
# Maybe output the FBVF
# It looks like FISH_BUILD_VERSION="2.7.1-621-ga2f065e6"
# It looks like "2.7.1-621-ga2f065e6"
test "$VN" = "$VC" || {
echo >&2 "FISH_BUILD_VERSION=$VN"
echo "FISH_BUILD_VERSION=\"$VN\"" >"$FBVF"
echo >&2 "$VN"
echo "$VN" >"$FBVF"
}
# Output the fish-build-version-witness.txt
# See https://cmake.org/cmake/help/v3.4/policy/CMP0058.html
date +%s > ${OUTPUT_DIR}fish-build-version-witness.txt
date +%s > "${OUTPUT_DIR}"fish-build-version-witness.txt

View File

@@ -0,0 +1,392 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>platform-application</key>
<true/>
<key>com.apple.private.security.no-container</key>
<true/>
<key>com.apple.private.security.container-manager</key>
<true/>
<key>com.apple.private.skip-library-validation</key>
<true/>
<key>com.apple.private.MobileContainerManager.allowed</key>
<true/>
<key>com.apple.private.security.storage.adprivacyd</key>
<true/>
<key>com.apple.private.security.storage.amfid</key>
<true/>
<key>com.apple.private.security.storage.AppBundles</key>
<true/>
<key>com.apple.private.security.storage.AppDataContainers</key>
<true/>
<key>com.apple.private.security.storage.automation-mode</key>
<true/>
<key>com.apple.private.security.storage.Biome</key>
<true/>
<key>com.apple.private.security.storage.Calendar</key>
<true/>
<key>com.apple.private.security.storage.CallHistory</key>
<true/>
<key>com.apple.private.security.storage.CarrierBundles</key>
<true/>
<key>com.apple.private.security.storage.chronod</key>
<true/>
<key>com.apple.private.security.storage.CloudDocsDB</key>
<true/>
<key>com.apple.private.security.storage.CloudKit</key>
<true/>
<key>com.apple.private.security.storage.containers</key>
<true/>
<key>com.apple.private.security.storage.CoreFollowUp</key>
<true/>
<key>com.apple.private.security.storage.CoreKnowledge</key>
<true/>
<key>com.apple.private.security.storage.Cryptex</key>
<true/>
<key>com.apple.private.security.storage.demo_backup</key>
<true/>
<key>com.apple.private.security.storage.DocumentRevisions</key>
<true/>
<key>com.apple.private.security.storage.DumpPanic</key>
<true/>
<key>com.apple.private.security.storage.ExposureNotification</key>
<true/>
<key>com.apple.private.security.storage.FaceTime</key>
<true/>
<key>com.apple.private.security.storage.familycircled</key>
<true/>
<key>com.apple.private.security.storage.FindMy</key>
<true/>
<key>com.apple.private.security.storage.fpsd</key>
<true/>
<key>com.apple.private.security.storage.Health</key>
<true/>
<key>com.apple.private.security.storage.HomeAI</key>
<true/>
<key>com.apple.private.security.storage.HomeKit</key>
<true/>
<key>com.apple.private.security.storage.iCloudDrive</key>
<true/>
<key>com.apple.private.security.storage.idcredd</key>
<true/>
<key>com.apple.private.security.storage.IdentityServices</key>
<true/>
<key>com.apple.private.security.storage.kbd</key>
<true/>
<key>com.apple.private.security.storage.Keychains</key>
<true/>
<key>com.apple.private.security.storage.Lockdown</key>
<true/>
<key>com.apple.private.security.storage.Mail</key>
<true/>
<key>com.apple.private.security.storage.Messages</key>
<true/>
<key>com.apple.private.security.storage.MessagesMetaData</key>
<true/>
<key>com.apple.private.security.storage.MobileContainerManager</key>
<true/>
<key>com.apple.private.security.storage.MobileDocuments</key>
<true/>
<key>com.apple.private.security.storage.MobileIdentityService</key>
<true/>
<key>com.apple.private.security.storage.mobilesync</key>
<true/>
<key>com.apple.private.security.storage.multimodalsearchd</key>
<true/>
<key>com.apple.private.security.storage.NanoTimeKit.FaceSupport</key>
<true/>
<key>com.apple.private.security.storage.News</key>
<true/>
<key>com.apple.private.security.storage.Notes</key>
<true/>
<key>com.apple.private.security.storage.Photos</key>
<true/>
<key>com.apple.private.security.storage.PhotosLibraries</key>
<true/>
<key>com.apple.private.security.storage.pipelined</key>
<true/>
<key>com.apple.private.security.storage.preferences</key>
<true/>
<key>com.apple.private.security.storage.PrivacyAccounting</key>
<true/>
<key>com.apple.private.security.storage.Safari</key>
<true/>
<key>com.apple.private.security.storage.SearchParty</key>
<true/>
<key>com.apple.private.security.storage.SecureElementService</key>
<true/>
<key>com.apple.private.security.storage.SensorKit</key>
<true/>
<key>com.apple.private.security.storage.SFAnalytics</key>
<true/>
<key>com.apple.private.security.storage.SiriInference</key>
<true/>
<key>com.apple.private.security.storage.SiriReferenceResolution</key>
<true/>
<key>com.apple.private.security.storage.SiriVocabulary</key>
<true/>
<key>com.apple.private.security.storage.SoC</key>
<true/>
<key>com.apple.private.security.storage.SpeechPersonalizedLM</key>
<true/>
<key>com.apple.private.security.storage.Spotlight</key>
<true/>
<key>com.apple.private.security.storage.StatusKit</key>
<true/>
<key>com.apple.private.security.storage.Stocks</key>
<true/>
<key>com.apple.private.security.storage.Suggestions</key>
<true/>
<key>com.apple.private.security.storage.SymptomFramework</key>
<true/>
<key>com.apple.private.security.storage.sysdagnose.ScreenshotServicesService</key>
<true/>
<key>com.apple.private.security.storage.TCC</key>
<true/>
<key>com.apple.private.security.storage.TimeMachine</key>
<true/>
<key>com.apple.private.security.storage.triald</key>
<true/>
<key>com.apple.private.security.storage.trustd</key>
<true/>
<key>com.apple.private.security.storage.trustd-private</key>
<true/>
<key>com.apple.private.security.storage.universalaccess</key>
<true/>
<key>com.apple.private.security.storage.Voicemail</key>
<true/>
<key>com.apple.private.security.storage.Wireless</key>
<true/>
<key>com.apple.private.security.disk-device-access</key>
<true/>
<key>com.apple.rootless.storage.ane_model_cache</key>
<true/>
<key>com.apple.rootless.storage.apfs_boot_mount</key>
<true/>
<key>com.apple.rootless.storage.clientScripter</key>
<true/>
<key>com.apple.rootless.storage.com.apple.mediaanalysisd</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.CarPlayAppBlacklist</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.DeviceCheck</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.DictionaryServices.dictionary2</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.DuetExpertCenterAsset</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.EmbeddedNL</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Font5</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Font6</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.HealthKt.FeatureAvailability</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.HomeKit</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.MacinTalkVoiceAssets</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.MailDynamicData</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.MXLongFormVideoApps</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.network.networknomicon</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.PKITrustSupplementals</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.SharingDeviceAssets</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.SiriShortcutsMobileAsset</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.TimeZoneUpdate</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.CombinedVocalizerVoices</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.CustomVoice</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.GryphonVoice</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceServicesVocalizerVoice</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceServices.VoiceResources</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.VoiceTriggerAssets</key>
<true/>
<key>com.apple.rootless.storage.CoreAnalytics</key>
<true/>
<key>com.apple.rootless.storage.coreduet_knowledge_store</key>
<true/>
<key>com.apple.rootless.storage.coreidvd</key>
<true/>
<key>com.apple.rootless.storage.coreknowledge</key>
<true/>
<key>com.apple.rootless.storage.CoreRoutine</key>
<true/>
<key>com.apple.rootless.storage.CoreSpeech</key>
<true/>
<key>com.apple.rootless.storage.dmd</key>
<true/>
<key>com.apple.rootless.storage.dprivacyd_storage</key>
<true/>
<key>com.apple.rootless.storage.ExtensibleSSO</key>
<true/>
<key>com.apple.rootless.storage.facekit</key>
<true/>
<key>com.apple.rootless.storage.fpsd</key>
<true/>
<key>com.apple.rootless.storage.MobileStorageMounter</key>
<true/>
<key>com.apple.rootless.storage.MusicApp</key>
<true/>
<key>com.apple.rootless.storage.nsurlsessiond</key>
<true/>
<key>com.apple.rootless.storage.pearl-field-diagnostics</key>
<true/>
<key>com.apple.rootless.storage.proactivepredictions</key>
<true/>
<key>com.apple.rootless.storage.QLThumbnailCache</key>
<true/>
<key>com.apple.rootless.storage.remotemanagementd</key>
<true/>
<key>com.apple.rootless.storage.RoleAccountStaging</key>
<true/>
<key>com.apple.rootless.storage.sensorkit</key>
<true/>
<key>com.apple.rootless.storage.shortcuts</key>
<true/>
<key>com.apple.rootless.storage.siriremembers</key>
<true/>
<key>com.apple.rootless.storage.timezone</key>
<true/>
<key>com.apple.rootless.storage.triald</key>
<true/>
<key>com.apple.rootless.storage.voiceshortcuts</key>
<true/>
<key>com.apple.private.security.storage-exempt.heritable</key>
<true/>
<key>com.apple.private.security.storage.AppleMediaServices</key>
<true/>
<key>com.apple.private.security.storage.ContactlessReader</key>
<true/>
<key>com.apple.private.security.storage.CoreRoutine</key>
<true/>
<key>com.apple.private.security.storage.DiagnosticReports</key>
<true/>
<key>com.apple.private.security.storage.DiagnosticReports.read-write</key>
<true/>
<key>com.apple.private.security.storage.DoNotDisturb</key>
<true/>
<key>com.apple.private.security.storage.Home</key>
<true/>
<key>com.apple.private.security.storage.IntelligencePlatform</key>
<true/>
<key>com.apple.private.security.storage.Location</key>
<true/>
<key>com.apple.private.security.storage.ManagedConfiguration</key>
<true/>
<key>com.apple.private.security.storage.MapsSync</key>
<true/>
<key>com.apple.private.security.storage.MobileBackup</key>
<true/>
<key>com.apple.private.security.storage.MobileStorageMounter</key>
<true/>
<key>com.apple.private.security.storage.PassKit</key>
<true/>
<key>com.apple.private.security.storage.SiriFeatureStore</key>
<true/>
<key>com.apple.private.security.storage.SiriSELF</key>
<true/>
<key>com.apple.private.security.storage.SoundProfileAsset</key>
<true/>
<key>com.apple.private.security.storage.TextUnderstanding</key>
<true/>
<key>com.apple.private.security.storage.Weather</key>
<true/>
<key>com.apple.private.security.storage.appleaccountd</key>
<true/>
<key>com.apple.private.security.storage.ciconia</key>
<true/>
<key>com.apple.private.security.storage.clipserviced</key>
<true/>
<key>com.apple.private.security.storage.coreduet_knowledge_store</key>
<true/>
<key>com.apple.private.security.storage.driverkitd</key>
<true/>
<key>com.apple.private.security.storage.geoanalyticsd</key>
<true/>
<key>com.apple.private.security.storage.geod</key>
<true/>
<key>com.apple.private.security.storage.launchd</key>
<true/>
<key>com.apple.private.security.storage.sessionkitd</key>
<true/>
<key>com.apple.private.security.storage.sysdiagnose.ScreenshotServicesService</key>
<true/>
<key>com.apple.private.security.storage.sysdiagnose.sysdiagnose</key>
<true/>
<key>com.apple.private.security.storage.tmp</key>
<true/>
<key>com.apple.rootless.critical</key>
<true/>
<key>com.apple.rootless.datavault.metadata</key>
<true/>
<key>com.apple.rootless.install</key>
<true/>
<key>com.apple.rootless.install.heritable</key>
<true/>
<key>com.apple.rootless.restricted-block-devices</key>
<true/>
<key>com.apple.rootless.storage.MobileAssetDownload</key>
<true/>
<key>com.apple.rootless.storage.amsengagementd</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.HealthKit.FeatureAvailability</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriDialogAssets</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriExperienceCam</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriFindMyConfigurationFiles</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriInferredHelpfulness</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriTextToSpeech</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrAssistant</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrHammer</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAsrUaap</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingAttentionAssets</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingMorphun</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingNL</key>
<true/>
<key>com.apple.rootless.storage.com.apple.MobileAsset.Trial.Siri.SiriUnderstandingNLOverrides</key>
<true/>
<key>com.apple.rootless.storage.coreparsec_feedbacks</key>
<true/>
<key>com.apple.rootless.storage.coreparsec_uploadables</key>
<true/>
<key>com.apple.rootless.storage.early_boot_mount</key>
<true/>
<key>com.apple.rootless.storage.screentime</key>
<true/>
<key>com.apple.rootless.volume.ISCRecovery</key>
<true/>
<key>com.apple.rootless.volume.Preboot</key>
<true/>
<key>com.apple.rootless.volume.Recovery</key>
<true/>
<key>com.apple.rootless.volume.Update</key>
<true/>
<key>com.apple.rootless.volume.VM</key>
<true/>
<key>com.apple.rootless.volume.iSCPreboot</key>
<true/>
</dict>
</plist>

View File

@@ -1,28 +0,0 @@
# Map file for the include-what-you-use tool on Linux.
[
{ include: ["<bits/fcntl-linux.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<bits/mman-linux.h>", "private", "<sys/mman.h>", "public"] },
{ include: ["<bits/socket-linux.h>", "private", "<sys/socket.h>", "public"] },
{ include: ["<bits/socket_type.h>", "private", "<sys/socket.h>", "public"] },
{ include: ["<bits/local_lim.h>", "private", "<limits.h>", "public"] },
{ include: ["<tr1/memory>", "public", "<memory>", "public"] },
{ include: ["<features.h>", "public", "<stdio.h>", "public"] },
{ include: ["<features.h>", "public", "<stddef.h>", "public"] },
{ include: ["<features.h>", "public", "<unistd.h>", "public"] },
{ symbol: ["size_t", "private", "<unistd.h>", "public"] },
{ symbol: ["size_t", "private", "<stddef.h>", "public"] },
{ symbol: ["size_t", "private", "<stdlib.h>", "public"] },
{ symbol: ["intmax_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["intmax_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uint32_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uint32_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uint64_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uint64_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uintmax_t", "private", "<sys/stdint.h>", "public"] },
{ symbol: ["uintmax_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["clock_gettime", "private", "<sys/time.h>", "public"] },
{ symbol: ["timespec", "private", "<sys/time.h>", "public"] },
{ symbol: ["memset", "private", "<string.h>", "public"] },
{ symbol: ["strerror", "private", "<string.h>", "public"] },
]

View File

@@ -1,171 +0,0 @@
# Map file for the include-what-you-use tool on OS X. For some reason
# the version installed by HomeBrew doesn't have useful mappings for the
# system provided headers. This also has mappings for FreeBSD.
[
{ include: ["<__functional_base>", private, "<functional>", public ] },
{ include: ["<__mutex_base>", private, "<mutex>", public ] },
{ include: ["@<__algorithm/.*>", "private", "<algorithm>", "public"] },
{ include: ["@<__iterator/.*>", "private", "<iterator>", "public"] },
{ include: ["@<__functional/.*>", "private", "<functional>", "public"] },
{ include: ["@<__memory/.*>", "private", "<memory>", "public"] },
{ include: ["@<__utility/.*>", "private", "<utility>", "public"] },
{ include: ["@<__chrono/.*>", "private", "<chrono>", "public"] },
{ include: ["@<__numeric/.*>", "private", "<numeric>", "public"] },
{ include: ["@<__random/.*>", "private", "<random>", "public"] },
{ include: ["@<__locale/.*>", "private", "<locale>", "public"] },
{ include: ["@<xlocale/.*>", "private", "<xlocale.h>", "public"] },
# ratio false positive. See https://groups.google.com/g/include-what-you-use/c/OKVkkWUlx44
{ include: ["<ratio>", "public", "<chrono>", "public"] },
{ include: ["<__locale>", "private", "<locale>", "public"] },
{ include: ["<_ctype.h>", "private", "<ctype.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_once_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_mutex_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_rwlock_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_mutexattr_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_attr_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_cond_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthread/_pthread_key_t.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_pthreadtypes.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_types/_posix_vdisable.h>", "private", "<pthread.h>", "public"] },
{ include: ["<sys/_types/_time_t.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_types/_suseconds_t.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_types/_suseconds_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/errno.h>", "private", "<errno.h>", "public"] },
{ include: ["<sys/unistd.h>", "private", "<unistd.h>", "public"] },
{ include: ["<_wctype.h>", "private", "<wctype.h>", "public"] },
{ include: ["<sys/fcntl.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<sys/_types/_seek_set.h>", "private", "<fcntl.h>", "public"] },
{ include: ["<sys/_types/_mbstate_t.h>", "private", "<wchar.h>", "public"] },
{ include: ["<iosfwd>", "public", "<string>", "public"] },
{ include: ["<sys/_stdint.h>", "private", "<stdint.h>", "public"] },
{ include: ["<sys/_types/_s_ifmt.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_size_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_size_t.h>", "private", "<stdlib.h>", "public"] },
{ include: ["<sys/_types/_mode_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_pid_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_def.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_isset.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_set.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_fd_zero.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_timeval.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_uid_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_intmax_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uintmax_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uint8_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_int32_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<_types/_uint64_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_uintptr_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_dev_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_ino_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_va_list.h>", "private", "<stdio.h>", "public"] },
{ include: ["<__functional_base>", "private", "<memory>", "public"] },
{ include: ["<__functional_base>", "private", "<vector>", "public"] },
{ include: ["<__functional_base>", "private", "<string>", "public"] },
{ include: ["<__tree>", "private", "<map>", "public"] },
{ include: ["<__tree>", "private", "<set>", "public"] },
{ include: ["<_types/_uint32_t.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_va_list.h>", "private", "<sys/types.h>", "public"] },
{ include: ["<sys/_types/_sigset_t.h>", "private", "<signal.h>", "public"] },
{ include: ["<sys/signal.h>", "private", "<signal.h>", "public"] },
{ include: ["<sys/termios.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/_termios.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/ttycom.h>", "private", "<termios.h>", "public"] },
{ include: ["<sys/syslimits.h>", "private", "<limits.h>", "public"] },
{ include: ["<i386/limits.h>", "private", "<limits.h>", "public"] },
{ include: ["<sys/limits.h>", "private", "<limits.h>", "public"] },
{ include: ["<sys/_types/_wint_t.h>", "private", "<stddef.h>", "public"] },
{ include: ["<sys/_select.h>", "private", "<select.h>", "public"] },
{ include: ["<sys/cdefs.h>", "private", "<unistd.h>", "public"] },
{ include: ["<istream>", "public", "<iostream>", "public"] },
{ include: ["<sys/_endian.h>", "private", "<netinet/in.h>", "public"] },
{ include: ["<sys/_types/_timespec.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/_timespec.h>", "private", "<time.h>", "public"] },
{ include: ["<sys/spawn.h>", "private", "<spawn.h>", "public"] },
{ include: ["<sys/dirent.h>", "private", "<dirent.h>", "public"] },
{ include: ["<__mutex_base>", "private", "<mutex>", "public"] },
{ include: ["<__hash_table>", "private", "<unordered_map>", "public"] },
{ include: ["<__hash_table>", "private", "<unordered_set>", "public"] },
{ include: ['"../common.h"', "public", '"common.h"', "public"] },
# We provide our own assert. including assert.h/cassert spoils it and redefines the macro
{ symbol: ["assert", "private", '"common.h"', "public"] },
{ symbol: ["assert", "private", '"../common.h"', "public"] },
{ symbol: ["wcstring", "private", '"common.h"', "public"] },
{ symbol: ["wcstring", "private", '"../common.h"', "public"] },
{ symbol: ["wcstring_list_t", "private", '"common.h"', "public"] },
{ symbol: ["wcstring_list_t", "private", '"../common.h"', "public"] },
{ symbol: ["wcstring", "private", '"flog.h"', "public"] },
{ symbol: ["wcstring_list_t", "private", '"flog.h"', "public"] },
{ symbol: ["size_t", "private", "<cstddef>", "public"] },
{ symbol: ["mutex", "private", "<mutex>", "public"] },
{ symbol: ["sig_atomic_t", "private", "<csignal>", "public"] },
{ symbol: ["va_end", "private", "<stdarg.h>", "public"] },
{ symbol: ["va_list", "private", "<stdarg.h>", "public"] },
{ symbol: ["va_start", "private", "<stdarg.h>", "public"] },
{ symbol: ["NULL", "private", "<cstddef>", "public"] },
{ symbol: ["NULL", "private", "<stdlib.h>", "public"] },
{ symbol: ["NULL", "private", "<stdio.h>", "public"] },
{ symbol: ["NULL", "private", "<unistd.h>", "public"] },
{ symbol: ["off_t", "private", "<unistd.h>", "public"] },
{ symbol: ["off_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["size_t", "private", "<cstddef>", "public"] },
{ symbol: ["ssize_t", "private", "<cstddef>", "public"] },
{ symbol: ["intptr_t", "private", "<unistd.h>", "public"] },
{ symbol: ["gid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["uid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["pid_t", "private", "<unistd.h>", "public"] },
{ symbol: ["pid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["uid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["gid_t", "private", "<sys/types.h>", "public"] },
{ symbol: ["timeval", "private", "<sys/time.h>", "public"] },
{ symbol: ["__uint32_t", "private", "<cstdint>", "public"] },
{ symbol: ["uint32_t", "private", "<cstdint>", "public"] },
{ symbol: ["intptr_t", "private", "<cstdint>", "public"] },
{ symbol: ["tparm", "private", "<ncurses.h>", "public"] },
{ symbol: ["select", "private", "<sys/select.h>", "public"] },
{ symbol: ["_LIBCPP_VERSION", "private", "<cstddef>", "public"] },
{ symbol: ["_LIBCPP_VERSION", "private", "<unistd.h>", "public"] },
{ symbol: ["MB_CUR_MAX", "private", "<cstdlib>", "public"] },
{ symbol: ["MB_LEN_MAX", "private", "<cstdlib>", "public"] },
{ symbol: ["WEOF", "private", "<cwctype>", "public"] },
{ symbol: [ "std::declval", private, "<utility>", public ] },
{ symbol: [ "std::forward", private, "<utility>", public ] },
{ symbol: [ "std::move", private, "<utility>", public ] },
{ symbol: [ "std::nullptr_t", private, "<cstddef>", public ] },
{ symbol: [ "std::string", private, "<string>", public ] },
{ symbol: [ "std::isalnum", private, "<locale>", public ] },
{ symbol: [ "std::toupper", private, "<locale>", public ] },
{ symbol: [ "sem_t", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_post", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_wait", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_init", private, "<semaphore.h>", public ] },
{ symbol: [ "sem_destroy", private, "<semaphore.h>", public ] },
{ symbol: [ "FD_SETSIZE", private, "<sys/select.h>", public ] },
{ symbol: [ "locale_t", private, "<locale>", public ] },
{ include: [ "<assert.h>", public, "<cassert>", public ] },
{ include: [ "<complex.h>", public, "<ccomplex>", public ] },
{ include: [ "<ctype.h>", public, "<cctype>", public ] },
{ include: [ "<errno.h>", public, "<cerrno>", public ] },
{ include: [ "<fenv.h>", public, "<cfenv>", public ] },
{ include: [ "<float.h>", public, "<cfloat>", public ] },
{ include: [ "<inttypes.h>", public, "<cinttypes>", public ] },
{ include: [ "<iso646.h>", public, "<ciso646>", public ] },
{ include: [ "<limits.h>", public, "<climits>", public ] },
{ include: [ "<locale.h>", public, "<clocale>", public ] },
{ include: [ "<math.h>", public, "<cmath>", public ] },
{ include: [ "<setjmp.h>", public, "<csetjmp>", public ] },
{ include: [ "<signal.h>", public, "<csignal>", public ] },
{ include: [ "<stdalign.h>", public, "<cstdalign>", public ] },
{ include: [ "<stdarg.h>", public, "<cstdarg>", public ] },
{ include: [ "<stdbool.h>", public, "<cstdbool>", public ] },
{ include: [ "<stddef.h>", public, "<cstddef>", public ] },
{ include: [ "<stdlib.h>", public, "<cstdlib>", public ] },
{ include: [ "<string.h>", public, "<cstring>", public ] },
{ include: [ "<tgmath.h>", public, "<ctgmath>", public ] },
{ include: [ "<time.h>", public, "<ctime>", public ] },
{ include: [ "<uchar.h>", public, "<cuchar>", public ] },
{ include: [ "<wchar.h>", public, "<cwchar>", public ] },
{ include: [ "<wctype.h>", public, "<cwctype>", public ] },
{ include: [ "<_xlocale.h>", private, "<xlocale.h>", public ] },
]

View File

@@ -1,119 +0,0 @@
#!/usr/bin/env fish
#
# This is meant to be run by "make lint" or "make lint-all". It is not meant to
# be run directly from a shell prompt.
#
# We don't include "missingInclude" as that doesn't find our config.h.
# Missing includes will quickly be found by... compiling the thing anyway.
set -l cppchecks warning,performance,portability,information #,missingInclude
set -l cppcheck_args
set -l c_files
set -l all no
set -l kernel_name (uname -s)
set -l machine_type (uname -m)
argparse a/all p/project= -- $argv
# We only want -D and -I options to be passed thru to cppcheck.
for arg in $argv
if string match -q -- '-D*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
else if string match -q -- '-I*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
else if string match -q -- '-iquote*' $arg
set -a cppcheck_args (string split -- ' ' $arg)
end
end
# Not sure when this became necessary but without these flags cppcheck no longer works on macOS.
# It complains that "Cppcheck cannot find all the include files." Adding these include paths should
# be harmless everywhere else.
set cppcheck_args $cppcheck_args -I /usr/include -I .
if test "$machine_type" = x86_64
set cppcheck_args -D__x86_64__ -D__LP64__ $cppcheck_args
end
if set -q _flag_all
set c_files src/*.cpp
set cppchecks "$cppchecks,unusedFunction"
else
# We haven't been asked to lint all the source. If there are uncommitted
# changes lint those, else lint the files in the most recent commit.
# Select (cached files) (modified but not cached, and untracked files)
set -l files (git diff-index --cached HEAD --name-only)
set files $files (git ls-files --exclude-standard --others --modified)
if not set -q files[1]
# No pending changes so lint the files in the most recent commit.
set files (git diff-tree --no-commit-id --name-only -r HEAD)
end
# Extract just the C/C++ files that exist.
set c_files
for file in (string match -r '.*\.c(?:pp)?$' -- $files)
test -f $file; and set c_files $c_files $file
end
end
# We now have a list of files to check so run the linters.
if set -q c_files[1]
if type -q include-what-you-use
echo
echo ========================================
echo Running IWYU
echo ========================================
for c_file in $c_files
switch $kernel_name
case Darwin FreeBSD
include-what-you-use -Xiwyu --no_default_mappings -Xiwyu \
--mapping_file=build_tools/iwyu.osx.imp --std=c++11 \
$cppcheck_args $c_file 2>&1
case Linux
include-what-you-use -Xiwyu --mapping_file=build_tools/iwyu.linux.imp \
$cppcheck_args $c_file 2>&1
case '*' # hope for the best
include-what-you-use --std=c++11 $cppcheck_args $c_file 2>&1
end
end
end
if type -q cppcheck
echo
echo ========================================
echo Running cppcheck
echo ========================================
build_tools/cppcheck.sh --enable=$cppchecks $c_files 2>&1
echo
echo ========================================
echo 'Running `cppcheck --check-config` to identify missing includes and similar problems.'
echo 'Ignore unmatchedSuppression warnings as they are probably false positives we'
echo 'cannot suppress.'
echo ========================================
cppcheck $cppcheck_args --check-config $c_files 2>&1
end
if type -q oclint
echo
echo ========================================
echo Running oclint
echo ========================================
# The stderr to stdout redirection is because oclint, incorrectly writes its final summary
# counts of the errors detected to stderr. Anyone running this who wants to capture its
# output will expect those messages to be written to stdout.
oclint $c_files -- $argv 2>&1
end
if type -q clang-tidy; and set -q _flag_project
echo
echo ========================================
echo Running clang-tidy
echo ========================================
clang-tidy -p $_flag_project $c_files
end
else
echo
echo 'WARNING: No C/C++ files to check'
echo
end

View File

@@ -0,0 +1,3 @@
# LSAN can detect leaks tracing back to __asan::AsanThread::ThreadStart (probably caused by our
# threads not exiting before their TLS dtors are called). Just ignore it.
leak:AsanThread

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# Helper to notarize an .app.zip or .pkg file.
@@ -13,7 +13,7 @@ for INPUT in "$@"; do
echo "Processing $INPUT"
test -f "$INPUT" || die "Not a file: $INPUT"
ext="${INPUT##*.}"
(test "$ext" = "zip" || test "$ext" = "pkg") || die "Unrecognized extension: $ext"
{ test "$ext" = "zip" || test "$ext" = "pkg"; } || die "Unrecognized extension: $ext"
xcrun notarytool submit "$INPUT" --keychain-profile AC_PASSWORD --wait
@@ -21,9 +21,7 @@ for INPUT in "$@"; do
TMPDIR=$(mktemp -d)
echo "Extracting to $TMPDIR"
unzip -q "$INPUT" -d "$TMPDIR"
# Force glob expansion.
STAPLE_TARGET="$TMPDIR"/*
STAPLE_TARGET=$(echo $STAPLE_TARGET)
STAPLE_TARGET=$(echo "$TMPDIR"/*)
else
STAPLE_TARGET="$INPUT"
fi
@@ -35,7 +33,7 @@ for INPUT in "$@"; do
INPUT_FULL=$(realpath "$INPUT")
rm -f "$INPUT"
cd "$(dirname "$STAPLE_TARGET")"
zip -r -q "$INPUT_FULL" $(basename "$STAPLE_TARGET")
zip -r -q "$INPUT_FULL" "$(basename "$STAPLE_TARGET")"
fi
echo "Processed $INPUT"

177
build_tools/make_macos_pkg.sh Executable file
View File

@@ -0,0 +1,177 @@
#!/usr/bin/env bash
# Script to produce an OS X installer .pkg and .app(.zip)
usage() {
echo "Build macOS packages, optionally signing and notarizing them."
echo "Usage: $0 options"
echo "Options:"
echo " -s Enables code signing"
echo " -f <APP_KEY.p12> Path to .p12 file for application signing"
echo " -i <INSTALLER_KEY.p12> Path to .p12 file for installer signing"
echo " -p <PASSWORD> Password for the .p12 files (necessary to access the certificates)"
echo " -e <entitlements file> (Optional) Path to an entitlements XML file"
echo " -n Enables notarization. This will fail if code signing is not also enabled."
echo " -j <API_KEY.JSON> Path to JSON file generated with \`rcodesign encode-app-store-connect-api-key\` (required for notarization)"
echo
exit 1
}
set -x
set -e
SIGN=
NOTARIZE=
ARM64_DEPLOY_TARGET='MACOSX_DEPLOYMENT_TARGET=11.0'
X86_64_DEPLOY_TARGET='MACOSX_DEPLOYMENT_TARGET=10.9'
# As of this writing, the most recent Rust release supports macOS back to 10.12.
# The first supported version of macOS on arm64 is 10.15, so any Rust is fine for arm64.
# We wish to support back to 10.9 on x86-64; the last version of Rust to support that is
# version 1.73.0.
RUST_VERSION_X86_64=1.70.0
while getopts "sf:i:p:e:nj:" opt; do
case $opt in
s) SIGN=1;;
f) P12_APP_FILE=$(realpath "$OPTARG");;
i) P12_INSTALL_FILE=$(realpath "$OPTARG");;
p) P12_PASSWORD="$OPTARG";;
e) ENTITLEMENTS_FILE=$(realpath "$OPTARG");;
n) NOTARIZE=1;;
j) API_KEY_FILE=$(realpath "$OPTARG");;
\?) usage;;
esac
done
if [ -n "$SIGN" ] && { [ -z "$P12_APP_FILE" ] || [ -z "$P12_INSTALL_FILE" ] || [ -z "$P12_PASSWORD" ]; }; then
usage
fi
if [ -n "$NOTARIZE" ] && [ -z "$API_KEY_FILE" ]; then
usage
fi
VERSION=$(build_tools/git_version_gen.sh --stdout 2>/dev/null)
echo "Version is $VERSION"
PKGDIR=$(mktemp -d)
echo "$PKGDIR"
SRC_DIR=$PWD
OUTPUT_PATH=${FISH_ARTEFACT_PATH:-~/fish_built}
mkdir -p "$PKGDIR/build_x86_64" "$PKGDIR/build_arm64" "$PKGDIR/root" "$PKGDIR/intermediates" "$PKGDIR/dst"
# Build and install for arm64.
# Pass FISH_USE_SYSTEM_PCRE2=OFF because a system PCRE2 on macOS will not be signed by fish,
# and will probably not be built universal, so the package will fail to validate/run on other systems.
# Note CMAKE_OSX_ARCHITECTURES is still relevant for the Mac app.
{ cd "$PKGDIR/build_arm64" \
&& cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \
-DRust_CARGO_TARGET=aarch64-apple-darwin \
-DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \
-DFISH_USE_SYSTEM_PCRE2=OFF \
"$SRC_DIR" \
&& env $ARM64_DEPLOY_TARGET make VERBOSE=1 -j 12 \
&& env DESTDIR="$PKGDIR/root/" $ARM64_DEPLOY_TARGET make install;
}
# Build for x86-64 but do not install; instead we will make some fat binaries inside the root.
# Set RUST_VERSION_X86_64 to the last version of Rust that supports macOS 10.9.
{ cd "$PKGDIR/build_x86_64" \
&& cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \
-DRust_TOOLCHAIN="$RUST_VERSION_X86_64" \
-DRust_CARGO_TARGET=x86_64-apple-darwin \
-DRust_COMPILER="$(rustup +$RUST_VERSION_X86_64 which rustc)" \
-DRust_CARGO="$(rustup +$RUST_VERSION_X86_64 which cargo)" \
-DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \
-DFISH_USE_SYSTEM_PCRE2=OFF "$SRC_DIR" \
&& env $X86_64_DEPLOY_TARGET make VERBOSE=1 -j 12; }
# Fatten them up.
for FILE in "$PKGDIR"/root/usr/local/bin/*; do
X86_FILE="$PKGDIR/build_x86_64/$(basename "$FILE")"
rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE"
chmod 755 "$FILE"
done
if test -n "$SIGN"; then
echo "Signing executables"
ARGS=(
--p12-file "$P12_APP_FILE"
--p12-password "$P12_PASSWORD"
--code-signature-flags runtime
--for-notarization
)
if [ -n "$ENTITLEMENTS_FILE" ]; then
ARGS+=(--entitlements-xml-file "$ENTITLEMENTS_FILE")
fi
for FILE in "$PKGDIR"/root/usr/local/bin/*; do
(set +x; rcodesign sign "${ARGS[@]}" "$FILE")
done
fi
pkgbuild --scripts "$SRC_DIR/build_tools/osx_package_scripts" --root "$PKGDIR/root/" --identifier 'com.ridiculousfish.fish-shell-pkg' --version "$VERSION" "$PKGDIR/intermediates/fish.pkg"
productbuild --package-path "$PKGDIR/intermediates" --distribution "$SRC_DIR/build_tools/osx_distribution.xml" --resources "$SRC_DIR/build_tools/osx_package_resources/" "$OUTPUT_PATH/fish-$VERSION.pkg"
if test -n "$SIGN"; then
echo "Signing installer"
ARGS=(
--p12-file "$P12_INSTALL_FILE"
--p12-password "$P12_PASSWORD"
--code-signature-flags runtime
--for-notarization
)
(set +x; rcodesign sign "${ARGS[@]}" "$OUTPUT_PATH/fish-$VERSION.pkg")
fi
# Make the app
(cd "$PKGDIR/build_arm64" && env $ARM64_DEPLOY_TARGET make -j 12 fish_macapp)
(cd "$PKGDIR/build_x86_64" && env $X86_64_DEPLOY_TARGET make -j 12 fish_macapp)
# Make the app's /usr/local/bin binaries universal. Note fish.app/Contents/MacOS/fish already is, courtesy of CMake.
cd "$PKGDIR/build_arm64"
for FILE in fish.app/Contents/Resources/base/usr/local/bin/*; do
X86_FILE="$PKGDIR/build_x86_64/fish.app/Contents/Resources/base/usr/local/bin/$(basename "$FILE")"
rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE"
# macho-universal-create screws up the permissions.
chmod 755 "$FILE"
done
if test -n "$SIGN"; then
echo "Signing app"
ARGS=(
--p12-file "$P12_APP_FILE"
--p12-password "$P12_PASSWORD"
--code-signature-flags runtime
--for-notarization
)
if [ -n "$ENTITLEMENTS_FILE" ]; then
ARGS+=(--entitlements-xml-file "$ENTITLEMENTS_FILE")
fi
(set +x; rcodesign sign "${ARGS[@]}" "fish.app")
fi
cp -R "fish.app" "$OUTPUT_PATH/fish-$VERSION.app"
cd "$OUTPUT_PATH"
# Maybe notarize.
if test -n "$NOTARIZE"; then
echo "Notarizing"
rcodesign notarize --staple --wait --max-wait-seconds 1800 --api-key-file "$API_KEY_FILE" "$OUTPUT_PATH/fish-$VERSION.pkg"
rcodesign notarize --staple --wait --max-wait-seconds 1800 --api-key-file "$API_KEY_FILE" "$OUTPUT_PATH/fish-$VERSION.app"
fi
# Zip it up.
zip -r "fish-$VERSION.app.zip" "fish-$VERSION.app" && rm -Rf "fish-$VERSION.app"
rm -rf "$PKGDIR"

View File

@@ -1,43 +0,0 @@
#!/usr/bin/env bash
# Script to produce an OS X installer .pkg and .app(.zip)
VERSION=$(git describe --always --dirty 2>/dev/null)
if test -z "$VERSION" ; then
echo "Could not get version from git"
if test -f version; then
VERSION=$(cat version)
fi
fi
echo "Version is $VERSION"
set -x
#Exit on error
set -e
# Respect MAC_CODESIGN_ID, or default for ad-hoc.
# Note the :- means "or default" and the following - is the value.
MAC_CODESIGN_ID=${MAC_CODESIGN_ID:--}
PKGDIR=$(mktemp -d)
SRC_DIR=$PWD
OUTPUT_PATH=${FISH_ARTEFACT_PATH:-~/fish_built}
mkdir -p "$PKGDIR/build" "$PKGDIR/root" "$PKGDIR/intermediates" "$PKGDIR/dst"
# Pass FISH_USE_SYSTEM_PCRE2=OFF because a system PCRE2 on macOS will not be signed by fish,
# and will probably not be built universal, so the package will fail to validate/run on other systems.
{ cd "$PKGDIR/build" && cmake -DMAC_INJECT_GET_TASK_ALLOW=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_GETTEXT=OFF -DFISH_USE_SYSTEM_PCRE2=OFF -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' -DMAC_CODESIGN_ID="${MAC_CODESIGN_ID}" "$SRC_DIR" && make VERBOSE=1 -j 12 && env DESTDIR="$PKGDIR/root/" make install; }
pkgbuild --scripts "$SRC_DIR/build_tools/osx_package_scripts" --root "$PKGDIR/root/" --identifier 'com.ridiculousfish.fish-shell-pkg' --version "$VERSION" "$PKGDIR/intermediates/fish.pkg"
productbuild --package-path "$PKGDIR/intermediates" --distribution "$SRC_DIR/build_tools/osx_distribution.xml" --resources "$SRC_DIR/build_tools/osx_package_resources/" "$OUTPUT_PATH/fish-$VERSION.pkg"
MAC_PRODUCTSIGN_ID=${MAC_PRODUCTSIGN_ID:--}
productsign --sign "${MAC_PRODUCTSIGN_ID}" "$OUTPUT_PATH/fish-$VERSION.pkg" "$OUTPUT_PATH/fish-$VERSION-signed.pkg" && mv "$OUTPUT_PATH/fish-$VERSION-signed.pkg" "$OUTPUT_PATH/fish-$VERSION.pkg"
# Make the app
{ cd "$PKGDIR/build" && make -j 12 signed_fish_macapp && zip -r "$OUTPUT_PATH/fish-$VERSION.app.zip" fish.app; }
rm -rf "$PKGDIR"

1
build_tools/make_pkg.sh Symbolic link
View File

@@ -0,0 +1 @@
make_macos_pkg.sh

View File

@@ -9,30 +9,38 @@
# Exit on error
set -e
# We wil generate a tarball with a prefix "fish-VERSION"
# We will generate a tarball with a prefix "fish-VERSION"
# git can do that automatically for us via git-archive
# but to get the documentation in, we need to make a symlink called "fish-VERSION"
# and tar from that, so that the documentation gets the right prefix
# Use Ninja if available, as it automatically parallelises
BUILD_TOOL="make"
BUILD_GENERATOR="Unix Makefiles"
if command -v ninja >/dev/null; then
BUILD_TOOL="ninja"
BUILD_GENERATOR="Ninja"
fi
# We need GNU tar as that supports the --mtime and --transform options
TAR=notfound
for try in tar gtar gnutar; do
if $try -Pcf /dev/null --mtime now /dev/null >/dev/null 2>&1; then
TAR=$try
break
fi
if $try -Pcf /dev/null --mtime now /dev/null >/dev/null 2>&1; then
TAR=$try
break
fi
done
if [ "$TAR" = "notfound" ]; then
echo 'No suitable tar (supporting --mtime) found as tar/gtar/gnutar in PATH'
exit 1
echo 'No suitable tar (supporting --mtime) found as tar/gtar/gnutar in PATH'
exit 1
fi
# Get the current directory, which we'll use for symlinks
wd="$PWD"
# Get the version from git-describe
VERSION=$(git describe --dirty 2>/dev/null)
# Get the version
VERSION=$(build_tools/git_version_gen.sh --stdout 2>/dev/null)
# The name of the prefix, which is the directory that you get when you untar
prefix="fish-$VERSION"
@@ -51,11 +59,11 @@ git archive --format=tar --prefix="$prefix"/ HEAD > "$path"
PREFIX_TMPDIR=$(mktemp -d)
cd "$PREFIX_TMPDIR"
echo "$VERSION" > version
cmake "$wd"
make doc
cmake -G "$BUILD_GENERATOR" -DCMAKE_BUILD_TYPE=Debug "$wd"
$BUILD_TOOL doc
TAR_APPEND="$TAR --append --file=$path --mtime=now --owner=0 --group=0 \
--mode=g+w,a+rX --transform s/^/$prefix\//"
--mode=g+w,a+rX --transform s/^/$prefix\//"
$TAR_APPEND --no-recursion user_doc
$TAR_APPEND user_doc/html user_doc/man
$TAR_APPEND version
@@ -66,6 +74,6 @@ rm -r "$PREFIX_TMPDIR"
# xz it
xz "$path"
# Output what we did, and the sha1 hash
# Output what we did, and the sha256 hash
echo "Tarball written to $path".xz
openssl dgst -sha256 "$path".xz

View File

@@ -0,0 +1,55 @@
#!/bin/sh
# Script to generate a tarball of vendored (downloaded) Rust dependencies
# and the cargo configuration to ensure they are used
# This tarball should be unpacked into a fish source directory
# Outputs to $FISH_ARTEFACT_PATH or ~/fish_built by default
# Exit on error
set -e
# We need GNU tar as that supports the --mtime and --transform options
TAR=notfound
for try in tar gtar gnutar; do
if $try -Pcf /dev/null --mtime now /dev/null >/dev/null 2>&1; then
TAR=$try
break
fi
done
if [ "$TAR" = "notfound" ]; then
echo 'No suitable tar (supporting --mtime) found as tar/gtar/gnutar in PATH'
exit 1
fi
# Get the current directory, which we'll use for telling Cargo where to find the sources
wd="$PWD"
# Get the version from git-describe
VERSION=$(build_tools/git_version_gen.sh --stdout 2>/dev/null)
# The name of the prefix, which is the directory that you get when you untar
prefix="fish-$VERSION"
# The path where we will output the tar file
# Defaults to ~/fish_built
path=${FISH_ARTEFACT_PATH:-~/fish_built}/$prefix-vendor.tar
# Clean up stuff we've written before
rm -f "$path" "$path".xz
# Work in a temporary directory to avoid clobbering the source directory
PREFIX_TMPDIR=$(mktemp -d)
cd "$PREFIX_TMPDIR"
mkdir .cargo
cargo vendor --manifest-path "$wd/Cargo.toml" > .cargo/config.toml
tar cfvJ "$path".xz vendor .cargo
cd -
rm -r "$PREFIX_TMPDIR"
# Output what we did, and the sha256 hash
echo "Tarball written to $path".xz
openssl dgst -sha256 "$path".xz

View File

@@ -8,7 +8,6 @@
code, tt {
font-family: ui-monospace, Menlo, monospace;
}
</style>
</head>
<body>

View File

@@ -4,12 +4,12 @@
if test $# -eq 0
then
echo usage: $0 shellname [shellname ...]
echo "usage: $0 shellname [shellname ...]"
exit 1
fi
scriptname=`basename "$0"`
if [[ $UID -ne 0 ]]; then
scriptname=$(basename "$0")
if [ "$(id -u)" -ne 0 ]; then
echo "${scriptname} must be run as root"
exit 1
fi
@@ -20,6 +20,7 @@ tmpfile=${file}.tmp
set -o noclobber
# shellcheck disable=SC2064
trap "rm -f $tmpfile" EXIT
if ! cat $file > $tmpfile
@@ -32,15 +33,13 @@ EOF
fi
# Append a newline if it doesn't exist
if [ "$(tail -c1 "$tmpfile"; echo x)" != $'\nx' ]; then
echo "" >> "$tmpfile"
fi
[ -z "$(tail -c1 "$tmpfile")" ] || echo "" >> "$tmpfile"
for i
do
if ! grep -q "^${i}$" "$tmpfile"
then
echo $i >> "$tmpfile"
echo "$i" >> "$tmpfile"
fi
done

View File

@@ -1,3 +1,3 @@
#!/bin/sh -x
./add-shell ${DSTVOLUME}usr/local/bin/fish
./add-shell "${DSTVOLUME}"usr/local/bin/fish

View File

@@ -1,7 +1,7 @@
#!/bin/sh -x
echo "Removing any previous installation"
pkgutil --pkg-info ${INSTALL_PKG_SESSION_ID} && pkgutil --only-files --files ${INSTALL_PKG_SESSION_ID} | while read installed
do rm -v ${DSTVOLUME}${installed}
pkgutil --pkg-info "${INSTALL_PKG_SESSION_ID}" && pkgutil --only-files --files "${INSTALL_PKG_SESSION_ID}" | while read -r installed
do rm -v "${DSTVOLUME}${installed}"
done
echo "... removed"

104
build_tools/release-notes.sh Executable file
View File

@@ -0,0 +1,104 @@
#!/bin/sh
set -e
workspace_root=$(dirname "$0")/..
relnotes_tmp=$(mktemp -d)
mkdir -p "$relnotes_tmp/fake-workspace" "$relnotes_tmp/out"
(
cd "$workspace_root"
cp -r doc_src CONTRIBUTING.rst README.rst "$relnotes_tmp/fake-workspace"
)
version=$(sed 's,^fish \(\S*\) .*,\1,; 1q' "$workspace_root/CHANGELOG.rst")
previous_version=$(
cd "$workspace_root"
awk <CHANGELOG.rst '
( /^fish \S*\.\S*\.\S* \(released .*\)$/ &&
NR > 1 &&
# Skip tags that have not been created yet..
system("git rev-parse --verify >/dev/null --quiet refs/tags/"$2) == 0 \
) {
print $2; ok = 1; exit
}
END { exit !ok }
'
)
minor_version=${version%.*}
previous_minor_version=${previous_version%.*}
{
sed -n 1,2p <"$workspace_root/CHANGELOG.rst"
ListCommitters() {
comm "$@" "$relnotes_tmp/committers-then" "$relnotes_tmp/committers-now"
}
(
cd "$workspace_root"
git log "$previous_version" --format="%aN" | sort -u >"$relnotes_tmp/committers-then"
git log "$previous_version".. --format="%aN" | sort -u >"$relnotes_tmp/committers-now"
ListCommitters -13 >"$relnotes_tmp/committers-new"
ListCommitters -12 >"$relnotes_tmp/committers-returning"
)
if [ "$minor_version" != "$previous_minor_version" ]; then
(
cd "$workspace_root"
num_commits=$(git log --no-merges --format=%H "$previous_version".. | wc -l)
num_authors=$(wc -l <"$relnotes_tmp/committers-now")
num_new_authors=$(wc -l <"$relnotes_tmp/committers-new")
printf %s \
"This release comprises $num_commits commits since $previous_version," \
" contributed by $num_authors authors, $num_new_authors of which are new committers."
echo
echo
)
fi
printf '%s\n' "$(awk <"$workspace_root/CHANGELOG.rst" '
NR <= 2 || /^\.\. ignore / { next }
/^===/ { exit }
{ print }
' | sed '$d')" |
sed -e '$s/^----*$//' # Remove spurious transitions at the end of the document.
if [ "$minor_version" != "$previous_minor_version" ]; then {
JoinEscaped() {
sed 's/\S/\\&/g' |
awk '
NR != 1 { printf ",\n" }
{ printf "%s", $0 }
END { printf "\n" }
'
}
echo ""
echo "---"
echo ""
echo "Thanks to everyone who contributed through issue discussions, code reviews, or code changes."
echo
printf "Welcome our new committers: "
JoinEscaped <"$relnotes_tmp/committers-new"
echo
printf "Welcome back our returning committers: "
JoinEscaped <"$relnotes_tmp/committers-returning"
} fi
echo
echo "---"
echo
echo "*Download links: To download the source code for fish, we suggest the file named \"fish-$version.tar.xz\". The file downloaded from \"Source code (tar.gz)\" will not build correctly.*"
echo
echo "*The files called fish-$version-linux-\*.tar.xz are experimental packages containing a single standalone ``fish`` binary for any Linux with the given CPU architecture.*"
} >"$relnotes_tmp/fake-workspace"/CHANGELOG.rst
sphinx-build >&2 -j auto \
-W -E -b markdown -c "$workspace_root/doc_src" \
-d "$relnotes_tmp/doctree" "$relnotes_tmp/fake-workspace/doc_src" "$relnotes_tmp/out" \
-D markdown_http_base="https://fishshell.com/docs/$minor_version" \
-D markdown_uri_doc_suffix=".html" \
-D markdown_github_flavored=1 \
"$@"
# Skip changelog header
sed -n 1p "$relnotes_tmp/out/relnotes.md" | grep -Fxq "# Release notes"
sed -n 2p "$relnotes_tmp/out/relnotes.md" | grep -Fxq ''
sed 1,2d "$relnotes_tmp/out/relnotes.md"
rm -r "$relnotes_tmp"

253
build_tools/release.sh Executable file
View File

@@ -0,0 +1,253 @@
#!/bin/sh
{
set -ex
version=$1
repository_owner=fish-shell
remote=origin
if [ -n "$2" ]; then
set -u
repository_owner=$2
remote=$3
set +u
[ $# -eq 3 ]
fi
[ -n "$version" ]
for tool in \
bundle \
gh \
jq \
ruby \
timeout \
; do
if ! command -v "$tool" >/dev/null; then
echo >&2 "$0: missing command: $1"
exit 1
fi
done
repo_root="$(dirname "$0")/.."
fish_site=$repo_root/../fish-site
fish_site_repo=git@github.com:$repository_owner/fish-site
for path in . "$fish_site"
do
if ! git -C "$path" diff HEAD --quiet ||
git ls-files --others --exclude-standard | grep .; then
echo >&2 "$0: index and worktree must be clean"
exit 1
fi
done
(
cd "$fish_site"
[ "$(git rev-parse HEAD)" = \
"$(git ls-remote "$fish_site_repo" refs/heads/master |
awk '{print $1}')" ]
)
if git tag | grep -qxF "$version"; then
echo >&2 "$0: tag $version already exists"
exit 1
fi
integration_branch=$(
git for-each-ref --points-at=HEAD 'refs/heads/Integration_*' \
--format='%(refname:strip=2)'
)
[ -n "$integration_branch" ] ||
git merge-base --is-ancestor $remote/master HEAD
sed -n 1p CHANGELOG.rst | grep -q '^fish .*(released .*)$'
sed -n 2p CHANGELOG.rst | grep -q '^===*$'
changelog_title="fish $version (released $(date +'%B %d, %Y'))"
sed -i \
-e "1c$changelog_title" \
-e "2c$(printf %s "$changelog_title" | sed s/./=/g)" \
CHANGELOG.rst
CommitVersion() {
sed -i "s/^version = \".*\"/version = \"$1\"/g" Cargo.toml
cargo fetch --offline
git add CHANGELOG.rst Cargo.toml Cargo.lock
git commit -m "$2
Created by ./build_tools/release.sh $version"
}
CommitVersion "$version" "Release $version"
# N.B. this is not GPG-signed.
git tag --annotate --message="Release $version" $version
git push $remote $version
TIMEOUT=
gh() {
command ${TIMEOUT:+timeout $TIMEOUT} \
gh --repo "$repository_owner/fish-shell" "$@"
}
gh workflow run release.yml --ref="$version" \
--raw-field="version=$version"
run_id=
while [ -z "$run_id" ] && sleep 5
do
run_id=$(gh run list \
--json=databaseId --jq=.[].databaseId \
--workflow=release.yml --limit=1 \
--commit="$(git rev-parse "$version^{commit}")")
done
# Update fishshell.com
tag_oid=$(git rev-parse "$version")
tmpdir=$(mktemp -d)
# TODO This works on draft releases only if "gh" is configured to
# have write access to the fish-shell repository. Unless we are fine
# publishing the release at this point, we should at least fail if
# "gh" doesn't have write access.
while ! \
gh release download "$version" --dir="$tmpdir" \
--pattern="fish-$version.tar.xz"
do
TIMEOUT=30 gh run watch "$run_id" ||:
sleep 5
done
actual_tag_oid=$(git ls-remote "$remote" |
awk '$2 == "refs/tags/'"$version"'" { print $1 }')
[ "$tag_oid" = "$actual_tag_oid" ]
( cd "$tmpdir" && tar xf fish-$version.tar.xz )
CopyDocs() {
rm -rf "$fish_site/site/docs/$1"
cp -r "$tmpdir/fish-$version/user_doc/html" "$fish_site/site/docs/$1"
git -C $fish_site add "site/docs/$1"
}
minor_version=${version%.*}
CopyDocs "$minor_version"
latest_release=$(
releases=$(git tag | grep '^[0-9]*\.[0-9]*\.[0-9]*.*' |
sed $(: "De-prioritize release candidates (1.2.3-rc0)") \
's/-/~/g' | LC_ALL=C sort --version-sort)
printf %s\\n "$releases" | tail -1
)
if [ "$version" = "$latest_release" ]; then
CopyDocs current
fi
rm -rf "$tmpdir"
(
cd "$fish_site"
make
git add -u
git add docs
if git ls-files --others --exclude-standard | grep .; then
exit 1
fi
git commit --message="$(printf %s "\
| Release $version (docs)
|
| Created by ../fish-shell/build_tools/release.sh
" | sed 's,^\s*| \?,,')"
)
gh_api_repo() {
path=$1
shift
command gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/$repository_owner/fish-shell/$path" \
"$@"
}
# Approve macos-codesign
# TODO what if current user can't approve?
gh_pending_deployments() {
gh_api_repo "actions/runs/$run_id/pending_deployments" "$@"
}
while {
environment_id=$(gh_pending_deployments | jq .[].environment.id)
[ -z "$environment_id" ]
}
do
sleep 5
done
echo '
{
"environment_ids": ['"$environment_id"'],
"state": "approved",
"comment": "Approved via ./build_tools/release.sh"
}
' |
gh_pending_deployments --method POST --input=-
# Await completion.
gh run watch "$run_id"
while {
! draft=$(gh release view "$version" --json=isDraft --jq=.isDraft) \
|| [ "$draft" = true ]
}
do
sleep 20
done
(
cd "$fish_site"
make new-release
git add -u
git add docs
if git ls-files --others --exclude-standard | grep .; then
exit 1
fi
git commit --message="$(printf %s "\
| Release $version (release list update)
|
| Created by ../fish-shell/build_tools/release.sh
" | sed 's,^\s*| \?,,')"
# This takes care to support remote names that are different from
# fish-shell remote name. Also, support detached HEAD state.
git push "$fish_site_repo" HEAD:master
)
if [ -n "$integration_branch" ]; then {
git push $remote "$version^{commit}":refs/heads/$integration_branch
} else {
changelog=$(cat - CHANGELOG.rst <<EOF
fish ?.?.? (released ???)
=========================
EOF
)
printf %s\\n "$changelog" >CHANGELOG.rst
CommitVersion ${version}-snapshot "start new cycle"
git push $remote HEAD:master
} fi
milestone_number=$(
gh_api_repo milestones?state=open |
jq '.[] | select(.title == "fish '"$version"'") | .number'
)
gh_api_repo milestones/$milestone_number --method PATCH \
--raw-field state=closed
next_patch_version=$(
echo "$version" | awk -F. '
NF == 3 && $3 ~ /[0-9]+/ {
printf "%s.%s.%s", $1, $2, $3+1
}
'
)
if [ -n "$next_patch_version" ]; then
gh_api_repo milestones --method POST \
--raw-field title="fish $next_patch_version"
fi
exit
}

View File

@@ -1,119 +1,124 @@
#!/usr/bin/env fish
#
# This runs C++ files and fish scripts (*.fish) through their respective code
# formatting programs.
# This runs Python files, fish scripts (*.fish), and Rust files
# through their respective code formatting programs.
#
set -l git_clang_format no
set -l c_files
# `--all`: Format all eligible files instead of the ones specified as arguments.
# `--check`: Instead of reformatting, fail if a file is not formatted correctly.
# `--force`: Proceed without asking if uncommitted changes are detected.
# Only relevant if `--all` is specified but `--check` is not specified.
set -l fish_files
set -l python_files
set -l rust_files
set -l all no
if test "$argv[1]" = --all
argparse all check force -- $argv
or exit $status
if set -l -q _flag_all
set all yes
set -e argv[1]
if set -q argv[1]
echo "Unexpected arguments: '$argv'"
exit 1
end
end
if set -q argv[1]
echo "Unexpected arguments: '$argv'"
exit 1
end
set -l workspace_root (status dirname)/..
if test $all = yes
set -l files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
if set -q files[1]
echo
echo 'You have uncommitted changes. Are you sure you want to restyle?'
read -P 'y/N? ' -n1 -l ans
if not string match -qi "y" -- $ans
exit 1
if not set -l -q _flag_force; and not set -l -q _flag_check
# Potential for false positives: Not all fish files are formatted, see the `fish_files`
# definition below.
set -l relevant_uncommitted_changes (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//' | grep -E '.*\.(fish|py|rs)$')
if set -q relevant_uncommitted_changes[1]
for changed_file in $relevant_uncommitted_changes
echo $changed_file
end
echo
echo 'You have uncommitted changes (listed above). Are you sure you want to restyle?'
read -P 'y/N? ' -n1 -l ans
if not string match -qi y -- $ans
exit 1
end
end
end
set c_files src/*.h src/*.cpp src/*.c
set fish_files share/**.fish
set python_files {doc_src,share,tests}/**.py
set fish_files $workspace_root/{benchmarks,build_tools,etc,share}/**.fish
set python_files $workspace_root
else
# We haven't been asked to reformat all the source. If there are uncommitted changes reformat
# those using `git clang-format`. Else reformat the files in the most recent commit.
# Select (cached files) (modified but not cached, and untracked files)
set -l files (git diff-index --cached HEAD --name-only) (git ls-files --exclude-standard --others --modified)
if set -q files[1]
set git_clang_format yes
else
# No pending changes so lint the files in the most recent commit.
set files (git diff-tree --no-commit-id --name-only -r HEAD)
end
# Extract just the C/C++ files that exist.
set c_files
for file in (string match -r '^.*\.(?:c|cpp|h)$' -- $files)
test -f $file; and set c_files $c_files $file
end
# Extract just the fish files.
# Format the files specified as arguments.
set -l files $argv
set fish_files (string match -r '^.*\.fish$' -- $files)
set python_files (string match -r '^.*\.py$' -- $files)
set rust_files (string match -r '^.*\.rs$' -- $files)
end
set -l red (set_color red)
set -l green (set_color green)
set -l blue (set_color blue)
set -l yellow (set_color yellow)
set -l normal (set_color normal)
# Run the C++ reformatter if we have any C++ files.
if set -q c_files[1]
if test $git_clang_format = yes
if type -q git-clang-format
echo === Running "$red"git-clang-format"$normal"
git add $c_files
git-clang-format
else
echo
echo 'WARNING: Cannot find git-clang-format command'
echo
end
else if type -q clang-format
echo === Running "$red"clang-format"$normal"
for file in $c_files
if clang-format --dry-run -Werror $file
# file was clean, remove it from the list
set -e c_files[(contains -i $file $c_files)]
end
end
if set -q c_files[1]
printf "Reformat those %d files?\n" (count $c_files)
read -P 'y/N? ' -n1 -l ans
if string match -qi "y" -- $ans
clang-format -i --verbose $c_files
else if string match -qi "n" -- $ans
echo Skipping
else # like they ctrl-C'd or something.
exit 1
end
end
else
echo
echo 'WARNING: Cannot find clang-format command'
echo
end
end
# Run the fish reformatter if we have any fish files.
if set -q fish_files[1]
if not type -q fish_indent
make fish_indent
set PATH . $PATH
echo
echo $yellow'Could not find `fish_indent` in `$PATH`.'$normal
exit 127
end
echo === Running "$green"fish_indent"$normal"
fish_indent -w -- $fish_files
if set -l -q _flag_check
if not fish_indent --check -- $fish_files
echo $red"Fish files are not formatted correctly."$normal
exit 1
end
else
fish_indent -w -- $fish_files
end
end
if set -q python_files[1]
if not type -q black
echo
echo Please install "`black`" to style python
if not type -q ruff
echo
echo $yellow'Please install `ruff` to style python'$normal
exit 127
end
echo === Running "$green"ruff format"$normal"
if set -l -q _flag_check
if not ruff format --check $python_files
echo $red"Python files are not formatted correctly."$normal
exit 1
end
else
echo === Running "$blue"black"$normal"
black $python_files
ruff format $python_files
end
end
if not cargo fmt --version >/dev/null
echo
echo $yellow'Please install "rustfmt" to style Rust, e.g. via:'
echo "rustup component add rustfmt"$normal
exit 127
end
echo === Running "$green"rustfmt"$normal"
if set -l -q _flag_check
if set -l -q _flag_all
if not cargo fmt --all --check
echo $red"Rust files are not formatted correctly."$normal
exit 1
end
else
if set -q rust_files[1]
if not rustfmt --check --files-with-diff $rust_files
echo $red"Rust files are not formatted correctly."
exit 1
end
end
end
else
if set -l -q _flag_all
cargo fmt --all
else
if set -q rust_files[1]
rustfmt $rust_files
end
end
end

View File

@@ -0,0 +1,157 @@
#!/usr/bin/env fish
# Updates the files used for gettext translations.
# By default, the whole xgettext + msgmerge pipeline runs,
# which extracts the messages from the source files into $template_file,
# and updates the PO files for each language from that.
#
# Use cases:
# For developers:
# - Run with no args to update all PO files after making changes to Rust/fish sources.
# For translators:
# - Specify the language you want to work on as an argument, which must be a file in the po/
# directory. You can specify a language which does not have translations yet by specifying the
# name of a file which does not yet exist. Make sure to follow the naming convention.
# For testing:
# - Specify `--dry-run` to see if any updates to the PO files would by applied by this script.
# If this flag is specified, the script will exit with an error if there are outstanding
# changes, and will display the diff. Do not specify other flags if `--dry-run` is specified.
#
# Specify `--use-existing-template=FILE` to prevent running cargo for extracting an up-to-date
# version of the localized strings. This flag is intended for testing setups which make it
# inconvenient to run cargo here, but run it in an earlier step to ensure up-to-date values.
# This argument is passed on to the `fish_xgettext.fish` script and has no other uses.
# `FILE` must be the path to a gettext template file generated from our compilation process.
# It can be obtained by running:
# set -l FILE (mktemp)
# FISH_GETTEXT_EXTRACTION_FILE=$FILE cargo check --features=gettext-extract
# The sort utility is locale-sensitive.
# Ensure that sorting output is consistent by setting LC_ALL here.
set -gx LC_ALL C.UTF-8
set -l build_tools (status dirname)
set -l po_dir $build_tools/../po
set -l extract
set -l po
argparse dry-run use-existing-template= -- $argv
or exit $status
if test -z $argv[1]
# Update everything if not specified otherwise.
set -g po_files $po_dir/*.po
else
set -l po_dir_id (stat --format='%d:%i' -- $po_dir)
for arg in $argv
set -l arg_dir_id (stat --format='%d:%i' -- (dirname $arg) 2>/dev/null)
if test $po_dir_id != "$arg_dir_id"
echo "Argument $arg is not a file in the directory $(realpath $po_dir)."
echo "Non-option arguments must specify paths to files in this directory."
echo ""
echo "If you want to add a new language to the translations not the following:"
echo "The filename must identify a language, with a two letter ISO 639-1 language code of the target language (e.g. 'pt' for Portuguese), and use the file extension '.po'."
echo "Optionally, you can specify a regional variant (e.g. 'pt_BR')."
echo "So valid filenames are of the shape 'll.po' or 'll_CC.po'."
exit 1
end
if not basename $arg | grep -qE '^[a-z]{2,3}(_[A-Z]{2})?\.po$'
echo "Filename does not match the expected format ('ll.po' or 'll_CC.po')."
exit 1
end
end
set -g po_files $argv
end
set -g template_file (mktemp)
# Protect from externally set $tmpdir leaking into this script.
set -g tmpdir
function cleanup_exit
set -l exit_status $status
rm $template_file
if set -g --query tmpdir[1]
rm -r $tmpdir
end
exit $exit_status
end
if set -l --query extract
set -l xgettext_args
if set -l --query _flag_use_existing_template
set xgettext_args --use-existing-template=$_flag_use_existing_template
end
$build_tools/fish_xgettext.fish $xgettext_args >$template_file
or cleanup_exit
end
if set -l --query _flag_dry_run
# On a dry run, we do not modify po/ but write to a temporary directory instead and check if
# there is a difference between po/ and the tmpdir after re-generating the PO files.
set -g tmpdir (mktemp -d)
# Ensure tmpdir has the same initial state as the po dir.
cp -r $po_dir/* $tmpdir
end
# This is used to identify lines which should be set here via $header_lines.
# Make sure that this prefix does not appear elsewhere in the file and only contains characters
# without special meaning in a sed pattern.
set -g header_prefix "# fish-note-sections: "
function print_header
set -l header_lines \
"Translations are divided into sections, each starting with a fish-section-* pseudo-message." \
"The first few sections are more important." \
"Ignore the tier3 sections unless you have a lot of time."
for line in $header_lines
printf '%s%s\n' $header_prefix $line
end
end
function merge_po_files --argument-names template_file po_file
msgmerge --no-wrap --update --no-fuzzy-matching --backup=none --quiet \
$po_file $template_file
or cleanup_exit
set -l new_po_file (mktemp) # TODO Remove on failure.
# Remove obsolete messages instead of keeping them as #~ entries.
and msgattrib --no-wrap --no-obsolete -o $new_po_file $po_file
or cleanup_exit
begin
print_header
# Paste PO file without old header lines.
sed '/^'$header_prefix'/d' $new_po_file
end >$po_file
rm $new_po_file
end
for po_file in $po_files
if set --query tmpdir[1]
set po_file $tmpdir/(basename $po_file)
end
if set -l --query po
if test -e $po_file
merge_po_files $template_file $po_file
else
begin
print_header
cat $template_file
end >$po_file
end
end
end
if set -g --query tmpdir[1]
diff -ur $po_dir $tmpdir
or begin
echo ERROR: translations in ./po/ are stale. Try running build_tools/update_translations.fish
cleanup_exit
end
end
cleanup_exit

View File

@@ -1,6 +1,7 @@
# Support for benchmarking fish.
add_custom_target(benchmark
COMMAND ${CMAKE_SOURCE_DIR}/benchmarks/driver.sh $<TARGET_FILE:fish>
COMMAND ${CMAKE_SOURCE_DIR}/benchmarks/driver.sh ${CMAKE_BINARY_DIR}/fish
DEPENDS fish
USES_TERMINAL
)

View File

@@ -1,123 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See full license information in
# doc_src/license.hdr or https://cmake.org/licensing for details.
#.rst:
# CheckIncludeFiles
# -----------------
#
# Provides a macro to check if a list of one or more header files can
# be included together in ``C``.
#
# .. command:: CHECK_INCLUDE_FILES
#
# ::
#
# CHECK_INCLUDE_FILES("<includes>" <variable> [LANGUAGE <language>])
#
# Check if the given ``<includes>`` list may be included together
# in a ``C`` source file and store the result in an internal cache
# entry named ``<variable>``. Specify the ``<includes>`` argument
# as a :ref:`;-list <CMake Language Lists>` of header file names.
#
# If LANGUAGE is set, the specified compiler will be used to perform the
# check. Acceptable values are C and CXX.
#
# The following variables may be set before calling this macro to modify
# the way the check is run:
#
# ``CMAKE_REQUIRED_FLAGS``
# string of compile command line flags
# ``CMAKE_REQUIRED_DEFINITIONS``
# list of macros to define (-DFOO=bar)
# ``CMAKE_REQUIRED_INCLUDES``
# list of include directories
# ``CMAKE_REQUIRED_QUIET``
# execute quietly without messages
#
# See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX`
# to check for a single header file in ``C`` or ``CXX`` languages.
macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
if(NOT DEFINED "${VARIABLE}")
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
if("x${ARGN}" STREQUAL "x")
if(CMAKE_C_COMPILER_LOADED)
set(_lang C)
elseif(CMAKE_CXX_COMPILER_LOADED)
set(_lang CXX)
else()
message(FATAL_ERROR "CHECK_INCLUDE_FILES needs either C or CXX language enabled")
endif()
elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")
set(_lang "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n")
endif()
if(_lang STREQUAL "C")
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.c)
elseif(_lang STREQUAL "CXX")
set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.cpp)
else()
message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n")
endif()
if(CMAKE_REQUIRED_INCLUDES)
set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
else()
set(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
endif()
set(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
set(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
foreach(FILE ${INCLUDE})
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
"#include <${FILE}>\n")
endforeach()
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
"\n\nint main(void){return 0;}\n")
configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
"${src}" @ONLY)
set(_INCLUDE ${INCLUDE}) # remove empty elements
if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
list(LENGTH _INCLUDE _INCLUDE_LEN)
set(_description "${_INCLUDE_LEN} include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}")
elseif("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$")
set(_description "include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}")
else()
set(_description "include file ${_INCLUDE}")
endif()
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${_description}")
endif()
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${src}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
"${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT)
if(${VARIABLE})
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${_description} - found")
endif()
set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if files ${INCLUDE} "
"exist passed with the following output:\n"
"${OUTPUT}\n\n")
else()
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${_description} - not found")
endif()
set(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if files ${INCLUDE} "
"exist failed with the following output:\n"
"${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
endif()
endif()
endmacro()

View File

@@ -1,308 +0,0 @@
# The following defines affect the environment configuration tests are run in:
# CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_LIBRARIES,
# and CMAKE_REQUIRED_INCLUDES
# `wcstod_l` is a GNU-extension, sometimes hidden behind GNU-related defines.
# This is the case for at least Cygwin and Newlib.
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE=1)
include(CheckCXXCompilerFlag)
include(CMakePushCheckState)
if(APPLE)
check_cxx_compiler_flag("-Werror=unguarded-availability" REQUIRES_UNGUARDED_AVAILABILITY)
if(REQUIRES_UNGUARDED_AVAILABILITY)
list(APPEND CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-Werror=unguarded-availability")
endif()
endif()
# An unrecognized flag is usually a warning and not an error, which CMake apparently does
# not pick up on. Combine it with -Werror to determine if it's actually supported.
# This is not bulletproof; old versions of GCC only emit a warning about unrecognized warning
# options when there are other warnings to emit :rolleyes:
# See https://github.com/fish-shell/fish-shell/commit/fe2da0a9#commitcomment-47431659
# GCC supports -Wno-redundant-move from GCC9 onwards
check_cxx_compiler_flag("-Werror=no-redundant-move" HAS_NO_REDUNDANT_MOVE)
if (HAS_NO_REDUNDANT_MOVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move")
endif()
# Clang once supported -Wno-redundant-move but replaced it with a Wredundant-move option instead
# (and it is functionally different from its older version of GCC's Wno-redundant-move).
check_cxx_compiler_flag("-Werror=redundant-move" HAS_REDUNDANT_MOVE)
if (HAS_REDUNDANT_MOVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-move")
endif()
# Defeat bogus warnings about missing field initializers for `var{}` initialization.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_FLAGS "-W")
check_cxx_source_compiles("
struct sr_t { int x; };
int main(void) {
sr_t sr{};
return sr.x;
}"
EMPTY_VALUE_INIT_ACCEPTED
FAIL_REGEX "-Wmissing-field-initializers"
)
if (NOT EMPTY_VALUE_INIT_ACCEPTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
endif()
cmake_pop_check_state()
endif()
# Disable static destructors if we can.
check_cxx_compiler_flag("-fno-c++-static-destructors" DISABLE_STATIC_DESTRUCTORS)
if (DISABLE_STATIC_DESTRUCTORS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-c++-static-destructors")
endif()
# Try using CMake's own logic to locate curses/ncurses
find_package(Curses)
if(NOT ${CURSES_FOUND})
# CMake has trouble finding platform-specific system libraries
# installed to multiarch paths (e.g. /usr/lib/x86_64-linux-gnu)
# if not symlinked or passed in as a manual define.
message("Falling back to pkg-config for (n)curses detection")
include(FindPkgConfig)
pkg_search_module(CURSES REQUIRED ncurses curses)
set(CURSES_CURSES_LIBRARY ${CURSES_LIBRARIES})
set(CURSES_LIBRARY ${CURSES_LIBRARIES})
endif()
# Set up extra include directories for CheckIncludeFile
list(APPEND CMAKE_REQUIRED_INCLUDES ${CURSES_INCLUDE_DIRS})
# Fix undefined reference to tparm on RHEL 6 and potentially others
# If curses is found via CMake, it also links against tinfo if it exists. But if we use our
# fallback pkg-config logic above, we need to do this manually.
find_library(CURSES_TINFO tinfo)
if (CURSES_TINFO)
set(CURSES_LIBRARY ${CURSES_LIBRARY} ${CURSES_TINFO})
else()
# on NetBSD, libtinfo has a longer name (libterminfo)
find_library(CURSES_TINFO terminfo)
if (CURSES_TINFO)
set(CURSES_LIBRARY ${CURSES_LIBRARY} ${CURSES_TINFO})
endif()
endif()
# Get threads.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Detect WSL. Does not match against native Windows/WIN32.
if (CMAKE_HOST_SYSTEM_VERSION MATCHES ".*-Microsoft")
set(WSL 1)
endif()
# Set up the config.h file.
set(PACKAGE_NAME "fish")
set(PACKAGE_TARNAME "fish")
include(CheckCXXSymbolExists)
include(CheckIncludeFileCXX)
include(CheckIncludeFiles)
include(CheckStructHasMember)
include(CheckCXXSourceCompiles)
include(CheckTypeSize)
check_cxx_symbol_exists(backtrace_symbols execinfo.h HAVE_BACKTRACE_SYMBOLS)
# workaround for lousy mtime precision on a Linux kernel
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
check_cxx_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
if ((HAVE_CLOCK_GETTIME) AND (HAVE_FUTIMENS))
set(UVAR_FILE_SET_MTIME_HACK 1)
endif()
endif()
check_cxx_symbol_exists(ctermid_r stdio.h HAVE_CTERMID_R)
check_struct_has_member("struct dirent" d_type dirent.h HAVE_STRUCT_DIRENT_D_TYPE LANGUAGE CXX)
check_cxx_symbol_exists(dirfd "sys/types.h;dirent.h" HAVE_DIRFD)
check_include_file_cxx(execinfo.h HAVE_EXECINFO_H)
check_cxx_symbol_exists(flock sys/file.h HAVE_FLOCK)
check_cxx_symbol_exists(getpwent pwd.h HAVE_GETPWENT)
check_cxx_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
check_cxx_symbol_exists(gettext libintl.h HAVE_GETTEXT)
check_cxx_symbol_exists(killpg "sys/types.h;signal.h" HAVE_KILLPG)
# mkostemp is in stdlib in glibc and FreeBSD, but unistd on macOS
check_cxx_symbol_exists(mkostemp "stdlib.h;unistd.h" HAVE_MKOSTEMP)
set(HAVE_CURSES_H ${CURSES_HAVE_CURSES_H})
set(HAVE_NCURSES_CURSES_H ${CURSES_HAVE_NCURSES_CURSES_H})
set(HAVE_NCURSES_H ${CURSES_HAVE_NCURSES_H})
if(HAVE_CURSES_H)
check_include_files("curses.h;term.h" HAVE_TERM_H)
endif()
if(NOT HAVE_TERM_H)
check_include_file_cxx("ncurses/term.h" HAVE_NCURSES_TERM_H)
endif()
check_include_file_cxx(siginfo.h HAVE_SIGINFO_H)
check_include_file_cxx(spawn.h HAVE_SPAWN_H)
check_struct_has_member("struct stat" st_ctime_nsec "sys/stat.h" HAVE_STRUCT_STAT_ST_CTIME_NSEC
LANGUAGE CXX)
check_struct_has_member("struct stat" st_mtimespec.tv_nsec "sys/stat.h"
HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC LANGUAGE CXX)
check_struct_has_member("struct stat" st_mtim.tv_nsec "sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
LANGUAGE CXX)
check_include_file_cxx(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_file_cxx(sys/select.h HAVE_SYS_SELECT_H)
# glibc 2.30 deprecated <sys/sysctl.h> because that's what glibc does.
# Checking for that here rather than hardcoding a check on the glibc
# version in the C++ sources at point of use makes more sense.
SET(OLD_CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
check_include_files("sys/types.h;sys/sysctl.h" HAVE_SYS_SYSCTL_H)
SET(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}")
check_cxx_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD)
check_cxx_symbol_exists(pipe2 unistd.h HAVE_PIPE2)
check_cxx_symbol_exists(wcscasecmp wchar.h HAVE_WCSCASECMP)
check_cxx_symbol_exists(wcsncasecmp wchar.h HAVE_WCSNCASECMP)
# These are for compatibility with Solaris 10, which places the following
# in the std namespace.
if(NOT HAVE_WCSNCASECMP)
check_cxx_symbol_exists(std::wcscasecmp wchar.h HAVE_STD__WCSCASECMP)
check_cxx_symbol_exists(std::wcsncasecmp wchar.h HAVE_STD__WCSNCASECMP)
endif()
# `xlocale.h` is required to find `wcstod_l` in `wchar.h` under FreeBSD,
# but it's not present under Linux.
check_include_files("xlocale.h" HAVE_XLOCALE_H)
if(HAVE_XLOCALE_H)
list(APPEND WCSTOD_L_INCLUDES "xlocale.h")
endif()
list(APPEND WCSTOD_L_INCLUDES "wchar.h")
check_cxx_symbol_exists(wcstod_l "${WCSTOD_L_INCLUDES}" HAVE_WCSTOD_L)
check_cxx_symbol_exists(uselocale "locale.h;xlocale.h" HAVE_USELOCALE)
cmake_push_check_state()
check_struct_has_member("struct winsize" ws_row "termios.h;sys/ioctl.h" _HAVE_WINSIZE)
check_cxx_symbol_exists("TIOCGWINSZ" "termios.h;sys/ioctl.h" HAVE_TIOCGWINSZ)
if(_HAVE_WINSIZE EQUAL 1 AND HAVE_TIOCGWINSZ EQUAL 1)
set(HAVE_WINSIZE 1)
endif()
cmake_pop_check_state()
check_type_size("wchar_t[8]" WCHAR_T_BITS LANGUAGE CXX)
set(TPARM_INCLUDES)
if(HAVE_NCURSES_H)
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses.h>\n")
elseif(HAVE_NCURSES_CURSES_H)
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses/curses.h>\n")
else()
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <curses.h>\n")
endif()
if(HAVE_TERM_H)
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <term.h>\n")
elseif(HAVE_NCURSES_TERM_H)
set(TPARM_INCLUDES "${TPARM_INCLUDES}#include <ncurses/term.h>\n")
endif()
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY})
# Solaris and X/Open-conforming systems have a fixed-args tparm
check_cxx_source_compiles("
#define TPARM_VARARGS
${TPARM_INCLUDES}
int main () {
tparm( \"\" );
}
"
TPARM_TAKES_VARARGS
)
# Check if tputs needs a function reading an int or char.
# The only curses I can find that needs a char is OpenIndiana.
check_cxx_source_compiles("
#include <curses.h>
#include <term.h>
static int writer(int b) {
return b;
}
int main() {
return tputs(\"foo\", 5, writer);
}"
TPUTS_USES_INT_ARG
)
if(TPARM_TAKES_VARARGS)
set(TPARM_VARARGS 1)
else()
set(TPARM_SOLARIS_KLUDGE 1)
endif()
cmake_pop_check_state()
# Work around the fact that cmake does not propagate the language standard flag into
# the CHECK_CXX_SOURCE_COMPILES function. See CMake issue #16456.
# Ensure we do this after the FIND_PACKAGE calls which use C, and will error on a C++
# standards flag.
# Also see https://github.com/fish-shell/fish-shell/issues/5865
if(NOT POLICY CMP0067)
list(APPEND CMAKE_REQUIRED_FLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_EXTENSION_COMPILE_OPTION}")
endif()
check_cxx_source_compiles("
#include <memory>
int main () {
std::unique_ptr<int> foo = std::make_unique<int>();
}
"
HAVE_STD__MAKE_UNIQUE
)
# Detect support for thread_local.
check_cxx_source_compiles("
int main () {
static thread_local int x = 3;
(void)x;
}
"
HAVE_CX11_THREAD_LOCAL
)
check_cxx_source_compiles("
#include <atomic>
#include <cstdint>
std::atomic<uint8_t> n8 (0);
std::atomic<uint64_t> n64 (0);
int main() {
uint8_t i = n8.load(std::memory_order_relaxed);
uint64_t j = n64.load(std::memory_order_relaxed);
return std::atomic_is_lock_free(&n8)
& std::atomic_is_lock_free(&n64);
}"
LIBATOMIC_NOT_NEEDED)
IF (NOT LIBATOMIC_NOT_NEEDED)
set(ATOMIC_LIBRARY "atomic")
endif()
check_cxx_source_compiles("
#include <sys/wait.h>
int main() {
static_assert(WEXITSTATUS(0x007f) == 0x7f, \"This is our message we need to add because C++ is terrible\");
return 0;
}
"
HAVE_WAITSTATUS_SIGNAL_RET)
IF (APPLE)
# Check if mbrtowc implementation attempts to encode invalid UTF-8 sequences
# Known culprits: at least some versions of macOS (confirmed Snow Leopard and Yosemite)
try_run(mbrtowc_invalid_utf8_exit mbrtowc_invalid_utf8_compiles ${CMAKE_CURRENT_BINARY_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/checks/mbrtowc_invalid_utf8.cpp")
IF ("${mbrtowc_invalid_utf8_compiles}" AND ("${mbrtowc_invalid_utf8_exit}" EQUAL 1))
SET(HAVE_BROKEN_MBRTOWC_UTF8 1)
ENDIF()
ENDIF()

View File

@@ -16,7 +16,7 @@ set(SPHINX_MANPAGE_DIR "${SPHINX_ROOT_DIR}/man")
# Prepend the output dir of fish_indent to PATH.
add_custom_target(sphinx-docs
mkdir -p ${SPHINX_HTML_DIR}/_static/
COMMAND env PATH="$<TARGET_FILE_DIR:fish_indent>:$$PATH"
COMMAND env PATH="${CMAKE_BINARY_DIR}:$$PATH"
${SPHINX_EXECUTABLE}
-j auto
-q -b html
@@ -29,7 +29,7 @@ add_custom_target(sphinx-docs
# sphinx-manpages needs the fish_indent binary for the version number
add_custom_target(sphinx-manpages
env PATH="$<TARGET_FILE_DIR:fish_indent>:$$PATH"
env FISH_BUILD_VERSION_FILE=${CMAKE_CURRENT_BINARY_DIR}/${FBVF}
${SPHINX_EXECUTABLE}
-j auto
-q -b man
@@ -38,7 +38,7 @@ add_custom_target(sphinx-manpages
"${SPHINX_SRC_DIR}"
# TODO: This only works if we only have section 1 manpages.
"${SPHINX_MANPAGE_DIR}/man1"
DEPENDS fish_indent
DEPENDS CHECK-FISH-BUILD-VERSION-FILE
COMMENT "Building man pages with Sphinx")
if(SPHINX_EXECUTABLE)

87
cmake/FindRust.cmake Normal file
View File

@@ -0,0 +1,87 @@
#[=======================================================================[.rst:
Imported from Corrosion https://github.com/corrosion-rs/corrosion/
Copyright (c) 2018 Andrew Gaspar
Licensed under the MIT license
However this is absolutely gutted and reduced to the bare minimum.
#]=======================================================================]
include(FindPackageHandleStandardArgs)
cmake_minimum_required(VERSION 3.12)
# List of user variables that will override any toolchain-provided setting
set(_Rust_USER_VARS Rust_COMPILER Rust_CARGO Rust_CARGO_TARGET)
foreach(_VAR ${_Rust_USER_VARS})
if (DEFINED "${_VAR}")
set(${_VAR}_CACHED "${${_VAR}}" CACHE INTERNAL "Internal cache of ${_VAR}")
else()
unset(${_VAR}_CACHED CACHE)
endif()
endforeach()
if (NOT DEFINED Rust_CARGO_CACHED)
find_program(Rust_CARGO_CACHED cargo PATHS "$ENV{HOME}/.cargo/bin")
endif()
if (NOT EXISTS "${Rust_CARGO_CACHED}")
message(FATAL_ERROR "The cargo executable ${Rust_CARGO_CACHED} was not found. "
"Consider setting `Rust_CARGO_CACHED` to the absolute path of `cargo`."
)
endif()
if (NOT DEFINED Rust_COMPILER_CACHED)
find_program(Rust_COMPILER_CACHED rustc PATHS "$ENV{HOME}/.cargo/bin")
endif()
if (NOT EXISTS "${Rust_COMPILER_CACHED}")
message(FATAL_ERROR "The rustc executable ${Rust_COMPILER} was not found. "
"Consider setting `Rust_COMPILER` to the absolute path of `rustc`."
)
endif()
# Figure out the target by just using the host target.
# If you want to cross-compile, you'll have to set Rust_CARGO_TARGET
if(NOT Rust_CARGO_TARGET_CACHED)
execute_process(
COMMAND "${Rust_COMPILER_CACHED}" --version --verbose
OUTPUT_VARIABLE _RUSTC_VERSION_RAW
RESULT_VARIABLE _RUSTC_VERSION_RESULT
)
if(NOT ( "${_RUSTC_VERSION_RESULT}" EQUAL "0" ))
message(FATAL_ERROR "Failed to get rustc version.\n"
"${Rust_COMPILER} --version failed with error: `${_RUSTC_VERSION_RESULT}`")
endif()
if (_RUSTC_VERSION_RAW MATCHES "host: ([a-zA-Z0-9_\\-]*)\n")
set(Rust_DEFAULT_HOST_TARGET "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR
"Failed to parse rustc host target. `rustc --version --verbose` evaluated to:\n${_RUSTC_VERSION_RAW}"
)
endif()
if(CMAKE_CROSSCOMPILING)
message(FATAL_ERROR "CMake is in cross-compiling mode."
"Manually set `Rust_CARGO_TARGET`."
)
endif()
set(Rust_CARGO_TARGET_CACHED "${Rust_DEFAULT_HOST_TARGET}" CACHE STRING "Target triple")
endif()
# Set the input variables as non-cache variables so that the variables are available after
# `find_package`, even if the values were evaluated to defaults.
foreach(_VAR ${_Rust_USER_VARS})
set(${_VAR} "${${_VAR}_CACHED}")
# Ensure cached variables have type INTERNAL
set(${_VAR}_CACHED "${${_VAR}_CACHED}" CACHE INTERNAL "Internal cache of ${_VAR}")
endforeach()
find_package_handle_standard_args(
Rust
REQUIRED_VARS Rust_COMPILER Rust_CARGO Rust_CARGO_TARGET
)

View File

@@ -1,13 +1,6 @@
# -DLOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}"
# -DPREFIX=L"${CMAKE_INSTALL_PREFIX}"
# -DDATADIR=L"${CMAKE_INSTALL_FULL_DATADIR}"
# -DSYSCONFDIR=L"${CMAKE_INSTALL_FULL_SYSCONFDIR}"
# -DBINDIR=L"${CMAKE_INSTALL_FULL_BINDIR}"
# -DDOCDIR=L"${CMAKE_INSTALL_FULL_DOCDIR}")
set(CMAKE_INSTALL_MESSAGE NEVER)
set(PROGRAMS fish fish_indent fish_key_reader)
set(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/fish ${CMAKE_CURRENT_BINARY_DIR}/fish_indent ${CMAKE_CURRENT_BINARY_DIR}/fish_key_reader)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(bindir ${CMAKE_INSTALL_BINDIR})
@@ -19,11 +12,6 @@ file(RELATIVE_PATH rel_datadir ${CMAKE_INSTALL_PREFIX} ${datadir})
set(docdir ${CMAKE_INSTALL_DOCDIR})
# Comment at the top of some .in files
set(configure_input
"This file was generated from a corresponding .in file.\
DO NOT MANUALLY EDIT THIS FILE!")
set(rel_completionsdir "fish/vendor_completions.d")
set(rel_functionsdir "fish/vendor_functions.d")
set(rel_confdir "fish/vendor_conf.d")
@@ -40,10 +28,21 @@ set(extra_confdir
"${datadir}/${rel_confdir}"
CACHE STRING "Path for extra configuration")
# These are the man pages that go in system manpath; all manpages go in the fish-specific manpath.
set(MANUALS ${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish_indent.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish_key_reader.1)
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish_key_reader.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-doc.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-tutorial.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-language.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-interactive.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-terminal-compatibility.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-completions.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-prompt-tutorial.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-for-bash-users.1
${CMAKE_CURRENT_BINARY_DIR}/user_doc/man/man1/fish-faq.1
)
# Determine which man page we don't want to install.
# On OS X, don't install a man page for open, since we defeat fish's open
@@ -76,7 +75,7 @@ function(FISH_TRY_CREATE_DIRS)
endforeach()
endfunction(FISH_TRY_CREATE_DIRS)
install(TARGETS ${PROGRAMS}
install(PROGRAMS ${PROGRAMS}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${bindir})
@@ -90,7 +89,6 @@ fish_create_dirs(${rel_datadir}/fish ${rel_datadir}/fish/completions
${rel_datadir}/fish/man/man1 ${rel_datadir}/fish/tools
${rel_datadir}/fish/tools/web_config
${rel_datadir}/fish/tools/web_config/js
${rel_datadir}/fish/tools/web_config/partials
${rel_datadir}/fish/tools/web_config/sample_prompts
${rel_datadir}/fish/tools/web_config/themes
)
@@ -110,7 +108,7 @@ configure_file(fish.pc.in fish.pc.noversion @ONLY)
add_custom_command(OUTPUT fish.pc
COMMAND sed '/Version/d' fish.pc.noversion > fish.pc
COMMAND printf "Version: " >> fish.pc
COMMAND sed 's/FISH_BUILD_VERSION=//\;s/\"//g' ${FBVF} >> fish.pc
COMMAND cat ${FBVF} >> fish.pc
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS CHECK-FISH-BUILD-VERSION-FILE ${CMAKE_CURRENT_BINARY_DIR}/fish.pc.noversion)
@@ -158,24 +156,8 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/user_doc/html/ # Trailing slash is
DESTINATION ${docdir} OPTIONAL)
install(FILES CHANGELOG.rst DESTINATION ${docdir})
# These files are built by cmake/gettext.cmake, but using GETTEXT_PROCESS_PO_FILES's
# INSTALL_DESTINATION leads to them being installed as ${lang}.gmo, not fish.mo
# The ${languages} array comes from cmake/gettext.cmake
if(GETTEXT_FOUND)
foreach(lang ${languages})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo DESTINATION
${CMAKE_INSTALL_LOCALEDIR}/${lang}/LC_MESSAGES/ RENAME fish.mo)
endforeach()
endif()
if (NOT APPLE)
install(FILES fish.desktop DESTINATION ${rel_datadir}/applications)
install(FILES ${SPHINX_SRC_DIR}/python_docs_theme/static/fish.png DESTINATION ${rel_datadir}/pixmaps)
endif()
# Group install targets into a InstallTargets folder
set_property(TARGET build_fish_pc CHECK-FISH-BUILD-VERSION-FILE
tests_buildroot_target
PROPERTY FOLDER cmake/InstallTargets)
# Make a target build_root that installs into the buildroot directory, for testing.

View File

@@ -1,44 +0,0 @@
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.10" CACHE STRING "Minimum OS X deployment version")
# Code signing ID on Mac.
# If this is falsey, codesigning is disabled.
# '-' is ad-hoc codesign.
set(MAC_CODESIGN_ID "" CACHE STRING "Mac code-signing identity")
# Whether to inject the "get-task-allow" entitlement, which permits debugging
# on the Mac.
set(MAC_INJECT_GET_TASK_ALLOW ON CACHE BOOL "Inject get-task-allow on Mac")
# When building a Mac build, it is common for fish to link against a
# pcre2 built for the host platform (e.g. macOS 10.15) while fish wants
# to link for macOS 10.9. This warning would be of interest for releases,
# but is just noise for daily development. Unfortunately it has no flag
# of its own, so suppress all linker warnings in debug builds.
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -w")
function(CODESIGN_ON_MAC target)
if((APPLE) AND (MAC_CODESIGN_ID))
execute_process(COMMAND sw_vers "-productVersion" OUTPUT_VARIABLE OSX_VERSION)
if(MAC_INJECT_GET_TASK_ALLOW)
set(ENTITLEMENTS "--entitlements" "${CMAKE_SOURCE_DIR}/osx/fish_debug.entitlements")
else()
set(ENTITLEMENTS "")
endif(MAC_INJECT_GET_TASK_ALLOW)
if(OSX_VERSION VERSION_LESS "10.13.6")
# `-options runtime` is only available in OS X from 10.13.6 and up
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND codesign --force --deep ${ENTITLEMENTS} --sign "${MAC_CODESIGN_ID}" $<TARGET_FILE:${target}>
VERBATIM
)
else()
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND codesign --force --deep --options runtime ${ENTITLEMENTS} --sign "${MAC_CODESIGN_ID}" $<TARGET_FILE:${target}>
VERBATIM
)
endif()
endif()
endfunction(CODESIGN_ON_MAC target)

View File

@@ -6,6 +6,9 @@ endif (NOT APPLE)
# The source tree containing certain macOS resources.
set(OSX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/osx)
# 10.9 is the minimum supported version.
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
set(RESOURCE_FILES
${OSX_DIR}/launch_fish.scpt
${OSX_DIR}/fish_term_icon.icns
@@ -21,7 +24,7 @@ add_executable(fish_macapp EXCLUDE_FROM_ALL
# Compute the version. Note this is done at generation time, not build time,
# so cmake must be re-run after version changes for the app to be updated. But
# generally this will be run by make_pkg.sh which always re-runs cmake.
# generally this will be run by make_macos_pkg.sh which always re-runs cmake.
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/git_version_gen.sh --stdout
COMMAND cut -d- -f1
@@ -29,7 +32,7 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Note CMake appends .app, so the real output name will be fish.app.
# Note CMake appends .app, so the real output name will be fish.app.
# This target does not include the 'base' resource.
set_target_properties(fish_macapp PROPERTIES OUTPUT_NAME "fish")
@@ -61,18 +64,5 @@ add_custom_command(TARGET fish_macapp POST_BUILD
# The entitlements file.
set(MACAPP_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/osx/MacApp.entitlements")
# Target to sign the macapp.
# Note that a POST_BUILD step happens before resources are copied,
# and therefore would be too early.
add_custom_target(signed_fish_macapp
DEPENDS fish_macapp "${MACAPP_ENTITLEMENTS}"
COMMAND codesign --force --deep
--options runtime
--entitlements "${MACAPP_ENTITLEMENTS}"
--sign "${MAC_CODESIGN_ID}"
$<TARGET_BUNDLE_DIR:fish_macapp>
VERBATIM
)
# Group our targets in a folder.
set_property(TARGET fish_macapp signed_fish_macapp PROPERTY FOLDER macapp)
set_property(TARGET fish_macapp PROPERTY FOLDER macapp)

View File

@@ -1,77 +1,9 @@
# PCRE2 needs some settings.
set(PCRE2_WIDTH ${WCHAR_T_BITS})
set(PCRE2_BUILD_PCRE2_8 OFF CACHE BOOL "Build 8bit PCRE2 library")
set(PCRE2_BUILD_PCRE2_${PCRE2_WIDTH} ON CACHE BOOL "Build ${PCRE2_WIDTH}bit PCRE2 library")
set(PCRE2_SHOW_REPORT OFF CACHE BOOL "Show the final configuration report")
set(PCRE2_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(PCRE2_BUILD_PCRE2GREP OFF CACHE BOOL "Build pcre2grep")
set(PCRE2_MIN_VERSION 10.21)
# Look for a system-installed PCRE2.
find_library(SYS_PCRE2_LIB pcre2-${PCRE2_WIDTH})
find_path(SYS_PCRE2_INCLUDE_DIR pcre2.h)
# We can either use the system-installed PCRE or our bundled version.
# This is controlled by the cache variable FISH_USE_SYSTEM_PCRE2.
# Here we compute the default value for that variable.
if ((APPLE) AND (MAC_CODESIGN_ID))
# On Mac, a codesigned fish will refuse to load a non-codesigned PCRE2
# (e.g. from Homebrew) so default to bundled PCRE2.
set(USE_SYS_PCRE2_DEFAULT OFF)
elseif((NOT SYS_PCRE2_LIB) OR (NOT SYS_PCRE2_INCLUDE_DIR))
# We did not find system PCRE2, so default to bundled.
set(USE_SYS_PCRE2_DEFAULT OFF)
else()
# Default to using the system PCRE2, which was found.
set(USE_SYS_PCRE2_DEFAULT ON)
endif()
set(FISH_USE_SYSTEM_PCRE2 ${USE_SYS_PCRE2_DEFAULT} CACHE BOOL
"Use PCRE2 from the system, instead of fetching and building it")
set(FISH_USE_SYSTEM_PCRE2 ON CACHE BOOL
"Try to use PCRE2 from the system, instead of the pcre2-sys version")
if(FISH_USE_SYSTEM_PCRE2)
set(PCRE2_LIB "${SYS_PCRE2_LIB}")
set(PCRE2_INCLUDE_DIR "${SYS_PCRE2_INCLUDE_DIR}")
message(STATUS "Using system PCRE2 library ${PCRE2_INCLUDE_DIR}")
message(STATUS "Trying to use PCRE2 from the system")
else()
include(FetchContent RESULT_VARIABLE HAVE_FetchContent)
if (${HAVE_FetchContent} STREQUAL "NOTFOUND")
message(FATAL_ERROR "Please install PCRE2 headers, or CMake >= 3.11 so I can download PCRE")
endif()
set(CMAKE_TLS_VERIFY true)
set(PCRE2_REPO "https://github.com/PCRE2Project/pcre2.git")
message(STATUS "Fetching and configuring PCRE2 from ${PCRE2_REPO}")
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
pcre2
GIT_REPOSITORY ${PCRE2_REPO}
GIT_TAG "72669190cb947f0cac1d038a8bb1820da59ef447" # tag: pcre2-10.36
GIT_SHALLOW ON
GIT_PROGRESS TRUE
)
# Don't try FetchContent_MakeAvailable, there's no way to add EXCLUDE_FROM_ALL
# so we end up installing all of PCRE2 including its headers, man pages, etc.
FetchContent_GetProperties(pcre2)
if (NOT pcre2_POPULATED)
# If GIT_WORK_TREE is set (by user or by git itself with e.g. git rebase), it
# will override the git directory which CMake tries to apply in FetchContent_Populate,
# resulting in a failed checkout.
# Ensure it is not set.
unset(ENV{GIT_WORK_TREE})
unset(ENV{GIT_DIR})
FetchContent_Populate(pcre2)
add_subdirectory(${pcre2_SOURCE_DIR} ${pcre2_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
set(PCRE2_INCLUDE_DIR ${pcre2_BINARY_DIR})
set(PCRE2_LIB pcre2-${PCRE2_WIDTH})
# Disable -Wunused-macros inside PCRE2, as it is noisy.
get_target_property(PCRE2_COMPILE_OPTIONS ${PCRE2_LIB} COMPILE_OPTIONS)
list(REMOVE_ITEM PCRE2_COMPILE_OPTIONS "-Wunused-macros")
set_property(TARGET ${PCRE2_LIB} PROPERTY COMPILE_OPTIONS ${PCRE2_COMPILE_OPTIONS})
message(STATUS "Forcing static build of PCRE2")
set(FISH_PCRE2_BUILDFLAG "PCRE2_SYS_STATIC=1")
endif(FISH_USE_SYSTEM_PCRE2)
include_directories(${PCRE2_INCLUDE_DIR})

46
cmake/Rust.cmake Normal file
View File

@@ -0,0 +1,46 @@
include(FindRust)
find_package(Rust REQUIRED)
set(FISH_RUST_BUILD_DIR "${CMAKE_BINARY_DIR}/cargo/build")
if(DEFINED ASAN)
list(APPEND CARGO_FLAGS "-Z" "build-std")
list(APPEND FISH_CARGO_FEATURES_LIST "asan")
endif()
if(DEFINED TSAN)
list(APPEND CARGO_FLAGS "-Z" "build-std")
list(APPEND FISH_CARGO_FEATURES_LIST "tsan")
endif()
if (Rust_CARGO_TARGET)
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_TARGET}")
else()
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_HOST_TARGET}")
endif()
set(rust_profile $<IF:$<CONFIG:Debug>,debug,$<IF:$<CONFIG:RelWithDebInfo>,release-with-debug,release>>)
set(rust_debugflags "$<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g>")
option(WITH_GETTEXT "Build with gettext localization support. Requires `msgfmt` to work." ON)
# Enable gettext feature unless explicitly disabled.
if(NOT DEFINED WITH_GETTEXT OR "${WITH_GETTEXT}")
list(APPEND FISH_CARGO_FEATURES_LIST "localize-messages")
endif()
list(JOIN FISH_CARGO_FEATURES_LIST , FISH_CARGO_FEATURES)
# Tell Cargo where our build directory is so it can find Cargo.toml.
set(VARS_FOR_CARGO
"FISH_BUILD_DIR=${CMAKE_BINARY_DIR}"
"PREFIX=${CMAKE_INSTALL_PREFIX}"
# Cheesy so we can tell cmake was used to build
"CMAKE=1"
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"
"BINDIR=${CMAKE_INSTALL_FULL_BINDIR}"
"CARGO_TARGET_DIR=${FISH_RUST_BUILD_DIR}"
"CARGO_BUILD_RUSTC=${Rust_COMPILER}"
"${FISH_PCRE2_BUILDFLAG}"
"RUSTFLAGS=$ENV{RUSTFLAGS} ${rust_debugflags}"
)

View File

@@ -1,177 +1,64 @@
# This adds ctest support to the project
enable_testing()
# By default, ctest runs tests serially
if(NOT CTEST_PARALLEL_LEVEL)
include(ProcessorCount)
ProcessorCount(CORES)
set(CTEST_PARALLEL_LEVEL ${CORES})
endif()
# Put in a tests folder to reduce the top level targets in IDEs.
set(CMAKE_FOLDER tests)
# We will use 125 as a reserved exit code to indicate that a test has been skipped, i.e. it did not
# pass but it should not be considered a failed test run, either.
set(SKIP_RETURN_CODE 125)
# Even though we are using CMake's ctest for testing, we still define our own `make test` target
# rather than use its default for many reasons:
# * CMake doesn't run tests in-proc or even add each tests as an individual node in the ninja
# dependency tree, instead it just bundles all tests into a target called `test` that always just
# shells out to `ctest`, so there are no build-related benefits to not doing that ourselves.
# * CMake devs insist that it is appropriate for `make test` to never depend on `make all`, i.e.
# running `make test` does not require any of the binaries to be built before testing.
# * The only way to have a test depend on a binary is to add a fake test with a name like
# "build_fish" that executes CMake recursively to build the `fish` target.
# * It is not possible to set top-level CTest options/settings such as CTEST_PARALLEL_LEVEL from
# within the CMake configuration file.
# * Circling back to the point about individual tests not being actual Makefile targets, CMake does
# not offer any way to execute a named test via the `make`/`ninja`/whatever interface; the only
# way to manually invoke test `foo` is to to manually run `ctest` and specify a regex matching
# `foo` as an argument, e.g. `ctest -R ^foo$`... which is really crazy.
# The top-level test target is "fish_run_tests".
add_custom_target(fish_run_tests
COMMAND env CTEST_PARALLEL_LEVEL=${CTEST_PARALLEL_LEVEL} FISH_FORCE_COLOR=1
FISH_SOURCE_DIR=${CMAKE_SOURCE_DIR}
${CMAKE_CTEST_COMMAND} --force-new-ctest-process # --verbose
--output-on-failure --progress
DEPENDS fish_tests tests_buildroot_target
USES_TERMINAL
)
# If CMP0037 is available, also make an alias "test" target.
# Note that this policy may not be available, in which case definining such a target silently fails.
cmake_policy(PUSH)
if(POLICY CMP0037)
cmake_policy(SET CMP0037 OLD)
add_custom_target(test DEPENDS fish_run_tests)
endif()
cmake_policy(POP)
# Build the low-level tests code
add_executable(fish_tests EXCLUDE_FROM_ALL
src/fish_tests.cpp)
fish_link_deps_and_sign(fish_tests)
# The "test" directory.
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test)
# CMake doesn't really support dynamic test discovery where a test harness is executed to list the
# tests it contains, making fish_tests.cpp's tests opaque to CMake (whereas littlecheck tests can be
# enumerated from the filesystem). We used to compile fish_tests.cpp without linking against
# anything (-Wl,-undefined,dynamic_lookup,--unresolved-symbols=ignore-all) to get it to print its
# tests at configuration time, but that's a little too much dark CMake magic.
#
# We now identify tests by checking against a magic regex that's #define'd as a no-op C-side.
file(READ "${CMAKE_SOURCE_DIR}/src/fish_tests.cpp" FISH_TESTS_CPP)
string(REGEX MATCHALL "TEST_GROUP\\( *\"([^\"]+)\"" "LOW_LEVEL_TESTS" "${FISH_TESTS_CPP}")
string(REGEX REPLACE "TEST_GROUP\\( *\"([^\"]+)\"" "\\1" "LOW_LEVEL_TESTS" "${LOW_LEVEL_TESTS}")
list(REMOVE_DUPLICATES LOW_LEVEL_TESTS)
# The directory into which fish is installed.
set(TEST_INSTALL_DIR ${TEST_DIR}/buildroot)
# The directory where the tests expect to find the fish root (./bin, etc)
set(TEST_ROOT_DIR ${TEST_DIR}/root)
# Copy needed directories for out-of-tree builds
if(NOT FISH_IN_TREE_BUILD)
add_custom_target(funcs_dir)
add_custom_command(TARGET funcs_dir
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/share
# Don't run ln twice or it will create a new link in the link.
COMMAND test -e ${CMAKE_BINARY_DIR}/share/functions || ln -sf
${CMAKE_SOURCE_DIR}/share/functions/ ${CMAKE_BINARY_DIR}/share/functions
COMMENT "Symlinking fish functions to binary dir"
VERBATIM)
add_custom_target(tests_dir DEPENDS tests)
add_custom_command(TARGET tests_dir
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/tests/ ${CMAKE_BINARY_DIR}/tests/
COMMENT "Copying test files to binary dir"
VERBATIM)
add_dependencies(fish_tests tests_dir funcs_dir)
endif()
# Copy littlecheck.py
configure_file(build_tools/littlecheck.py littlecheck.py COPYONLY)
# Copy pexpect_helper.py
configure_file(build_tools/pexpect_helper.py pexpect_helper.py COPYONLY)
# Suppress generating Xcode schemes for all tests, there's too many.
set(CMAKE_XCODE_GENERATE_SCHEME 0)
# CMake being CMake, you can't just add a DEPENDS argument to add_test to make it depend on any of
# your binaries actually being built before `make test` is executed (requiring `make all` first),
# and the only dependency a test can have is on another test. So we make building fish and
# `fish_tests` prerequisites to our entire top-level `test` target.
function(add_test_target NAME)
string(REPLACE "/" "-" NAME ${NAME})
add_custom_target("test_${NAME}" COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -R "^${NAME}$$"
DEPENDS fish_tests tests_buildroot_target USES_TERMINAL )
endfunction()
add_custom_target(tests_buildroot_target
# Make the directory in which to run tests:
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
COMMAND env DESTDIR=${TEST_INSTALL_DIR} ${CMAKE_COMMAND}
--build ${CMAKE_CURRENT_BINARY_DIR} --target install
# Put fish_test_helper there too:
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/fish_test_helper
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}/bin
# Also symlink fish to where the tests expect it to be:
COMMAND ${CMAKE_COMMAND} -E create_symlink
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}
${TEST_ROOT_DIR}
DEPENDS fish fish_test_helper)
# CMake less than 3.9.0 "fully supports" setting an exit code to denote a skipped test, but then
# it just goes ahead and reports it as failed. Really?
if(${CMAKE_VERSION} VERSION_LESS "3.9.0")
set(CMAKE_SKIPPED_HACK "env" "CMAKE_SKIPPED_HACK=1")
else()
set(CMAKE_SKIPPED_HACK)
endif()
foreach(LTEST ${LOW_LEVEL_TESTS})
add_test(
NAME ${LTEST}
COMMAND sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_env.sh
${CMAKE_BINARY_DIR}/fish_tests ${LTEST}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(${LTEST} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
add_test_target("${LTEST}")
endforeach(LTEST)
add_executable(fish_test_helper tests/fish_test_helper.c)
FILE(GLOB FISH_CHECKS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/checks/*.fish)
foreach(CHECK ${FISH_CHECKS})
get_filename_component(CHECK_NAME ${CHECK} NAME)
get_filename_component(CHECK ${CHECK} NAME_WE)
add_test(NAME ${CHECK_NAME}
COMMAND ${CMAKE_SKIPPED_HACK} sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_driver.sh
${CMAKE_CURRENT_BINARY_DIR}/tests/test.fish ${CHECK}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
add_custom_target(
test_${CHECK_NAME}
COMMAND ${CMAKE_SOURCE_DIR}/tests/test_driver.py ${CMAKE_CURRENT_BINARY_DIR}
checks/${CHECK_NAME}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
DEPENDS fish fish_indent fish_key_reader fish_test_helper
USES_TERMINAL
)
set_tests_properties(${CHECK_NAME} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
set_tests_properties(${CHECK_NAME} PROPERTIES ENVIRONMENT FISH_FORCE_COLOR=1)
add_test_target("${CHECK_NAME}")
endforeach(CHECK)
FILE(GLOB PEXPECTS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/pexpects/*.py)
foreach(PEXPECT ${PEXPECTS})
get_filename_component(PEXPECT ${PEXPECT} NAME)
add_test(NAME ${PEXPECT}
COMMAND ${CMAKE_SKIPPED_HACK} sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_driver.sh
${CMAKE_CURRENT_BINARY_DIR}/tests/interactive.fish ${PEXPECT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
add_custom_target(
test_${PEXPECT}
COMMAND ${CMAKE_SOURCE_DIR}/tests/test_driver.py ${CMAKE_CURRENT_BINARY_DIR}
pexpects/${PEXPECT}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
DEPENDS fish fish_indent fish_key_reader fish_test_helper
USES_TERMINAL
)
set_tests_properties(${PEXPECT} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
set_tests_properties(${PEXPECT} PROPERTIES ENVIRONMENT FISH_FORCE_COLOR=1)
add_test_target("${PEXPECT}")
endforeach(PEXPECT)
# Rust stuff.
set(cargo_test_flags)
if(DEFINED ASAN)
# Rust w/ -Zsanitizer=address requires explicitly specifying the --target triple or else linker
# errors pertaining to asan symbols will ensue.
if(NOT DEFINED Rust_CARGO_TARGET)
message(FATAL_ERROR "ASAN requires defining the CMake variable Rust_CARGO_TARGET to the
intended target triple")
endif()
endif()
if(DEFINED TSAN)
if(NOT DEFINED Rust_CARGO_TARGET)
message(FATAL_ERROR "TSAN requires defining the CMake variable Rust_CARGO_TARGET to the
intended target triple")
endif()
endif()
if(DEFINED Rust_CARGO_TARGET)
list(APPEND cargo_test_flags "--target" ${Rust_CARGO_TARGET})
list(APPEND cargo_test_flags "--lib")
endif()
set(max_concurrency_flag)
if(DEFINED ENV{FISH_TEST_MAX_CONCURRENCY})
list(APPEND max_concurrency_flag "--max-concurrency" $ENV{FISH_TEST_MAX_CONCURRENCY})
endif()
# The top-level test target is "fish_run_tests".
add_custom_target(fish_run_tests
# TODO: This should be replaced with a unified solution, possibly build_tools/check.sh.
COMMAND ${CMAKE_SOURCE_DIR}/tests/test_driver.py ${max_concurrency_flag} ${CMAKE_CURRENT_BINARY_DIR}
COMMAND env ${VARS_FOR_CARGO} cargo test --no-default-features ${CARGO_FLAGS} --workspace --target-dir ${rust_target_dir} ${cargo_test_flags}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS fish fish_indent fish_key_reader fish_test_helper
USES_TERMINAL
)

View File

@@ -1,18 +0,0 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cwchar>
// Check whether the runtime mbrtowc implementation attempts to encode
// invalid UTF-8 values.
int main() {
// TODO: I'm not sure how to enforce a UTF-8 locale without overriding the language
char sample[] = "hello world";
sample[0] |= 0xF8;
wchar_t wsample[100] {};
std::mbstate_t state = std::mbstate_t();
int res = std::mbrtowc(wsample, sample, strlen(sample), &state);
return res < 0 ? 0 : 1;
}

View File

@@ -1,56 +0,0 @@
set(languages de en fr pl pt_BR sv zh_CN)
include(FeatureSummary)
option(WITH_GETTEXT "translate messages if gettext is available" ON)
if(WITH_GETTEXT)
if(APPLE)
# Fix for https://github.com/fish-shell/fish-shell/issues/5244
# via https://gitlab.kitware.com/cmake/cmake/-/issues/18921
set(CMAKE_FIND_FRAMEWORK_OLD ${CMAKE_FIND_FRAMEWORK})
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
find_package(Intl QUIET)
find_package(Gettext)
if(GETTEXT_FOUND)
set(HAVE_GETTEXT 1)
include_directories(${Intl_INCLUDE_DIR})
endif()
if(APPLE)
set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_OLD})
unset(CMAKE_FIND_FRAMEWORK_OLD)
endif()
endif()
add_feature_info(gettext GETTEXT_FOUND "translate messages with gettext")
# Define translations
if(GETTEXT_FOUND)
# Group pofile targets into their own folder, as there's a lot of them.
set(CMAKE_FOLDER pofiles)
foreach(lang ${languages})
# Our translations aren't set up entirely as CMake expects, so installation is done in
# cmake/Install.cmake instead of using INSTALL_DESTINATION
gettext_process_po_files(${lang} ALL
PO_FILES po/${lang}.po)
endforeach()
set(CMAKE_FOLDER)
endif()
cmake_push_check_state()
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${Intl_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${Intl_LIBRARIES})
# libintl.h can be compiled into the stdlib on some GLibC systems
if(Intl_FOUND AND Intl_LIBRARIES)
set(LIBINTL_INCLUDE "#include <libintl.h>")
endif()
check_cxx_source_compiles("
${LIBINTL_INCLUDE}
#include <stdlib.h>
int main () {
extern int _nl_msg_cat_cntr;
int tmp = _nl_msg_cat_cntr;
exit(tmp);
}
"
HAVE__NL_MSG_CAT_CNTR)
cmake_pop_check_state()

View File

@@ -1,188 +0,0 @@
/* Define to 1 if you have the `backtrace_symbols' function. */
#cmakedefine HAVE_BACKTRACE_SYMBOLS 1
/* Define to 1 if compiled on WSL */
#cmakedefine WSL 1
/* Define to 1 if you have the `ctermid_r' function. */
#cmakedefine HAVE_CTERMID_R 1
/* Define to 1 if C++11 thread_local is supported. */
#cmakedefine HAVE_CX11_THREAD_LOCAL 1
/* Define to 1 if you have the `dirfd' function. */
#cmakedefine HAVE_DIRFD 1
/* Define to 1 if you have the <execinfo.h> header file. */
#cmakedefine HAVE_EXECINFO_H 1
/* Define to 1 if you have the `flock' function. */
#cmakedefine HAVE_FLOCK 1
/* Define to 1 if you have the `getpwent' function. */
#cmakedefine HAVE_GETPWENT 1
/* Define to 1 if you have the 'getrusage' function. */
#cmakedefine HAVE_GETRUSAGE 1
/* Define to 1 if you have the `gettext' function. */
#cmakedefine HAVE_GETTEXT 1
/* Define to 1 if you have the `killpg' function. */
#cmakedefine HAVE_KILLPG 1
/* Define to 1 if you have the `mkostemp' function. */
#cmakedefine HAVE_MKOSTEMP 1
/* Define to 1 if you have the <curses.h> header file. */
#cmakedefine HAVE_CURSES_H 1
/* Define to 1 if you have the <ncurses/curses.h> header file. */
#cmakedefine HAVE_NCURSES_CURSES_H 1
/* Define to 1 if you have the <ncurses.h> header file. */
#cmakedefine HAVE_NCURSES_H 1
/* Define to 1 if you have the <ncurses/term.h> header file. */
#cmakedefine HAVE_NCURSES_TERM_H 1
/* Define to 1 if you have the 'eventfd' function. */
#cmakedefine HAVE_EVENTFD 1
/* Define to 1 if you have the 'pipe2' function. */
#cmakedefine HAVE_PIPE2 1
/* Define to 1 if you have the <siginfo.h> header file. */
#cmakedefine HAVE_SIGINFO_H 1
/* Define to 1 if you have the <spawn.h> header file. */
#cmakedefine HAVE_SPAWN_H 1
/* Define to 1 if you have the `std::wcscasecmp' function. */
#cmakedefine HAVE_STD__WCSCASECMP 1
/* Define to 1 if you have the `std::wcsncasecmp' function. */
#cmakedefine HAVE_STD__WCSNCASECMP 1
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#cmakedefine HAVE_STRUCT_DIRENT_D_TYPE 1
/* Define to 1 if `st_ctime_nsec' is a member of `struct stat'. */
#cmakedefine HAVE_STRUCT_STAT_ST_CTIME_NSEC 1
/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
#cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */
#cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#cmakedefine HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
#cmakedefine HAVE_SYS_SELECT_H 1
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#cmakedefine HAVE_SYS_SYSCTL_H 1
/* Define to 1 if you have the <term.h> header file. */
#cmakedefine HAVE_TERM_H 1
/* Define to 1 if you have the `wcscasecmp' function. */
#cmakedefine HAVE_WCSCASECMP 1
/* Define to 1 if you have the `wcsncasecmp' function. */
#cmakedefine HAVE_WCSNCASECMP 1
/* Define to 1 if you have the `wcstod_l' function. */
#cmakedefine HAVE_WCSTOD_L 1
/* Define to 1 if the status that wait returns and WEXITSTATUS expects is signal and then ret instead of the other way around. */
#cmakedefine HAVE_WAITSTATUS_SIGNAL_RET 1
/* Define to 1 if the winsize struct and TIOCGWINSZ macro exist */
#cmakedefine HAVE_WINSIZE 1
/* Define to 1 if the _nl_msg_cat_cntr symbol is exported. */
#cmakedefine HAVE__NL_MSG_CAT_CNTR 1
/* Define to 1 if std::make_unique is available. */
#cmakedefine HAVE_STD__MAKE_UNIQUE 1
/* Define to use clock_gettime and futimens to hack around Linux mtime issue */
#cmakedefine UVAR_FILE_SET_MTIME_HACK 1
/* Define to 1 to disable ncurses macros that conflict with the STL */
#define NCURSES_NOMACROS 1
/* Define to 1 to disable curses macros that conflict with the STL */
#define NOMACROS 1
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "https://github.com/fish-shell/fish-shell/issues"
/* Define to the full name of this package. */
#define PACKAGE_NAME "fish"
/* Use a variadic tparm on NetBSD curses. */
#cmakedefine TPARM_VARARGS 1
/* The parameter type for the last tputs parameter */
#cmakedefine TPUTS_USES_INT_ARG 1
/* Define to 1 if tparm accepts a fixed amount of parameters. */
#cmakedefine TPARM_SOLARIS_KLUDGE 1
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
/* The size of wchar_t in bits. */
#define WCHAR_T_BITS ${WCHAR_T_BITS}
/* Define if xlocale.h is required for locale_t or wide character support */
#cmakedefine HAVE_XLOCALE_H 1
/* Define if uselocale is available */
#cmakedefine HAVE_USELOCALE 1
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Define to 1 if mbrtowc attempts to convert invalid UTF-8 sequences */
#cmakedefine HAVE_BROKEN_MBRTOWC_UTF8 1
/* Support __warn_unused on function return values. */
#if __GNUC__ >= 3
#ifndef __warn_unused
#define __warn_unused __attribute__ ((warn_unused_result))
#endif
#else
#define __warn_unused
#endif
/* Like __warn_unused, but applies to a type.
At the moment only clang supports this as a type attribute.
We need to check for __has_attribute being a thing before or old gcc fails - #7554.
*/
#ifndef __has_attribute
#define __has_attribute(x) 0 // Compatibility with non-clang and old gcc compilers.
#endif
#if defined(__clang__) && __has_attribute(warn_unused_result)
#ifndef __warn_unused_type
#define __warn_unused_type __attribute__ ((warn_unused_result))
#endif
#else
#define __warn_unused_type
#endif
#if __has_attribute(fallthrough)
#define __fallthrough__ __attribute__ ((fallthrough));
#else
#define __fallthrough__
#endif

View File

@@ -0,0 +1,12 @@
[package]
name = "fish-build-helper"
edition.workspace = true
rust-version.workspace = true
version = "0.0.0"
repository.workspace = true
[dependencies]
rsconf.workspace = true
[lints]
workspace = true

View File

@@ -0,0 +1,48 @@
use std::{borrow::Cow, env, os::unix::ffi::OsStrExt, path::Path};
pub fn env_var(name: &str) -> Option<String> {
let err = match env::var(name) {
Ok(p) => return Some(p),
Err(err) => err,
};
use env::VarError::*;
match err {
NotPresent => None,
NotUnicode(os_string) => {
panic!(
"Environment variable {name} is not valid Unicode: {:?}",
os_string.as_bytes()
)
}
}
}
pub fn workspace_root() -> &'static Path {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir.ancestors().nth(2).unwrap()
}
fn cargo_target_dir() -> Cow<'static, Path> {
option_env!("CARGO_TARGET_DIR")
.map(|d| Cow::Borrowed(Path::new(d)))
.unwrap_or(Cow::Owned(workspace_root().join("target")))
}
pub fn fish_build_dir() -> Cow<'static, Path> {
// This is set if using CMake.
option_env!("FISH_BUILD_DIR")
.map(|d| Cow::Borrowed(Path::new(d)))
.unwrap_or(cargo_target_dir())
}
// TODO Move this to rsconf
pub fn rebuild_if_path_changed<P: AsRef<Path>>(path: P) {
rsconf::rebuild_if_path_changed(path.as_ref().to_str().unwrap());
}
// TODO Move this to rsconf
pub fn rebuild_if_paths_changed<P: AsRef<Path>, I: IntoIterator<Item = P>>(paths: I) {
for path in paths {
rsconf::rebuild_if_path_changed(path.as_ref().to_str().unwrap());
}
}

View File

@@ -0,0 +1,13 @@
[package]
name = "fish-build-man-pages"
edition.workspace = true
rust-version.workspace = true
version = "0.0.0"
repository.workspace = true
[build-dependencies]
fish-build-helper.workspace = true
rsconf.workspace = true
[lints]
workspace = true

View File

@@ -0,0 +1,95 @@
#[cfg(not(clippy))]
use std::path::Path;
fn main() {
let mandir = fish_build_helper::fish_build_dir().join("fish-man");
let sec1dir = mandir.join("man1");
// Running `cargo clippy` on a clean build directory panics, because when rust-embed tries to
// embed a directory which does not exist it will panic.
let _ = std::fs::create_dir_all(sec1dir.to_str().unwrap());
#[cfg(not(clippy))]
build_man(&mandir);
}
#[cfg(not(clippy))]
fn build_man(man_dir: &Path) {
use std::process::{Command, Stdio};
use fish_build_helper::{env_var, workspace_root};
let workspace_root = workspace_root();
let man_str = man_dir.to_str().unwrap();
let sec1_dir = man_dir.join("man1");
let sec1_str = sec1_dir.to_str().unwrap();
let docsrc_dir = workspace_root.join("doc_src");
let docsrc_str = docsrc_dir.to_str().unwrap();
let sphinx_doc_sources = [
workspace_root.join("CHANGELOG.rst"),
workspace_root.join("CONTRIBUTING.rst"),
docsrc_dir.clone(),
];
fish_build_helper::rebuild_if_paths_changed(sphinx_doc_sources);
let args = &[
"-j", "auto", "-q", "-b", "man", "-c", docsrc_str,
// doctree path - put this *above* the man1 dir to exclude it.
// this is ~6M
"-d", man_str, docsrc_str, sec1_str,
];
let _ = std::fs::create_dir_all(sec1_str);
rsconf::rebuild_if_env_changed("FISH_BUILD_DOCS");
if env_var("FISH_BUILD_DOCS") == Some("0".to_string()) {
rsconf::warn!("Skipping man pages because $FISH_BUILD_DOCS is set to 0");
return;
}
// We run sphinx to build the man pages.
// Every error here is fatal so cargo doesn't cache the result
// - if we skipped the docs with sphinx not installed, installing it would not then build the docs.
// That means you need to explicitly set $FISH_BUILD_DOCS=0 (`FISH_BUILD_DOCS=0 cargo install --path .`),
// which is unfortunate - but the docs are pretty important because they're also used for --help.
let sphinx_build = match Command::new("sphinx-build")
.args(args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
if env_var("FISH_BUILD_DOCS") == Some("1".to_string()) {
panic!("Could not find sphinx-build to build man pages.\nInstall sphinx or disable building the docs by setting $FISH_BUILD_DOCS=0.");
}
rsconf::warn!("Cannot find sphinx-build to build man pages.");
rsconf::warn!("If you install it now you need to run `cargo clean` and rebuild, or set $FISH_BUILD_DOCS=1 explicitly.");
return;
}
Err(e) => {
// Another error - permissions wrong etc
panic!("Error starting sphinx-build to build man pages: {:?}", e);
}
Ok(sphinx_build) => sphinx_build,
};
match sphinx_build.wait_with_output() {
Err(err) => {
panic!(
"Error waiting for sphinx-build to build man pages: {:?}",
err
);
}
Ok(out) => {
if !out.stderr.is_empty() {
rsconf::warn!("sphinx-build: {}", String::from_utf8_lossy(&out.stderr));
}
assert_eq!(&String::from_utf8_lossy(&out.stdout), "");
if !out.status.success() {
panic!("sphinx-build failed to build the man pages.");
}
}
}
}

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,16 @@
[package]
name = "fish-gettext-extraction"
edition.workspace = true
rust-version.workspace = true
version = "0.0.0"
repository.workspace = true
description = "proc-macro for extracting strings for gettext translation"
[lib]
proc-macro = true
[dependencies]
proc-macro2.workspace = true
[lints]
workspace = true

View File

@@ -0,0 +1,107 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use std::{ffi::OsString, fs::OpenOptions, io::Write};
fn unescape_multiline_rust_string(s: String) -> String {
if !s.contains('\n') {
return s;
}
let mut unescaped = String::new();
enum State {
Ground,
Escaped,
ContinuationLineLeadingWhitespace,
}
use State::*;
let mut state = Ground;
for c in s.chars() {
match state {
Ground => match c {
'\\' => state = Escaped,
_ => {
unescaped.push(c);
}
},
Escaped => match c {
'\\' => {
unescaped.push('\\');
state = Ground
}
'\n' => state = ContinuationLineLeadingWhitespace,
_ => panic!("Unsupported escape sequence '\\{c}' in message string '{s}'"),
},
ContinuationLineLeadingWhitespace => match c {
' ' | '\t' => (),
_ => {
unescaped.push(c);
state = Ground
}
},
}
}
unescaped
}
fn append_po_entry_to_file(message: &TokenStream, file_name: &OsString) {
let mut file = OpenOptions::new()
.create(true)
.append(true)
.open(file_name)
.unwrap_or_else(|e| panic!("Could not open file {file_name:?}: {e}"));
let message_string = unescape_multiline_rust_string(message.to_string());
if message_string.contains('\n') {
panic!("Gettext strings may not contain unescaped newlines. Unescaped newline found in '{message_string}'")
}
// Crude check for format strings. This might result in false positives.
let format_string_annotation = if message_string.contains('%') {
"#, c-format\n"
} else {
""
};
let po_entry = format!("{format_string_annotation}msgid {message_string}\nmsgstr \"\"\n\n");
file.write_all(po_entry.as_bytes()).unwrap();
}
/// The `message` is passed through unmodified.
/// If `FISH_GETTEXT_EXTRACTION_FILE` is defined in the environment,
/// this file is used to write the message,
/// so that it can then be used for generating gettext PO files.
/// The `message` must be a string literal.
///
/// # Panics
///
/// This macro panics if the `FISH_GETTEXT_EXTRACTION_FILE` variable is set and `message` has an
/// unexpected format.
/// Note that for example `concat!(...)` cannot be passed to this macro, because expansion works
/// outside in, meaning this macro would still see the `concat!` macro invocation, instead of a
/// string literal.
#[proc_macro]
pub fn gettext_extract(message: TokenStream) -> TokenStream {
if let Some(file_path) = std::env::var_os("FISH_GETTEXT_EXTRACTION_FILE") {
let pm2_message = proc_macro2::TokenStream::from(message.clone());
let mut token_trees = pm2_message.into_iter();
let first_token = token_trees
.next()
.expect("gettext_extract got empty token stream. Expected one token.");
if token_trees.next().is_some() {
panic!("Invalid number of tokens passed to gettext_extract. Expected one token, but got more.")
}
if let proc_macro2::TokenTree::Group(group) = first_token {
let mut group_tokens = group.stream().into_iter();
let first_group_token = group_tokens
.next()
.expect("gettext_extract expected one group token but got none.");
if group_tokens.next().is_some() {
panic!("Invalid number of tokens in group passed to gettext_extract. Expected one token, but got more.")
}
if let proc_macro2::TokenTree::Literal(_) = first_group_token {
append_po_entry_to_file(&message, &file_path);
} else {
panic!("Expected literal in gettext_extract, but got: {first_group_token:?}");
}
} else {
panic!("Expected group in gettext_extract, but got: {first_token:?}");
}
}
message
}

View File

@@ -0,0 +1,18 @@
[package]
name = "fish-gettext-maps"
edition.workspace = true
rust-version.workspace = true
version = "0.0.0"
repository.workspace = true
[dependencies]
phf.workspace = true
[build-dependencies]
fish-build-helper.workspace = true
fish-gettext-mo-file-parser.workspace = true
phf_codegen.workspace = true
rsconf.workspace = true
[lints]
workspace = true

Some files were not shown because too many files have changed in this diff Show More