-
Notifications
You must be signed in to change notification settings - Fork 2.3k
move history txt to state dir #5410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,24 +397,37 @@ impl CliSession { | |
| let completer = GooseCompleter::new(self.completion_cache.clone()); | ||
| editor.set_helper(Some(completer)); | ||
|
|
||
| let history_file = Paths::config_dir().join("history.txt"); | ||
| let history_file = Paths::state_dir().join("history.txt"); | ||
| let old_history_file = Paths::config_dir().join("history.txt"); | ||
|
|
||
| if let Some(parent) = history_file.parent() { | ||
| if !parent.exists() { | ||
| std::fs::create_dir_all(parent)?; | ||
| } | ||
| } | ||
|
|
||
| if history_file.exists() { | ||
| let history_loaded = if history_file.exists() { | ||
| if let Err(err) = editor.load_history(&history_file) { | ||
| eprintln!("Warning: Failed to load command history: {}", err); | ||
| } | ||
| } | ||
| true | ||
| } else if old_history_file.exists() { | ||
| if let Err(err) = editor.load_history(&old_history_file) { | ||
| eprintln!("Warning: Failed to load command history: {}", err); | ||
| } | ||
| true | ||
| } else { | ||
| false | ||
| }; | ||
|
||
|
|
||
| let save_history = | ||
| |editor: &mut rustyline::Editor<GooseCompleter, rustyline::history::DefaultHistory>| { | ||
| if let Err(err) = editor.save_history(&history_file) { | ||
| eprintln!("Warning: Failed to save command history: {}", err); | ||
| } else if history_loaded && old_history_file.exists() { | ||
|
||
| if let Err(err) = std::fs::remove_file(&old_history_file) { | ||
| eprintln!("Warning: Failed to remove old history file: {}", err); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the above seems more complicated than it should be. we already check if the history file exists. if we also check whether the old history exists we can then just load from old if new doesn't exist and delete old when new does exist