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
16pub 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
23pub fn history_path_or_default(config: &NuConfig) -> PathBuf {
25 history_path(config).unwrap_or_else(default_history_path)
26}