Skip to content

Commit 384ae47

Browse files
Merge pull request RustPython#282 from orf/use-xdg
Use XDG paths to store Python history
2 parents a7d011f + a72dbf1 commit 384ae47

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ clap = "2.31.2"
1313
rustpython_parser = {path = "parser"}
1414
rustpython_vm = {path = "vm"}
1515
rustyline = "2.1.0"
16+
xdg = "2.2.0"
1617

1718
[profile.release]
1819
opt-level = "s"

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate log;
77
extern crate rustpython_parser;
88
extern crate rustpython_vm;
99
extern crate rustyline;
10+
extern crate xdg;
1011

1112
use clap::{App, Arg};
1213
use rustpython_parser::parser;
@@ -154,9 +155,10 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
154155
let mut input = String::new();
155156
let mut rl = Editor::<()>::new();
156157

157-
// TODO: Store the history in a proper XDG directory
158-
let repl_history_path = ".repl_history.txt";
159-
if rl.load_history(repl_history_path).is_err() {
158+
let xdg_dirs = xdg::BaseDirectories::with_prefix("rustpython").unwrap();
159+
let repl_history_path = xdg_dirs.place_cache_file("repl_history.txt").unwrap();
160+
let repl_history_path_str = repl_history_path.to_str().unwrap();
161+
if rl.load_history(repl_history_path_str).is_err() {
160162
println!("No previous history.");
161163
}
162164

@@ -220,7 +222,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult {
220222
}
221223
};
222224
}
223-
rl.save_history(repl_history_path).unwrap();
225+
rl.save_history(repl_history_path_str).unwrap();
224226

225227
Ok(vm.get_none())
226228
}

0 commit comments

Comments
 (0)