fork/fish-shell

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

Johannes AltmanningerMerge changes to config paths6d0cd3d9b

master
6.0 KiB165 linesraw
1# localization: tier1
2
3# This file does some internal fish setup.
4# It is not recommended to remove or edit it.
5
6set -g IFS \n\ \t
7set -qg __fish_added_user_paths
8or set -g __fish_added_user_paths
9
10#
11# Set default search paths for completions and shellscript functions
12# unless they already exist
13#
14
15# Grab extra directories (as specified by the build process, usually for
16# third-party packages to ship completions &c.
17set -l __extra_completionsdir
18set -l __extra_functionsdir
19set -l __extra_confdir
20status get-file __fish_build_paths.fish | source
21
22# Compute the directories for vendor configuration.  We want to include
23# all of XDG_DATA_DIRS, as well as the __extra_* dirs defined above.
24set -l xdg_data_dirs /usr/local/share/fish /usr/share/fish
25if test -n "$XDG_DATA_DIRS"
26    set --path xdg_data_dirs $XDG_DATA_DIRS
27    set xdg_data_dirs (string replace -r '([^/])/$' '$1' -- $xdg_data_dirs)/fish
28end
29
30set -g __fish_vendor_completionsdirs
31set -g __fish_vendor_functionsdirs
32set -g __fish_vendor_confdirs
33# Don't load vendor directories when running unit tests
34if not set -q FISH_UNIT_TESTS_RUNNING
35    set __fish_vendor_completionsdirs $__fish_user_data_dir/vendor_completions.d $xdg_data_dirs/vendor_completions.d
36    set __fish_vendor_functionsdirs $__fish_user_data_dir/vendor_functions.d $xdg_data_dirs/vendor_functions.d
37    set __fish_vendor_confdirs $__fish_user_data_dir/vendor_conf.d $xdg_data_dirs/vendor_conf.d
38
39    # Ensure that extra directories are always included.
40    if not contains -- $__extra_completionsdir $__fish_vendor_completionsdirs
41        set -a __fish_vendor_completionsdirs $__extra_completionsdir
42    end
43    if not contains -- $__extra_functionsdir $__fish_vendor_functionsdirs
44        set -a __fish_vendor_functionsdirs $__extra_functionsdir
45    end
46    if not contains -- $__extra_confdir $__fish_vendor_confdirs
47        set -a __fish_vendor_confdirs $__extra_confdir
48    end
49end
50
51# Set up function and completion paths. Make sure that the fish
52# default functions/completions are included in the respective path.
53
54if not set -q fish_function_path
55    set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $__fish_vendor_functionsdirs
56end
57
58if not set -q fish_complete_path
59    set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $__fish_vendor_completionsdirs
60    set -a fish_complete_path $__fish_cache_dir/generated_completions
61end
62
63# Add a handler for when fish_user_path changes, so we can apply the same changes to PATH
64function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
65    # Deduplicate $fish_user_paths
66    # This should help with people appending to it in config.fish
67    set -l new_user_path
68    for path in (string split : -- $fish_user_paths)
69        if not contains -- $path $new_user_path
70            set -a new_user_path $path
71        end
72    end
73
74    if test (count $new_user_path) -lt (count $fish_user_paths)
75        # This will end up calling us again, so we return
76        set fish_user_paths $new_user_path
77        return
78    end
79
80    set -l local_path $PATH
81
82    for x in $__fish_added_user_paths
83        set -l idx (contains --index -- $x $local_path)
84        and set -e local_path[$idx]
85    end
86
87    set -g __fish_added_user_paths
88    if set -q fish_user_paths
89        # Explicitly split on ":" because $fish_user_paths might not be a path variable,
90        # but $PATH definitely is.
91        for x in (string split ":" -- $fish_user_paths[-1..1])
92            if set -l idx (contains --index -- $x $local_path)
93                set -e local_path[$idx]
94            else
95                set -ga __fish_added_user_paths $x
96            end
97            set -p local_path $x
98        end
99    end
100
101    set -xg PATH $local_path
102end
103
104#
105# Launch debugger on SIGTRAP
106#
107function fish_sigtrap_handler --on-signal TRAP --no-scope-shadowing --description "TRAP handler: debug prompt"
108    breakpoint
109end
110
111#
112# When a prompt is first displayed, make sure that interactive
113# mode-specific initializations have been performed.
114# This includes a `read` prompt, hence the fish_read event.
115# This handler removes itself after it is first called.
116#
117function __fish_on_interactive --on-event fish_prompt --on-event fish_read
118    # We erase this *first* so it can't be called again,
119    # e.g. if fish_greeting calls "read".
120    functions -e __fish_on_interactive
121    __fish_config_interactive
122end
123
124# Set the locale if it isn't explicitly set. Allowing the lack of locale env vars to imply the
125# C/POSIX locale causes too many problems. Do this before reading the snippets because they might be
126# in UTF-8 (with non-ASCII characters).
127not set -q LANG # (fast path - no need to load the file if we have $LANG)
128and __fish_set_locale
129
130#
131# Some things should only be done for login terminals
132# This used to be in etc/config.fish - keep it here to keep the semantics
133#
134if status is-login && command -sq /usr/libexec/path_helper
135    __fish_macos_set_env PATH /etc/paths '/etc/paths.d'
136    if test -n "$MANPATH"
137        __fish_macos_set_env MANPATH /etc/manpaths '/etc/manpaths.d'
138    end
139    functions -e __fish_macos_set_env
140end
141
142# Invoke this here to apply the current value of fish_user_path after
143# PATH is possibly set above.
144__fish_reconstruct_path
145
146if status is-interactive
147    __fish_theme_migrate
148end
149if status is-interactive || set -qgx __fish_force_load_default_theme
150    fish_config theme choose default --no-override
151end
152
153# As last part of initialization, source the conf directories.
154# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename".
155set -l sourcelist
156for file in $__fish_config_dir/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish $__fish_vendor_confdirs/*.fish
157    set -l basename (string replace -r '^.*/' '' -- $file)
158    contains -- $basename $sourcelist
159    and continue
160    set sourcelist $sourcelist $basename
161    # Also skip non-files or unreadable files.
162    # This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd).
163    test -f $file -a -r $file
164    and source $file
165end