Skip to content

Commit a1d7a91

Browse files
committed
Use shell-words crate to parse HDC_PAGER variable.
Now it is possible to use shell command with HDC_PAGER="sh -c '...'".
1 parent b5eb042 commit a1d7a91

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-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
@@ -16,6 +16,7 @@ gumdrop = "0.8.0"
1616
reqwest = { version = "0.10.9", features = ["json"] }
1717
serde = { version = "1.0.117", features = ["derive"] }
1818
serde_json = "1.0.59"
19+
shell-words = "1.0.0"
1920
terminal_size = "0.1.15"
2021
textwrap = { version = "0.12", features = ["terminal_size"] }
2122
tokio = { version = "0.2", features = ["rt-threaded", "io-util", "io-std"] }

src/pager.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ pub fn command(repository: Option<&str>) -> Option<Command> {
1313
}
1414

1515
let pager_var = env::var(PAGER_ENV);
16-
let mut pager_args = pager_var
17-
.as_deref()
18-
.unwrap_or(DEFAULT_PAGER)
19-
.split_whitespace();
16+
let pager_args = pager_var.as_deref().unwrap_or(DEFAULT_PAGER);
17+
18+
let mut pager_args = match shell_words::split(pager_args) {
19+
Ok(words) => words.into_iter(),
20+
Err(e) => {
21+
eprintln!("Failed to parse $HDC_PAGER: {:?}", e);
22+
return None;
23+
}
24+
};
2025

2126
let mut cmd = Command::new(pager_args.next()?);
2227

0 commit comments

Comments
 (0)