Commit Graph

22985 Commits

Author SHA1 Message Date
Johannes Altmanninger
6d0cd3d9b5 Merge changes to config paths 2026-06-09 22:31:14 +09:00
Johannes Altmanninger
9303e64708 env_init: remove unused argument 2026-06-09 22:31:14 +09:00
Johannes Altmanninger
74ff7d2c6c Make internal path variables read-only
It does not make sense to change these.

If anything, we should make them computed electric variable, so they
change whenever one of $HOME, $XDG_CONFIG_HOME and friends change.

Make them electric variables, purely because that's our only
way of marking variables as read-only.  In future we can add a
EnvVarFlags::READ_ONLY instead.  We'll want this anyway for "set
--read-only".
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
654041895b Stop using universal __fish_initialized to detect first launch
As of 7640e95bd7 (Create user config file/directories only on
first startup again, 2025-12-29) we interpret absence of the
__fish_initialized variable as "this is the first run, so create
~/.config/fish/conf.d etc.".

As reported in #11226, the presence of this universal variable causes
friction to users who track ~/.config/fish/fish_variables in version
control.

Also, __fish_initialized is the only universal variable we create
by default.

Use another way to detect the first run: since we already create
~/.config/fish on every run, assume that a successful mkdir() means
we should also create the subdirectories.

