浏览代码

feat: store history at NUMBAT_HISTORY if variable exists

Tom Webber 4 月之前
父节点
当前提交
4b6f662d24
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      numbat-cli/src/main.rs

+ 9 - 1
numbat-cli/src/main.rs

@@ -31,7 +31,7 @@ use rustyline::{EventHandler, Highlighter, KeyCode, KeyEvent, Modifiers};
 use std::io::IsTerminal;
 use std::io::IsTerminal;
 use std::path::{Path, PathBuf};
 use std::path::{Path, PathBuf};
 use std::sync::{Arc, Mutex};
 use std::sync::{Arc, Mutex};
-use std::{fs, thread};
+use std::{env, fs, thread};
 
 
 #[derive(Debug, PartialEq, Eq)]
 #[derive(Debug, PartialEq, Eq)]
 pub enum ExitStatus {
 pub enum ExitStatus {
@@ -570,6 +570,14 @@ impl Cli {
     }
     }
 
 
     fn get_history_path(&self) -> Result<PathBuf> {
     fn get_history_path(&self) -> Result<PathBuf> {
+        if let Ok(history) = env::var("NUMBAT_HISTORY") {
+            let history_path = PathBuf::from(history);
+            if let Some(parent) = history_path.parent() {
+                fs::create_dir_all(parent).ok();
+            }
+            return Ok(history_path);
+        }
+
         let data_dir = dirs::data_dir()
         let data_dir = dirs::data_dir()
             .unwrap_or_else(|| PathBuf::from("."))
             .unwrap_or_else(|| PathBuf::from("."))
             .join("numbat");
             .join("numbat");