Create user config file/directories only on first startup again

Not being able to delete these for good (if unused) seems to be
a nuisance.  Let's go back to storing universal __fish_initialized
also on fresh installations, which I guess is a small price to to
avoid recreating these files.

Closes #12230
This commit is contained in:
Johannes Altmanninger
2025-12-29 10:24:23 +01:00
parent 767115a93d
commit 7640e95bd7
7 changed files with 35 additions and 23 deletions

View File

@@ -13,7 +13,7 @@ fish 4.3.0 (released December 28, 2025)
Deprecations and removed features
---------------------------------
- fish no longer sets :ref:`universal variables <variables-universal>` by default, making the configuration easier to understand.
- fish no longer sets user-facing :ref:`universal variables <variables-universal>` by default, making the configuration easier to understand.
Specifically, the ``fish_color_*``, ``fish_pager_color_*`` and ``fish_key_bindings`` variables are now set in the global scope by default.
After upgrading to 4.3.0, fish will (once and never again) migrate these universals to globals set at startup in the
``~/.config/fish/conf.d/fish_frozen_theme.fish`` and

View File

@@ -205,7 +205,7 @@ if command -q kill
end
if status is-interactive
__fish_theme_migrate
__fish_migrate
end
fish_config theme choose default --no-override

View File

@@ -6,15 +6,6 @@
#
function __fish_config_interactive -d "Initializations that should be performed when entering interactive mode"
functions -e __fish_config_interactive
# Create empty configuration directores if they do not already exist
test -e $__fish_config_dir/completions/ -a -e $__fish_config_dir/conf.d/ -a -e $__fish_config_dir/functions/ ||
mkdir -p $__fish_config_dir/{completions, conf.d, functions}
# Create config.fish with some boilerplate if it does not exist
test -e $__fish_config_dir/config.fish || echo "\
if status is-interactive
# Commands to run in interactive sessions can go here
end" >$__fish_config_dir/config.fish
set -g __fish_active_key_bindings

View File

@@ -1,9 +1,27 @@
# localization: skip(private)
function __fish_theme_migrate
functions -e __fish_theme_migrate
function __fish_migrate
functions -e __fish_migrate
set -l migration_version 4300
# Maybe migrate.
if not set -q __fish_initialized || test $__fish_initialized -ge 4300
if set -q __fish_initialized && test $__fish_initialized -ge $migration_version
return
end
# Create empty configuration directores if they do not already exist
test -e $__fish_config_dir/completions/ -a -e $__fish_config_dir/conf.d/ -a -e $__fish_config_dir/functions/ ||
mkdir -p $__fish_config_dir/{completions, conf.d, functions}
# Create config.fish with some boilerplate if it does not exist
test -e $__fish_config_dir/config.fish || echo "\
if status is-interactive
# Commands to run in interactive sessions can go here
end" >$__fish_config_dir/config.fish
set -l mark_migration_done set -U __fish_initialized $migration_version
if not set -q __fish_initialized
$mark_migration_done
return
end
@@ -22,7 +40,7 @@ function __fish_theme_migrate
for varname in $theme_uvars
set -a theme_data "$(string escape -- $varname $$varname | string join " ")"
end
__fish_theme_freeze __fish_theme_migrate $theme_data
__fish_theme_freeze __fish_migrate $theme_data
set msg_suffix " by default."\n" Migrated them to global variables set in $(set_color --underline)$(
__fish_unexpand_tilde $__fish_config_dir/conf.d/fish_frozen_theme.fish
)$(set_color normal)"
@@ -35,6 +53,7 @@ function __fish_theme_migrate
set -l relative_filename conf.d/fish_frozen_key_bindings.fish
set -l filename $__fish_config_dir/$relative_filename
__fish_backup_config_files $relative_filename
mkdir -p -- (path dirname -- $filename)
echo >$filename "\
# This file was created by fish when upgrading to version 4.3, to migrate
# the 'fish_key_bindings' variable from its old default scope (universal)
@@ -62,7 +81,7 @@ set --erase --universal fish_key_bindings"
(set_color normal))
source $__fish_config_dir/$relative_filename
end
set -U __fish_initialized 4300
$mark_migration_done
if $removing_uvars
echo -s (set_color --bold) 'fish:' (set_color normal) " upgraded to version 4.3:"
string join \n -- $msg

View File

@@ -9,8 +9,9 @@ function __fish_theme_freeze
__fish_data_with_file help_sections $(command -v grep) -Fxq $help_section
or echo "fish: internal error: missing help section '$help_section'"
mkdir -p -- (path dirname -- $__fish_config_dir/conf.d)
printf >$__fish_config_dir/$relative_path %s\n \
$(test $data_source = __fish_theme_migrate &&
$(test $data_source = __fish_migrate &&
echo "\
# This file was created by fish when upgrading to version 4.3, to migrate
# theme variables from universal to global scope.") \
@@ -21,7 +22,7 @@ function __fish_theme_freeze
# or
# man fish-interactive | less +/^SYNTAX.HIGHLIGHTING
# for appropriate commands to add to ~/.config/fish/config.fish instead." \
$(test $data_source = __fish_theme_migrate &&
$(test $data_source = __fish_migrate &&
echo '# See also the release notes for fish 4.3.0 (run `help relnotes`).') \
"" \
'set --global '$theme_data

View File

@@ -30,7 +30,7 @@ echo no default universal variables
# CHECK: ok
provoke-migration
$fish -c __fish_theme_migrate
$fish -c __fish_migrate
# CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{upgraded.*}}
# CHECK: {{.*Color.*no.longer.*universal.*}}
# CHECK: Migrated {{.*}} {{\S*}}/xdg_config_home/fish/conf.d/fish_frozen_theme.fish{{\x1b\[m}}
@@ -49,7 +49,7 @@ echo no default universal variables
# But the migration is only done once, in case the user really wants these as universals.
set -U fish_color_autosuggestion 8e8e8e
$fish -c '
__fish_theme_migrate
__fish_migrate
set -eg fish_color_autosuggestion
echo $fish_color_autosuggestion
# CHECK: 8e8e8e
@@ -63,7 +63,7 @@ echo no default universal variables
echo yes | fish_config theme save default
fake-old-uvars
provoke-migration
$fish -c __fish_theme_migrate
$fish -c __fish_migrate
# CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{upgraded.*}}
# CHECK: {{.*Color.*no.longer.*universal.*}}
# CHECK: {{.*restart.*}}
@@ -80,7 +80,7 @@ echo no default universal variables
$fish -c '
set -g fish_color_autosuggestion red
set -g fish_color_command green --theme=default
__fish_theme_migrate
__fish_migrate
for cmd in "" "__fish_color_theme=unknown __fish_apply_theme"
eval $cmd
echo fish_color_autosuggestion $fish_color_autosuggestion
@@ -98,7 +98,7 @@ echo no default universal variables
{
set -U fish_key_bindings fish_vi_key_bindings
provoke-migration
$fish -c __fish_theme_migrate
$fish -c __fish_migrate
# CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{upgraded.*}}
# CHECK: {{.*fish_key_bindings.*no.longer.*universal.*}}
# CHECK: Migrated {{.*}} {{\S*}}/xdg_config_home/fish/conf.d/fish_frozen_key_bindings.fish{{\x1b\[m}}

View File

@@ -1,4 +1,5 @@
#RUN: fish=%fish %fish %s
__fish_migrate # make sure the interactive fish doesn't need mkdir in PATH
set -g PATH
$fish -c "nonexistent-command-1234 banana rama"
#CHECKERR: fish: Unknown command: nonexistent-command-1234