Skip to content

Commit b93f7d1

Browse files
committed
sh: cleanup write_history_to_file
1 parent 4e708ef commit b93f7d1

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

sh/src/shell/history.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,12 @@ pub fn write_history_to_file(history: &History, env: &Environment) {
228228
eprintln!("sh: HISTFILE or HOME not set, history not saved");
229229
return;
230230
};
231-
match std::fs::File::options().write(true).open(&path) {
232-
Ok(mut file) => {
233-
for entry in &history.entries {
234-
if let Err(err) = writeln!(file, "{}", entry.command) {
235-
eprintln!("sh: failed to write to history file at {} ({err})", path);
236-
return;
237-
}
238-
}
239-
}
240-
Err(err) => {
241-
eprintln!("sh: failed to open history file at {} ({err})", path);
242-
}
231+
let mut content = String::new();
232+
for entry in &history.entries {
233+
content.push_str(&entry.command);
234+
}
235+
if let Err(err) = std::fs::write(&path, content) {
236+
eprintln!("sh: failed to open history file at {} ({err})", path);
243237
}
244238
}
245239

0 commit comments

Comments
 (0)