mirror of
https://github.com/nushell/nushell.git
synced 2025-03-29 00:56:45 +01:00
* Use ctx.configs in all config commands * Remove all setting/accessing of vars.("config-path") * Add tests * Add comment * Reload cfg on remove * Hypocratic ws change * Use history_path in hist_or_default * Make clippy happy * Fix rebase stuff * Fix clippy lint
31 lines
801 B
Rust
31 lines
801 B
Rust
use std::path::PathBuf;
|
|
|
|
use super::NuConfig;
|
|
|
|
const DEFAULT_LOCATION: &str = "history.txt";
|
|
|
|
pub fn default_history_path() -> PathBuf {
|
|
crate::config::user_data()
|
|
.map(|mut p| {
|
|
p.push(DEFAULT_LOCATION);
|
|
p
|
|
})
|
|
.unwrap_or_else(|_| PathBuf::from(DEFAULT_LOCATION))
|
|
}
|
|
|
|
/// Get history path of config, if present
|
|
pub fn history_path(config: &NuConfig) -> Option<PathBuf> {
|
|
config
|
|
.var("history-path")
|
|
.map(|custom_path| match custom_path.as_string() {
|
|
Ok(path) => Some(PathBuf::from(path)),
|
|
Err(_) => None,
|
|
})
|
|
.flatten()
|
|
}
|
|
|
|
/// Get history path in config or default
|
|
pub fn history_path_or_default(config: &NuConfig) -> PathBuf {
|
|
history_path(config).unwrap_or_else(default_history_path)
|
|
}
|