diff --git a/docs/cli/set.md b/docs/cli/set.md index 3db2d038c1..59a3b8d834 100644 --- a/docs/cli/set.md +++ b/docs/cli/set.md @@ -57,7 +57,8 @@ Can be used multiple times. Requires --age-encrypt. The TOML file to update Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory. -Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`. +Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. ### `--no-redact` diff --git a/docs/cli/unset.md b/docs/cli/unset.md index 833c215e3f..fbba905cd5 100644 --- a/docs/cli/unset.md +++ b/docs/cli/unset.md @@ -21,6 +21,8 @@ e.g.: NODE_ENV Specify a file to use instead of `mise.toml` +Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. + ### `-g --global` Use the global config file diff --git a/docs/cli/unuse.md b/docs/cli/unuse.md index 0b771dacc3..8d4d974c9b 100644 --- a/docs/cli/unuse.md +++ b/docs/cli/unuse.md @@ -16,10 +16,12 @@ In the following order: - If `--global` is set, it will use the global config file. - If `--path` is set, it will use the config file at the given path. - If `--env` is set, it will use `mise..toml`. -- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. +- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. - Otherwise just "mise.toml" or global config if cwd is home directory. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. + Will also prune the installed version if no other configurations are using it. ## Arguments diff --git a/docs/cli/use.md b/docs/cli/use.md index fb373c9375..ad35a6004c 100644 --- a/docs/cli/use.md +++ b/docs/cli/use.md @@ -17,10 +17,12 @@ In the following order: - If `--global` is set, it will use the global config file. - If `--path` is set, it will use the config file at the given path. - If `--env` is set, it will use `mise..toml`. -- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. +- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. - Otherwise just "mise.toml" or global config if cwd is home directory. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. + Use the `--global` flag to use the global config file instead. ## Arguments diff --git a/docs/configuration.md b/docs/configuration.md index c9e4ad9c23..fbdef3f597 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -488,6 +488,17 @@ Default: `$MISE_CONFIG_DIR/config.toml` (Usually `~/.config/mise/config.toml`) This is the path to the config file. +Use this when you want global writes, such as `mise use` or `mise set` run from +`$HOME`, to target a different config file. [`MISE_DEFAULT_CONFIG_FILENAME`](#mise_default_config_filename) +customizes the default local config filename, not the global config path. + +### `MISE_DEFAULT_CONFIG_FILENAME` + +Default: `mise.toml` + +This customizes the default local config filename used when mise creates or +looks for project config files. + ### `MISE_GLOBAL_CONFIG_ROOT` Default: `$HOME` diff --git a/docs/configuration/settings.md b/docs/configuration/settings.md index b6a492c404..93d22f9663 100644 --- a/docs/configuration/settings.md +++ b/docs/configuration/settings.md @@ -5,7 +5,8 @@ import Settings from '/components/settings.vue'; The following is a list of all of mise's settings. These can be set via `mise settings key=value`, -by directly modifying `~/.config/mise/config.toml` or local config, or via environment variables. +by directly modifying the [global config file](/configuration.html#mise_global_config_file) +(`~/.config/mise/config.toml`) or local config, or via environment variables. Some of them also can be set via global CLI flags. diff --git a/e2e/cli/test_global_config_file_home b/e2e/cli/test_global_config_file_home new file mode 100644 index 0000000000..573cef5236 --- /dev/null +++ b/e2e/cli/test_global_config_file_home @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +mkdir -p "$HOME/.config/mise" +cat >"$HOME/.config/mise/config.toml" <<'TOML' +[env] +LOCAL_ONLY = "true" +TOML +cat >"$HOME/.config/mise/config-global.toml" <<'TOML' +[env] +GLOBAL_ONLY = "true" +TOML +export MISE_GLOBAL_CONFIG_FILE="$HOME/.config/mise/config-global.toml" + +cd "$HOME" || exit 1 + +assert "mise set FOO=bar" "" +assert_contains "cat $HOME/.config/mise/config-global.toml" 'FOO = "bar"' +assert_not_contains "cat $HOME/.config/mise/config.toml" "FOO" + +assert "mise unset FOO" "" +assert_not_contains "cat $HOME/.config/mise/config-global.toml" "FOO" + +assert_contains "mise use dummy@system" "mise ~/.config/mise/config-global.toml tools: dummy@system" +assert_contains "cat $HOME/.config/mise/config-global.toml" 'dummy = "system"' +assert_not_contains "cat $HOME/.config/mise/config.toml" "dummy" + +assert_contains "mise unuse -y dummy 2>&1" "mise removed: dummy from ~/.config/mise/config-global.toml" +assert_not_contains "cat $HOME/.config/mise/config-global.toml" "dummy" diff --git a/man/man1/mise.1 b/man/man1/mise.1 index 8f7a568af8..0adfb9b2c5 100644 --- a/man/man1/mise.1 +++ b/man/man1/mise.1 @@ -2388,7 +2388,8 @@ Render completions The TOML file to update Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory. -Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`. +Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. .TP \fB\-\-no\-redact\fR Show raw values instead of redacting secrets @@ -3303,6 +3304,8 @@ By default, this command modifies `mise.toml` in the current directory. .TP \fB\-f, \-\-file\fR \fI\fR Specify a file to use instead of `mise.toml` + +Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. .TP \fB\-g, \-\-global\fR Use the global config file @@ -3334,10 +3337,12 @@ In the following order: \- If `\-\-global` is set, it will use the global config file. \- If `\-\-path` is set, it will use the config file at the given path. \- If `\-\-env` is set, it will use `mise..toml`. - \- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. + \- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. \- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. \- Otherwise just "mise.toml" or global config if cwd is home directory. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. + Will also prune the installed version if no other configurations are using it. .PP \fBUsage:\fR mise unuse [OPTIONS] ... @@ -3445,10 +3450,12 @@ In the following order: \- If `\-\-global` is set, it will use the global config file. \- If `\-\-path` is set, it will use the config file at the given path. \- If `\-\-env` is set, it will use `mise..toml`. - \- If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. + \- If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. \- If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. \- Otherwise just "mise.toml" or global config if cwd is home directory. +Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. + Use the `\-\-global` flag to use the global config file instead. .PP \fBUsage:\fR mise use [OPTIONS] [] ... diff --git a/mise.usage.kdl b/mise.usage.kdl index cab0504a3a..f172d4ef1d 100644 --- a/mise.usage.kdl +++ b/mise.usage.kdl @@ -972,7 +972,7 @@ cmd set help="Set environment variables in mise.toml" { } flag --complete help="Render completions" hide=#true flag --file help="The TOML file to update" { - long_help "The TOML file to update\n\nCan be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.\nDefaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`." + long_help "The TOML file to update\n\nCan be a file path or directory. If a directory is provided, will create/use mise.toml in that directory.\nDefaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`.\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path." arg } flag --no-redact help="Show raw values instead of redacting secrets" @@ -1343,6 +1343,7 @@ cmd unset help="Remove environment variable(s) from the config file." { long_help "Remove environment variable(s) from the config file.\n\nBy default, this command modifies `mise.toml` in the current directory." after_long_help "Examples:\n\n # Remove NODE_ENV from the current directory's config\n $ mise unset NODE_ENV\n\n # Remove NODE_ENV from the global config\n $ mise unset NODE_ENV -g\n" flag "-f --file" help="Specify a file to use instead of `mise.toml`" { + long_help "Specify a file to use instead of `mise.toml`\n\nDefaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path." arg } flag "-g --global" help="Use the global config file" @@ -1353,7 +1354,7 @@ cmd untrust help="No longer trust a config, will prompt in the future" { } cmd unuse help="Removes installed tool versions from mise.toml" { alias rm remove - long_help "Removes installed tool versions from mise.toml\n\nBy default, this will use the `mise.toml` file that has the tool defined.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise..toml`.\n - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nWill also prune the installed version if no other configurations are using it." + long_help "Removes installed tool versions from mise.toml\n\nBy default, this will use the `mise.toml` file that has the tool defined.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise..toml`.\n - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.\n\nWill also prune the installed version if no other configurations are using it." after_long_help "Examples:\n\n # will uninstall specific version\n $ mise unuse node@18.0.0\n\n # will uninstall specific version from global config\n $ mise unuse -g node@18.0.0\n\n # will uninstall specific version from .mise.local.toml\n $ mise unuse --env local node@20\n\n # will uninstall specific version from .mise.staging.toml\n $ mise unuse --env staging node@20\n" flag "-e --env" help="Create/modify an environment-specific config file like .mise..toml" { arg @@ -1400,7 +1401,7 @@ cmd usage hide=#true help="Generate a usage CLI spec" { } cmd use help="Installs a tool and adds the version to mise.toml." { alias u - long_help "Installs a tool and adds the version to mise.toml.\n\nThis will install the tool version if it is not already installed.\nBy default, this will use a `mise.toml` file in the current directory.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise..toml`.\n - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse the `--global` flag to use the global config file instead." + long_help "Installs a tool and adds the version to mise.toml.\n\nThis will install the tool version if it is not already installed.\nBy default, this will use a `mise.toml` file in the current directory.\nIf multiple config files exist (e.g., both `mise.toml` and `mise.local.toml`),\nthe lowest precedence file (`mise.toml`) will be used.\nSee https://mise.en.dev/configuration.html#target-file-for-write-operations\n\nIn the following order:\n - If `--global` is set, it will use the global config file.\n - If `--path` is set, it will use the config file at the given path.\n - If `--env` is set, it will use `mise..toml`.\n - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead.\n - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list.\n - Otherwise just \"mise.toml\" or global config if cwd is home directory.\n\nUse [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path.\n\nUse the `--global` flag to use the global config file instead." after_long_help "Examples:\n\n # run with no arguments to use the interactive selector\n $ mise use\n\n # set the current version of node to 20.x in mise.toml of current directory\n # will write the fuzzy version (e.g.: 20)\n $ mise use node@20\n\n # set the current version of node to 20.x in ~/.config/mise/config.toml\n # will write the precise version (e.g.: 20.0.0)\n $ mise use -g --pin node@20\n\n # sets .mise.local.toml (which is intended not to be committed to a project)\n $ mise use --env local node@20\n\n # sets .mise.staging.toml (which is used if MISE_ENV=staging)\n $ mise use --env staging node@20\n" flag "-e --env" help="Create/modify an environment-specific config file like .mise..toml" { arg diff --git a/src/cli/set.rs b/src/cli/set.rs index 3794a5026b..e5f8378ad4 100644 --- a/src/cli/set.rs +++ b/src/cli/set.rs @@ -68,7 +68,8 @@ pub struct Set { /// The TOML file to update /// /// Can be a file path or directory. If a directory is provided, will create/use mise.toml in that directory. - /// Defaults to MISE_DEFAULT_CONFIG_FILENAME environment variable, or `mise.toml`. + /// Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. + /// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. #[clap(long, verbatim_doc_comment, required = false, value_hint = clap::ValueHint::AnyPath)] file: Option, diff --git a/src/cli/unset.rs b/src/cli/unset.rs index ef74ee9ba8..6e6a010791 100644 --- a/src/cli/unset.rs +++ b/src/cli/unset.rs @@ -4,7 +4,7 @@ use eyre::Result; use crate::config::config_file::ConfigFile; use crate::config::config_file::mise_toml::MiseToml; -use crate::{config, env}; +use crate::config::{ConfigPathOptions, resolve_target_config_path}; /// Remove environment variable(s) from the config file. /// @@ -18,6 +18,9 @@ pub struct Unset { keys: Vec, /// Specify a file to use instead of `mise.toml` + /// + /// Defaults to [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) environment variable, or `mise.toml`. + /// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. #[clap(short, long, value_hint = clap::ValueHint::FilePath)] file: Option, @@ -39,13 +42,14 @@ const AFTER_LONG_HELP: &str = color_print::cstr!( impl Unset { pub async fn run(self) -> Result<()> { - let filename = if let Some(file) = &self.file { - file.clone() - } else if self.global { - config::global_config_path() - } else { - config::top_toml_config().unwrap_or(env::MISE_DEFAULT_CONFIG_FILENAME.clone().into()) - }; + let filename = resolve_target_config_path(ConfigPathOptions { + global: self.global, + path: self.file.clone(), + env: None, + cwd: None, + prefer_toml: true, + prevent_home_local: true, + })?; let mut config = MiseToml::from_file(&filename).unwrap_or_default(); diff --git a/src/cli/unuse.rs b/src/cli/unuse.rs index 9d75b97699..55dc6bdb49 100644 --- a/src/cli/unuse.rs +++ b/src/cli/unuse.rs @@ -21,10 +21,12 @@ use path_absolutize::Absolutize; /// - If `--global` is set, it will use the global config file. /// - If `--path` is set, it will use the config file at the given path. /// - If `--env` is set, it will use `mise..toml`. -/// - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. +/// - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. /// - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. /// - Otherwise just "mise.toml" or global config if cwd is home directory. /// +/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. +/// /// Will also prune the installed version if no other configurations are using it. #[derive(Debug, clap::Args)] #[clap(verbatim_doc_comment, visible_aliases = ["rm", "remove"], after_long_help = AFTER_LONG_HELP)] diff --git a/src/cli/use.rs b/src/cli/use.rs index 4eac67e18c..a0f215811f 100644 --- a/src/cli/use.rs +++ b/src/cli/use.rs @@ -34,10 +34,12 @@ use crate::{config, env, exit, file}; /// - If `--global` is set, it will use the global config file. /// - If `--path` is set, it will use the config file at the given path. /// - If `--env` is set, it will use `mise..toml`. -/// - If `MISE_DEFAULT_CONFIG_FILENAME` is set, it will use that instead. +/// - If [`MISE_DEFAULT_CONFIG_FILENAME`](https://mise.en.dev/configuration.html#mise_default_config_filename) is set, it will use that instead. /// - If `MISE_OVERRIDE_CONFIG_FILENAMES` is set, it will the first from that list. /// - Otherwise just "mise.toml" or global config if cwd is home directory. /// +/// Use [`MISE_GLOBAL_CONFIG_FILE`](https://mise.en.dev/configuration.html#mise_global_config_file) to choose a different global config path. +/// /// Use the `--global` flag to use the global config file instead. #[derive(Debug, clap::Args)] #[clap(verbatim_doc_comment, visible_alias = "u", after_long_help = AFTER_LONG_HELP)]