nu_data/config/
path.rs

1use std::path::PathBuf;
2
3use super::NuConfig;
4
5const DEFAULT_LOCATION: &str = "history.txt";
6
7pub fn default_history_path() -> PathBuf {
8    crate::config::user_data()
9        .map(|mut p| {
10            p.push(DEFAULT_LOCATION);
11            p
12        })
13        .unwrap_or_else(|_| PathBuf::from(DEFAULT_LOCATION))
14}
15
16/// Get history path of config, if present
17pub fn history_path(config: &NuConfig) -> Option<PathBuf> {
18    config
19        .var("history-path")
20        .and_then(|custom_path| custom_path.as_string().map(PathBuf::from).ok())
21}
22
23/// Get history path in config or default
24pub fn history_path_or_default(config: &NuConfig) -> PathBuf {
25    history_path(config).unwrap_or_else(default_history_path)
26}