mirror of
https://github.com/nushell/nushell
synced 2024-12-27 13:33:16 +00:00
Make history file location configurable (#2320)
* Make history location configurable Add history-path to your config if you want an alternate history file location * use IndexMap.get() instead of index Co-authored-by: Amanita Muscaria <nope>
This commit is contained in:
parent
901157341b
commit
9264325e57
1 changed files with 18 additions and 2 deletions
|
@ -203,12 +203,28 @@ pub struct History;
|
|||
impl History {
|
||||
pub fn path() -> PathBuf {
|
||||
const FNAME: &str = "history.txt";
|
||||
config::user_data()
|
||||
let default = config::user_data()
|
||||
.map(|mut p| {
|
||||
p.push(FNAME);
|
||||
p
|
||||
})
|
||||
.unwrap_or_else(|_| PathBuf::from(FNAME))
|
||||
.unwrap_or_else(|_| PathBuf::from(FNAME));
|
||||
|
||||
let cfg = crate::data::config::config(Tag::unknown());
|
||||
if let Ok(c) = cfg {
|
||||
match &c.get("history-path") {
|
||||
Some(Value {
|
||||
value: UntaggedValue::Primitive(p),
|
||||
..
|
||||
}) => match p {
|
||||
Primitive::String(path) => PathBuf::from(path),
|
||||
_ => default,
|
||||
},
|
||||
_ => default,
|
||||
}
|
||||
} else {
|
||||
default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue