Skip to content
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

zsh import multi-line fix #2390

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions crates/atuin-client/src/import/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ impl Importer for Zsh {
_ => continue, // we can skip past things like invalid utf8
};

if let Some(s) = s.strip_suffix('\\') {
line.push_str(s);
line.push_str("\\\n");
if s.ends_with("\\\\") {
if let Some(s) = s.strip_suffix("\\\\") {
line.push_str(s);
line.push_str("\\\n");
}
} else if s.ends_with('\\') {
if let Some(s) = s.strip_suffix('\\') {
line.push_str(s);
line.push_str("\\\n");
}
} else {
line.push_str(&s);
let command = std::mem::take(&mut line);
Expand Down Expand Up @@ -189,13 +196,15 @@ mod test {
let bytes = r": 1613322469:0;cargo install atuin
: 1613322469:10;cargo install atuin; \
cargo update
: 1613322469:10;cargo install atuin; \\
cargo update
: 1613322469:10;cargo :b̷i̶t̴r̵o̴t̴ ̵i̷s̴ ̷r̶e̵a̸l̷
"
.as_bytes()
.to_owned();

let mut zsh = Zsh { bytes };
assert_eq!(zsh.entries().await.unwrap(), 4);
assert_eq!(zsh.entries().await.unwrap(), 6);

let mut loader = TestLoader::default();
zsh.load(&mut loader).await.unwrap();
Expand All @@ -205,6 +214,7 @@ cargo update
[
"cargo install atuin",
"cargo install atuin; \\\ncargo update",
"cargo install atuin; \\\ncargo update",
"cargo :b̷i̶t̴r̵o̴t̴ ̵i̷s̴ ̷r̶e̵a̸l̷",
],
);
Expand Down