fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge changes to config paths6d0cd3d9b

master
6.4 KiB150 linesraw
1# localization: skip(private)
2function __fish_theme_migrate
3    functions -e __fish_theme_migrate
4
5    set -l migration_version 4300
6
7    # Maybe migrate.
8    if not set -q __fish_initialized || test $__fish_initialized -ge $migration_version
9        return
10    end
11
12    set -l removing_uvars false
13    set -l msg
14    # Copy legacy uvars to globals.
15    set -l theme_uvars (__fish_theme_variables --universal)
16    if set -q theme_uvars[1]
17        set removing_uvars true
18        set -l msg_suffix .
19        if not __fish_config_theme_uvars_subset_of_historical_default $theme_uvars
20            for varname in $theme_uvars
21                set -g $varname $$varname
22            end
23            set -l theme_data
24            for varname in $theme_uvars
25                set -a theme_data "$(string escape -- $varname $$varname | string join " ")"
26            end
27            __fish_theme_freeze __fish_theme_migrate $theme_data
28            set msg_suffix " by default."\n"  Migrated them to global variables set in $(set_color --underline)$(
29                    __fish_unexpand_tilde $__fish_config_dir/conf.d/fish_frozen_theme.fish
30                )$(set_color --reset)"
31        end
32        set -a msg "* Color variables are no longer set in universal scope$msg_suffix"
33        set -a msg '  To restore syntax highlighting in other fish sessions, please restart them.'
34    end
35    if set -Uq fish_key_bindings
36        set removing_uvars true
37        set -l relative_filename conf.d/fish_frozen_key_bindings.fish
38        set -l filename $__fish_config_dir/$relative_filename
39        __fish_backup_config_files $relative_filename
40        mkdir -p -- (path dirname -- $filename)
41        echo >$filename "\
42# This file was created by fish when upgrading to version >= 4.3, to migrate
43# the 'fish_key_bindings' variable from its old default scope (universal)
44# to its new default scope (global).  We recommend you delete this file
45# and configure key bindings in ~/.config/fish/config.fish if needed.
46
47$(
48    # No need to freeze the default value.
49    test "$fish_key_bindings" = fish_default_key_bindings
50    # Nor if the user has shadowed our previous uvar.
51    or set -qg fish_key_bindings
52    and echo "# "
53)set --global fish_key_bindings $fish_key_bindings
54
55# Prior to version 4.3, fish shipped an event handler that runs
56# `set --universal fish_key_bindings fish_default_key_bindings`
57# whenever the fish_key_bindings variable is erased.
58# This means that as long as any fish < 4.3 is still running on this system,
59# we cannot complete the migration.
60# As a workaround, erase the universal variable at every shell startup.
61set --erase --universal fish_key_bindings"
62        set -a msg '* The fish_key_bindings variable is no longer set in universal scope by default.'
63        set -a msg (echo -s "  Migrated it to a global variable set in  " \
64            "$(set_color --underline)$(__fish_unexpand_tilde $filename)" \
65            (set_color --reset))
66        source $__fish_config_dir/$relative_filename
67    end
68    # TODO In a few years, stop setting it.
69    set -U __fish_initialized $migration_version
70    if $removing_uvars
71        echo -s (set_color --bold) 'fish:' (set_color --reset) " upgraded to version >= 4.3.0:"
72        string join \n -- $msg
73        echo 'See also the release notes for 4.3.0 (type `help relnotes`).'
74        set -Ue fish_key_bindings $theme_uvars
75        set -l sh (__fish_posix_shell)
76        eval "$sh -c 'sleep 7 # Please read above notice about universal variables' </dev/null &>/dev/null &"
77    end
78end
79
80function __fish_config_theme_matches --no-scope-shadowing
81    set -l varname $argv[1]
82    set -l possible_values $argv[2..]
83    if not set -q possible_values[1]
84        set possible_values normal "" --reset
85    end
86    set -a checked_varnames $varname
87    not set -q $varname
88    or contains -- "$$varname" $possible_values
89end
90function __fish_config_theme_uvars_subset_of_historical_default
91    set -l checked_varnames
92    set -l matches __fish_config_theme_matches
93    $matches fish_color_keyword "$fish_color_command"
94    and $matches fish_color_option "$fish_color_param"
95    and $matches fish_color_autosuggestion brblack "555 brblack"
96    and $matches fish_color_cancel -r
97    and $matches fish_color_command normal blue --reset
98    and $matches fish_color_comment red
99    and $matches fish_color_cwd green
100    and $matches fish_color_cwd_root red
101    and $matches fish_color_end green
102    and $matches fish_color_error brred
103    and $matches fish_color_escape brcyan
104    and $matches fish_color_history_current --bold
105    and $matches fish_color_host
106    and $matches fish_color_host_remote yellow
107    and $matches fish_color_normal
108    and $matches fish_color_operator brcyan
109    and $matches fish_color_param cyan
110    and $matches fish_color_quote yellow
111    and $matches fish_color_redirection "cyan --bold"
112    and $matches fish_color_search_match \
113        "--background=111" \
114        "--background=brblack" \
115        "bryellow --background=brblack" \
116        "bryellow --background=brblack --bold" \
117        "white --background=brblack" \
118        "white --background=brblack --bold"
119    and $matches fish_color_selection \
120        "white --background=brblack --bold" \
121        "white --bold --background=brblack"
122    and $matches fish_color_status red
123    and $matches fish_color_user brgreen
124    and $matches fish_color_valid_path --underline
125    and $matches fish_color_background
126    and $matches fish_pager_color_background
127    and $matches fish_pager_color_completion
128    and $matches fish_pager_color_description "B3A06D yellow -i" "yellow -i" "yellow --italics"
129    and $matches fish_pager_color_prefix \
130        "normal --bold --underline" \
131        "cyan --bold --underline" \
132        "--bold --underline"
133    and $matches fish_pager_color_progress \
134        "brwhite --background=cyan" \
135        "brwhite --background=cyan --bold"
136    and $matches fish_pager_color_secondary_background
137    and $matches fish_pager_color_secondary_completion
138    and $matches fish_pager_color_secondary_description
139    and $matches fish_pager_color_secondary_prefix
140    and $matches fish_pager_color_selected_background -r
141    and $matches fish_pager_color_selected_completion
142    and $matches fish_pager_color_selected_description
143    and $matches fish_pager_color_selected_prefix
144    and $matches fish_color_match --background=brblue
145    and for uvar in $argv
146        contains $uvar $checked_varnames
147        or test -z "$$uvar"
148        or return
149    end
150end