This has false negatives (if the user already created the directory)
and false positives (if the user doesn't want ~/.config/fish to exist)
but at least the latter should not really matter because historically
we always created it, at least for ~/.config/fish/fish_variables.

Alternatively, we could create a file at ~/.cache/fish/first-run-done.
But let's not add more state unless there's a good reason.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
511006833c config.fish template: add back indentation
Fixes 3e7c5ae399 (__fish_config_interactive: make config file
initialization independent of uvars, 2025-11-24).
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
a79ca0cb29 Create ~/.config/fish/{completions,conf.d,functions} with mode 700
Same as ~/config/fish and other directories we create.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
041f601050 make_base_directory: remove dead optimization code
path is never empty. Remove the check. Simplify the remaining code.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
59135087d7 make_base_directory: remove unused function path_get_config_remoteness
I think the remoteness check is handled by fish::fs::LockedFile
nowadays.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
93f483467f make_base_directory: remove extra trailing slash from statfs argument
This was added in d1fd3d5825 (Detect at startup whether config and
data paths are remote, 2021-05-08); I don't understand why
this would be necessary. On my system, statfs("/tmp") and
statfs("/tmp/") both yields f_type=TMPFS_MAGIC.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
a66a7b2b30 fs: correct path formatting in an error message
Convert to WString which uses our PUA escaping trick.
2026-06-09 22:31:14 +09:00
Johannes Altmanninger
45765f4e00 env_init: minor refactoring for initializating user path vars 2026-06-09 22:31:14 +09:00
Johannes Altmanninger
f525b8a7b6 Merge misc fixes 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
c075982f4a env: electric variables to hold their computation-function directly
In addition to the entry in ELECTRIC_VARIABLES, each computed electric
variable has a piece of code in "try_get_computed()".  Makes more
sense to store this directly in the electric variable itself, no?

use consts for the getter functions, so we can reuse the type.
This is a bit weird..
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
8585def79d Merge key decoding fixes 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
bb6774bef8 CHANGELOG improvements 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
66ac8d3e11 electric vars: no general-purpose $history var on background threads
try_get_computed() returns None if the variable is not computed.

That's the case for "$history" on (future) background threads.

This is a weird edge case, because we don't ever return None for any
other electric variable.  This will become especially apparent when
an upcoming commit adds the computing-function to ElectricVar.

Given that the main thread already can't use "$history" from being
used as general purpose variable, there seems to be little harm in
banning it for all of them.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
85908c3950 input decoding: rewrite recursive escape sequence parsing
parse_escape_sequence() can self-recurse once, to parse sequences of
the form "\e\e...", where we attempt to interpret the first byte as
either legacy alt (if the "\e..." suffix decodes to a key), or legacy
escape (if it doesn't).

On "\e\e]11;rgb:ffff/ffff/ffff\e\\", i.e. with the inner sequence
being an OSC which doesn't produce a key event, we (tragically)
stop parsing the sequence and assume legacy escape.

Rewrite the logic to keep parsing whole escape sequences whenever
possible.  Also, don't drop any leading \e even if we later error.
Also, make sure each key event gets the correct "originating sequence".

This makes

	tmux new-session fish -C '
		bind alt-b "echo alt-b"
		bind escape "echo escape"
		bind alt-escape "echo alt-escape"
		sleep 2
	'

output the following after quickly pressing "escape" five times
followed by "b" one time:

	escape
	alt-escape
	escape
	alt-b

which is weird but fine because "alt-escape" is rarely used.

If this proves to be a problem, we could disable translation of "\e\e"
to "alt-escape"?

Closes #12379
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
24109b3fe7 CHANGELOG: fix rst formatting 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
353dc0526f env: move electric variables to impl module
Electric variables are largely an implementation detail, and a following
commit wants to add a circular dependency between the electric var
impl and environment_impl.  Specifically, "ElectricVar" will know
about "EnvScopedImpl". Move both impls into a common impl module,
to make this dependency less surprising.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
19535d9933 input decoding: minimize logic 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
a98000cb36 Add all terminal commands to reader log 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
3b29d62daa env: reformat electric var table 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
53edd49213 input decoding: sequence parsing to return query events too
A following commit wants to make "on_byte_read()" potentially return
multiple CharEvent values, in case there is a legacy escape.

Today "parse_csi()" and friends simply insert into the input queue.
This makes it hard to get the ordering right when we return multiple
events.

Change the parsing functions to return their result rather than
queuing directly.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
b541931b6e docs: replace mention of /usr/share/fish/completions
This directory is no longer since 0fafff2c89 (CMake: stop installing
embedded files, 2026-05-08). Instead of telling users to see "status
list-files", refer them to the source directly.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
974aa160f3 fish_update_completions: pass explicit directory argument
Gets rid of another use of XDG_CACHE_HOME; this gets us closer to
a single source of truth. Not super important right now, but will
be helpful if we allow users to override XDG_CACHE_HOME in future.
I guess we could also remove it from create_manpage_completions.py,
that's unnecessary breakage but probably fine since this is not
public-facing.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
0c3283cbed input decoding: make read_sequence_byte overridable
A following commit wants to inject mock input bytes in unit tests.
Allow this in a quick-and-dirty way by making the input-byte-yielding an
overridable trait method again. Unfortunately this needs to be in the
shared trait; we can't specialize a private trait since specialization
is not supported in stable Rust.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
070aa01472 docs fish_delta: reword 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
ac27876252 share: reuse __fish_make_cache_dir
Our apropos wrapper uses "getconf DARWIN_USER_CACHE_DIR"; we should
either use that everywhere or nowhere.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
943300c572 input decoding: fix parsing of CSI/SS3 sequences prefixed with legacy alt
Commit af137e5e96 (scrollback-push to query for indn/cuu via XTGETTCAP,
2025-01-05) extracted a bool variable

	recursive_invocation = buffer.len() == 2

It replaced another instance of "buffer.len() == 2" with that variable,
but that's wrong because buffer has grown since then (so it's either
2 or 3).  Flip the bool to fix this.

While at it, tighten an assertion.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
52fabc3e31 wildcard: make symlink check easier to read 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
4dc15113d8 Don't set $__fish_config_dir to empty if inaccessible
Since commit ea998b03f2 (First stab at directory transition. Test with
care..., 2006-10-19), "path_get_config()"
returns an empty string (now Option) if "~/.config/fish" is inaccessible.

This is okay in C++/Rust source code, because
it makes it very obvious to the user of "path_get_config()"
that they probably don't want to try to access these files.

However commit 3855c2217f (Remove scripted XDG_CONFIG_HOME uses,
2018-12-14) made us compute $__fish_config_dir like this:

	wcstring user_config_dir;
	path_get_config(user_config_dir);
	env_set_one(FISH_CONFIG_DIR, ENV_GLOBAL, user_config_dir);

with the (inadvertent?) change that we set $__fish_config_dir to the
empty string if the directory is inaccessible.

This situation causes us to stat weird paths like "/functions"
"/completions/", "/conf.d".  This is usually inconsequential because
these paths usually don't exist, but still, we shouldn't do this.

Fix this by setting the variables to the actual value we tried,
reverting the inadvertent behavior change of 3855c2217f.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
800d8a5728 input decoding: use byte literal
We use b"\x1b" elsewhere in this file so be consistent with that.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
86f92cb1a2 Remove crate-wide suppression of non_camel_case_types lint 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
2f236a71be env_init: inline variables
These are only used once, so reduce their scope.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
693169a633 input decoding: add log messages on invalid CSI format 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
59e68e23d5 Idiomatic type name for parsed options
Each builtin is inside its own module, so there is no need to repeat
the builtin name.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
b48b5025d5 path: inline default_vars_path_directory() 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
0033854858 Apply clippy::ref-option lint 2026-06-09 22:24:07 +09:00
Clément Bœsch
6fe05fa772 fix(git-completion): add missing completion for git rebase --show-current-patch and --quit
Closes #12805
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
a31768bf9e history: remove code for migrating from ~/.config/fish/fish_history
Commit 2971887bbd (Access fish_history from $XDG_DATA_HOME, 2015-09-16)
changed the history file path to ~/.local/share/fish/fish_history.

Migration is done by commit b13f0701a4 (Migrate fish_history from
config to data dir, 2015-09-18).

This should no longer be needed in practice. Remove it.

FWIW, we used a similar-length grace period (10 years) when dropping
support for history file format version 1 in 77aeb6a2a8 (Port
execution, 2023-10-08).
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
f2e2c622bb input/input_common: reorganize modules
While at it, rename "input mapping" to "binding", to be consistent
with builtin bind. The "input" bit is already implied by the module
hierarchy.

Also, merge definitions of "enum ReadlineCmd" and
"INPUT_FUNCTION_METADATA" using a macro.

Review with

	git show --color-moved=zebra --color-moved-ws=allow-indentation-change
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
b6e5e5196d path_emit_config_directory_messages: also print error about ~/.cache 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
a580d82407 Stop exposing internal module names when we can use re-exports
Types like Environment are sometimes imported using their FQN and
sometimes via their re-export in the parent module; it seems better
to have one canonical name. I think we usually use the re-exports
already, so use them always.

It't not as trivial to enforce this in child modules (such as "mod
tests" which) but that's not a big loss.

While at it, make some other consistency improvements to imports.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
6efb5c1a61 path_emit_config_directory_messages: remove code clone 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
31a348e70d wutil: remove unused function 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
e861c7f923 path_emit_config_directory_messages: fix condition for inaccessible $__fish_config_dir
Commit 77471c500e (path: use `std::io::Error` instead of raw ints,
2026-01-21) inadvertently prints the "Unable to locate config directory"
error when the *data* dir is inaccessible, rather than when the *config*
dir is inaccessible.

Fix that. While at it, rename variables to avoid this issue.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
c4aa726111 wutil: place re-exports before imports
Public items are more important to the reader, so put them first
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
616ff5c5e9 config.fish: lazy load job control functions
These don't really belong in config.fish.  Put them in function files,
like similar wrappers.  The redundancy is ugly but if it's a problem
we can use code generation to fix that.
2026-06-09 22:24:07 +09:00
Johannes Altmanninger
499297fb03 input: remove unused code 2026-06-09 22:24:07 +09:00
Johannes Altmanninger
336df7793a Comment about handing over input data to reader on init 2026-06-09 22:24:07 +09:00