Remove scripted XDG_CONFIG_HOME uses

Cleaned up the code to no longer replicate in fishscript what fish
already does (and caches to boot) in C++ in setting up the paths to the
user configuration directory.

Also introduced a `$__fish_user_data_dir` instead of the sporadic
definitions of `$userdatadir` that may or may not go through
`XDG_DATA_HOME`.
This commit is contained in:
Mahmoud Al-Qudsi 2018-12-14 22:09:29 -06:00
parent 1634c0fa49
commit 3855c2217f
3 changed files with 13 additions and 21 deletions

View File

@ -62,18 +62,6 @@ end
# unless they already exist
#
set -g __fish_config_dir ~/.config/fish
if set -q XDG_CONFIG_HOME
set __fish_config_dir $XDG_CONFIG_HOME/fish
end
set -l userdatadir ~/.local/share
if set -q XDG_DATA_HOME
set userdatadir $XDG_DATA_HOME
end
# __fish_data_dir, __fish_sysconf_dir, __fish_help_dir, __fish_bin_dir
# are expected to have been set up by read_init from fish.cpp
@ -98,7 +86,7 @@ if not contains -- $__fish_data_dir/functions $fish_function_path
end
if not set -q fish_complete_path
set fish_complete_path $__fish_config_dir/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 $__fish_user_data_dir/generated_completions
end
if not contains -- $__fish_data_dir/completions $fish_complete_path
@ -109,7 +97,7 @@ end
function :
# no-op function for compatibility with sh, bash, and others.
# Often used to insert a comment into a chain of commands without having
# it eat up the remainder of the line, handy in Makefiles.
# it eat up the remainder of the line, handy in Makefiles.
end
#

View File

@ -21,12 +21,6 @@ function __fish_config_interactive -d "Initializations that should be performed
set -g __fish_config_interactive_done
set -g __fish_active_key_bindings
# Set the correct user data directory
set -l userdatadir ~/.local/share
if set -q XDG_DATA_HOME
set userdatadir $XDG_DATA_HOME
end
if not set -q fish_greeting
set -l line1 (_ 'Welcome to fish, the friendly interactive shell')
set -l line2 ''
@ -97,7 +91,7 @@ function __fish_config_interactive -d "Initializations that should be performed
#
# Don't do this if we're being invoked as part of running unit tests.
if not set -q FISH_UNIT_TESTS_RUNNING
if not test -d $userdatadir/fish/generated_completions
if not test -d $__fish_user_data_dir/generated_completions
# Generating completions from man pages needs python (see issue #3588).
# We cannot simply do `fish_update_completions &` because it is a function.

View File

@ -67,6 +67,8 @@
#define FISH_SYSCONFDIR_VAR L"__fish_sysconf_dir"
#define FISH_HELPDIR_VAR L"__fish_help_dir"
#define FISH_BIN_DIR L"__fish_bin_dir"
#define FISH_CONFIG_DIR L"__fish_config_dir"
#define FISH_USER_DATA_DIR L"__fish_user_data_dir"
/// At init, we read all the environment variables from this array.
extern char **environ;
@ -877,6 +879,14 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
env_set_one(FISH_BIN_DIR, ENV_GLOBAL, paths->bin);
}
wcstring user_config_dir;
path_get_config(user_config_dir);
env_set_one(FISH_CONFIG_DIR, ENV_GLOBAL, user_config_dir);
wcstring user_data_dir;
path_get_data(user_data_dir);
env_set_one(FISH_USER_DATA_DIR, ENV_GLOBAL, user_data_dir);
init_locale();
init_curses();
init_input();