mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 19:41:15 -03:00
Also trim trailing newlines when adding to history
When pasting and executing a full line, the trailing newline character will be included in history. I usually manually delete the newline before executing, but sometimes I forget. When I recall my (typically single-line) commands, it's surprising that the cursor is on the blank second line. The newline doesn't seem useful. Let's remove it automagically. I wonder if anyone will be thrown off by this smart behavior. In future, we can make this space trimming configurable, similar to fish_should_add_to_history.
This commit is contained in:
@@ -5722,7 +5722,10 @@ fn add_to_history(&mut self) {
|
||||
|
||||
// Historical behavior is to trim trailing spaces, unless escape (#7661).
|
||||
let mut text = self.command_line.text().to_owned();
|
||||
while text.chars().next_back() == Some(' ')
|
||||
while text
|
||||
.chars()
|
||||
.next_back()
|
||||
.is_some_and(|c| matches!(c, ' ' | '\n'))
|
||||
&& count_preceding_backslashes(&text, text.len() - 1) % 2 == 0
|
||||
{
|
||||
text.pop();
|
||||
|
||||
Reference in New Issue
Block a user