mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 17:31:14 -03:00
env: extract function for setting our config path variables
While at it, reorder the assignments to match the order in ConfigPaths.
This commit is contained in:
48
src/env/environment.rs
vendored
48
src/env/environment.rs
vendored
@@ -32,6 +32,7 @@
|
||||
use std::ffi::CStr;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Set when a universal variable has been modified but not yet been written to disk via sync().
|
||||
@@ -632,45 +633,36 @@ pub fn env_init(paths: Option<&ConfigPaths>, do_uvars: bool, default_paths: bool
|
||||
setup_user(vars);
|
||||
|
||||
if let Some(paths) = paths {
|
||||
let set_path = |key: &wstr, maybe_path: Option<&PathBuf>| {
|
||||
vars.set(
|
||||
key,
|
||||
EnvMode::GLOBAL,
|
||||
maybe_path
|
||||
.map(|path| vec![bytes2wcstring(path.as_os_str().as_bytes())])
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
};
|
||||
|
||||
set_path(FISH_SYSCONFDIR_VAR, Some(&paths.sysconf));
|
||||
set_path(FISH_BIN_DIR, paths.bin.as_ref());
|
||||
|
||||
#[cfg(feature = "embed-data")]
|
||||
vars.set_empty(FISH_DATADIR_VAR, EnvMode::GLOBAL);
|
||||
#[cfg(not(feature = "embed-data"))]
|
||||
{
|
||||
let datadir = bytes2wcstring(paths.data.as_os_str().as_bytes());
|
||||
vars.set_one(FISH_DATADIR_VAR, EnvMode::GLOBAL, datadir.clone());
|
||||
|
||||
let datadir = &paths.data;
|
||||
set_path(FISH_DATADIR_VAR, Some(datadir));
|
||||
if default_paths {
|
||||
let mut scstr = datadir;
|
||||
// This is generated by PathBuf.join() everywhere currently
|
||||
assert!(!scstr.ends_with("/"));
|
||||
scstr.push_str("/functions");
|
||||
vars.set_one(L!("fish_function_path"), EnvMode::GLOBAL, scstr);
|
||||
let mut scstr = datadir.clone();
|
||||
scstr.push("functions");
|
||||
set_path(L!("fish_function_path"), Some(&scstr));
|
||||
}
|
||||
}
|
||||
|
||||
vars.set_one(
|
||||
FISH_SYSCONFDIR_VAR,
|
||||
EnvMode::GLOBAL,
|
||||
bytes2wcstring(paths.sysconf.as_os_str().as_bytes()),
|
||||
);
|
||||
|
||||
#[cfg(feature = "embed-data")]
|
||||
vars.set_empty(FISH_HELPDIR_VAR, EnvMode::GLOBAL);
|
||||
#[cfg(not(feature = "embed-data"))]
|
||||
vars.set_one(
|
||||
FISH_HELPDIR_VAR,
|
||||
EnvMode::GLOBAL,
|
||||
bytes2wcstring(paths.doc.as_os_str().as_bytes()),
|
||||
);
|
||||
if let Some(bp) = &paths.bin {
|
||||
vars.set_one(
|
||||
FISH_BIN_DIR,
|
||||
EnvMode::GLOBAL,
|
||||
bytes2wcstring(bp.as_os_str().as_bytes()),
|
||||
);
|
||||
} else {
|
||||
vars.set_empty(FISH_BIN_DIR, EnvMode::GLOBAL);
|
||||
};
|
||||
set_path(FISH_HELPDIR_VAR, Some(&paths.doc));
|
||||
}
|
||||
|
||||
let user_config_dir = path_get_config();
|
||||
|
||||
Reference in New Issue
Block a user