From 74af4f10dede26ed8e635b44883fa38e189dfc75 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 25 Dec 2025 08:38:13 +0100 Subject: [PATCH] uvar migration: tell users to restart running sessions Users who run the default theme are silently migrated to global variables. Universal color variables are deleted, leaving existing sessions uncolored. Tell the user to restart them, and make some other improvements; now it looks like: fish: upgraded to version 4.3: * Color variables are no longer set in universal scope. To restore syntax highlighting in other fish sessions, please restart them. * The fish_key_bindings variable is no longer set in universal scope by default. Migrated it to a global variable set in ~/.config/fish/conf.d/fish_frozen_key_bindings.fish Same for users who do not use the default theme (who already got a message before this change). For them, the first bullet point looks like this: [...] * Color variables are no longer set in universal scope by default. Migrated them to global variables set in ~/.config/fish/conf.d/fish_frozen_theme.fish To restore syntax highlighting in other fish sessions, please restart them. [...] Closes #12161 --- share/functions/__fish_theme_freeze.fish | 8 ++++--- share/functions/__fish_theme_migrate.fish | 26 ++++++++++++++--------- tests/checks/__fish_theme_migrate.fish | 25 ++++++++++++++++------ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/share/functions/__fish_theme_freeze.fish b/share/functions/__fish_theme_freeze.fish index 3bafda209..4b6b8355c 100644 --- a/share/functions/__fish_theme_freeze.fish +++ b/share/functions/__fish_theme_freeze.fish @@ -11,16 +11,18 @@ function __fish_theme_freeze printf >$__fish_config_dir/$relative_path %s\n \ $(test $data_source = __fish_theme_migrate && - echo '# This file was created by fish to migrate the default universal variables.') \ + echo "\ +# This file was created by fish when upgrading to version 4.3, to migrate +# theme variables from universal to global scope.") \ "\ -# Don't edit this, as it will be written by the web-config tool (`fish_config`). +# Don't edit this file, as it will be written by the web-config tool (`fish_config`). # To customize your theme, delete this file and see # help $help_section # or # man fish-interactive | less +/^SYNTAX.HIGHLIGHTING # for appropriate commands to add to ~/.config/fish/config.fish instead." \ $(test $data_source = __fish_theme_migrate && - echo '# See also the release notes for fish 4.3.0 (`help relnotes`).') \ + echo '# See also the release notes for fish 4.3.0 (run `help relnotes`).') \ "" \ 'set --global '$theme_data end diff --git a/share/functions/__fish_theme_migrate.fish b/share/functions/__fish_theme_migrate.fish index b900c0da1..a51eb4454 100644 --- a/share/functions/__fish_theme_migrate.fish +++ b/share/functions/__fish_theme_migrate.fish @@ -8,9 +8,11 @@ function __fish_theme_migrate end set -l removing_uvars false + set -l msg # Copy legacy uvars to globals. if set -l theme_uvars (__fish_theme_variables --universal) set removing_uvars true + set -l msg_suffix . if not __fish_config_theme_uvars_subset_of_historical_default $theme_uvars for varname in $theme_uvars set -g $varname $$varname @@ -20,11 +22,12 @@ function __fish_theme_migrate set -a theme_data "$(string escape -- $varname $$varname | string join " ")" end __fish_theme_freeze __fish_theme_migrate $theme_data - echo -s (set_color --bold) 'fish:' (set_color normal)' color variables are no longer set in universal scope by default.' - echo "Migrated them to global variables set in $(set_color --underline)$( + 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)" end + set -a msg "* Color variables are no longer set in universal scope$msg_suffix" + set -a msg ' To restore syntax highlighting in other fish sessions, please restart them.' end if set -Uq fish_key_bindings set removing_uvars true @@ -32,10 +35,10 @@ function __fish_theme_migrate set -l filename $__fish_config_dir/$relative_filename __fish_backup_config_files $relative_filename echo >$filename "\ -# This file was created by fish to migrate the 'fish_key_bindings' variable -# from its old default scope (universal) to its new default scope (global). -# It is recommended you delete this file and configure key bindings however -# you prefer. +# 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) +# to its new default scope (global). We recommend you delete this file +# and configure key bindings in ~/.config/fish/config.fish if needed. $( # No need to freeze the default value. @@ -50,16 +53,19 @@ $( # whenever the fish_key_bindings variable is erased. # This means that as long as any fish < 4.3 is still running on this system, # we cannot complete the migration. -# As a workaround, we erase the universal variable at every shell startup. +# As a workaround, erase the universal variable at every shell startup. set --erase --universal fish_key_bindings" - echo -s (set_color --bold) 'fish:' (set_color normal) ' the fish_key_bindings variable is no longer set in universal scope by default.' - echo -s "Migrated it to a global variable set in " \ + set -a msg '* The fish_key_bindings variable is no longer set in universal scope by default.' + set -a msg (echo -s " Migrated it to a global variable set in " \ "$(set_color --underline)$(__fish_unexpand_tilde $filename)" \ - (set_color normal) + (set_color normal)) source $__fish_config_dir/$relative_filename end set -U __fish_initialized 4300 if $removing_uvars + echo -s (set_color --bold) 'fish:' (set_color normal) " upgraded to version 4.3:" + string join \n -- $msg + echo 'See also the release notes (type `help relnotes`).' set -Ue fish_key_bindings $theme_uvars set -l sh (__fish_posix_shell) eval "$sh -c 'sleep 7 # Please read above notice about universal variables' &" diff --git a/tests/checks/__fish_theme_migrate.fish b/tests/checks/__fish_theme_migrate.fish index 43a9146e5..93161bba8 100644 --- a/tests/checks/__fish_theme_migrate.fish +++ b/tests/checks/__fish_theme_migrate.fish @@ -31,10 +31,13 @@ echo no default universal variables provoke-migration $fish -c __fish_theme_migrate - # CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{.*}} + # 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}} - # CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{.*}} + # CHECK: {{.*restart.*}} + # CHECK: {{.*fish_key_bindings.*no.longer.*universal.*}} # CHECK: Migrated {{.*}} {{\S*}}/xdg_config_home/fish/conf.d/fish_frozen_key_bindings.fish{{\x1b\[m}} + # CHECK: {{.*help relnotes.*}} grep -v '^#' $__fish_config_dir/conf.d/fish_frozen_theme.fish | grep . | head -3 # CHECK: set --global fish_color_autosuggestion 7f7f7f # CHECK: set --global fish_color_cancel ffffff --background=000000 @@ -54,13 +57,17 @@ echo no default universal variables set -Ue fish_color_autosuggestion } -# If existing universal variables match old defaults exactly (common case), pretend they don't -# exist at all (silently delete them). +# If existing universal colors match old defaults exactly (common case), don't migrate but +# delete them. { echo yes | fish_config theme save default --color-theme=unknown fake-old-uvars provoke-migration $fish -c __fish_theme_migrate + # CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{upgraded.*}} + # CHECK: {{.*Color.*no.longer.*universal.*}} + # CHECK: {{.*restart.*}} + # CHECK: {{.*help relnotes.*}} not path is $__fish_config_dir/conf.d/fish_frozen_theme.fish and echo ok # CHECK: ok @@ -86,14 +93,18 @@ echo no default universal variables ' } -# If existing universal variables match old defaults exactly (common case), -# don't migrate them and silently delete them). +# If existing universal key bindings match old defaults exactly (common case), don't migrate +# but delete them). { set -U fish_key_bindings fish_vi_key_bindings provoke-migration $fish -c __fish_theme_migrate - # CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{.*}}. + # CHECK: {{\x1b\[1m}}fish:{{\x1b\[m}} {{upgraded.*}} + # CHECK: {{.*Color.*no.longer.*universal.*}} + # CHECK: {{.*restart.*}} + # CHECK: {{.*fish_key_bindings.*no.longer.*universal.*}} # CHECK: Migrated {{.*}} {{\S*}}/xdg_config_home/fish/conf.d/fish_frozen_key_bindings.fish{{\x1b\[m}} + # CHECK: {{.*help relnotes.*}} path is $__fish_config_dir/conf.d/fish_frozen_key_bindings.fish and echo ok # CHECK: ok