Add $__fish_config_dir variable

Contains the path to the user config.fish (e.g. ~/.config/fish)
without having to do the `set -q XDG_CONFIG_HOME` dance.

See #5270.
This commit is contained in:
Fabian Homborg 2018-10-21 15:42:25 +02:00
parent 162af88c9a
commit 6c988abe28
3 changed files with 9 additions and 14 deletions

View file

@ -1250,14 +1250,14 @@ Configuration files are evaluated in the following order:
- Configuration shipped with fish, which should not be edited, in `$__fish_data_dir/config.fish` (usually `/usr/share/fish/config.fish`).
- System-wide configuration files, where administrators can include initialization that should be run for all users on the system - similar to `/etc/profile` for POSIX-style shells - in `$__fish_sysconf_dir` (usually `/etc/fish/config.fish`);
- Configuration snippets in files ending in `.fish`, in the directories:
- `$XDG_CONFIG_HOME/fish/conf.d` (by default, `~/.config/fish/conf.d/`)
- `$__fish_config_dir/conf.d` (by default, `~/.config/fish/conf.d/`)
- `$__fish_sysconf_dir/conf.d` (by default, `/etc/fish/conf.d`)
- `/usr/share/fish/vendor_conf.d` (set at compile time; by default, `$__fish_data_dir/conf.d`)
If there are multiple files with the same name in these directories, only the first will be executed.
They are executed in order of their filename, sorted (like globs) in a natural order (i.e. "01" sorts before "2").
- User initialization, usually in `~/.config/fish/config.fish` (controlled by the `XDG_CONFIG_HOME` environment variable).
- User initialization, usually in `~/.config/fish/config.fish` (controlled by the `XDG_CONFIG_HOME` environment variable, and accessible as `$__fish_config_dir`).
These paths are controlled by parameters set at build, install, or run time, and may vary from the defaults listed above.

View file

@ -62,10 +62,10 @@ end
# unless they already exist
#
set -l configdir ~/.config
set -g __fish_config_dir ~/.config
if set -q XDG_CONFIG_HOME
set configdir $XDG_CONFIG_HOME
set __fish_config_dir $XDG_CONFIG_HOME
end
set -l userdatadir ~/.local/share
@ -90,7 +90,7 @@ end
# default functions/completions are included in the respective path.
if not set -q fish_function_path
set fish_function_path $configdir/fish/functions $__fish_sysconf_dir/functions $__extra_functionsdir $__fish_data_dir/functions
set fish_function_path $__fish_config_dir/functions $__fish_sysconf_dir/functions $__extra_functionsdir $__fish_data_dir/functions
end
if not contains -- $__fish_data_dir/functions $fish_function_path
@ -98,7 +98,7 @@ if not contains -- $__fish_data_dir/functions $fish_function_path
end
if not set -q fish_complete_path
set fish_complete_path $configdir/fish/completions $__fish_sysconf_dir/completions $__extra_completionsdir $__fish_data_dir/completions $userdatadir/fish/generated_completions
set fish_complete_path $__fish_config_dir/completions $__fish_sysconf_dir/completions $__extra_completionsdir $__fish_data_dir/completions $userdatadir/fish/generated_completions
end
if not contains -- $__fish_data_dir/completions $fish_complete_path
@ -294,7 +294,7 @@ end
# As last part of initialization, source the conf directories.
# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename".
set -l sourcelist
for file in $configdir/fish/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish $__extra_confdir/*.fish
for file in $__fish_config_dir/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish $__extra_confdir/*.fish
set -l basename (string replace -r '^.*/' '' -- $file)
contains -- $basename $sourcelist
and continue

View file

@ -8,12 +8,7 @@ function funcsave --description "Save the current definition of all specified fu
return 0
end
set -l configdir ~/.config
if set -q XDG_CONFIG_HOME
set configdir $XDG_CONFIG_HOME
end
if not mkdir -p $configdir/fish/functions
if not mkdir -p $__fish_config_dir/functions
printf (_ "%s: Could not create configuration directory\n") funcsave
return 1
end
@ -21,7 +16,7 @@ function funcsave --description "Save the current definition of all specified fu
set -l retval 0
for funcname in $argv
if functions -q -- $funcname
functions -- $funcname >$configdir/fish/functions/$funcname.fish
functions -- $funcname >$__fish_config_dir/functions/$funcname.fish
else
printf (_ "%s: Unknown function '%s'\n") funcsave $funcname
set retval 1