mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-13 22:28:26 +00:00
Prevent fork nightmare with PAGER=batcat (#2235)
* Added rsamuelklatchko's changes * Added some comments and deleted redundant code * Ran cargo fmt * Update src/pager.rs Co-authored-by: Martin Nordholts <enselic@gmail.com> * Added bugfix to changelog * src/pager.rs nitpick: arg0 -> s I forgot to comment on this name so I figured I'd just push a commit to take care of it. Co-authored-by: Martin Nordholts <enselic@gmail.com>
This commit is contained in:
parent
c4d9d7561b
commit
7b2e0ece55
@ -6,6 +6,8 @@
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Prevent fork nightmare with `PAGER=batcat`. See #2235 (@johnmatthiggins)
|
||||
|
||||
## Other
|
||||
|
||||
- Relaxed glibc requirements on amd64, see #2106 and #2194 (@sharkdp)
|
||||
|
20
src/pager.rs
20
src/pager.rs
@ -40,15 +40,23 @@ impl PagerKind {
|
||||
fn from_bin(bin: &str) -> PagerKind {
|
||||
use std::path::Path;
|
||||
|
||||
match Path::new(bin)
|
||||
.file_stem()
|
||||
.map(|s| s.to_string_lossy())
|
||||
.as_deref()
|
||||
{
|
||||
Some("bat") => PagerKind::Bat,
|
||||
// Set to `less` by default on most Linux distros.
|
||||
let pager_bin = Path::new(bin).file_stem();
|
||||
|
||||
// The name of the current running binary. Normally `bat` but sometimes
|
||||
// `batcat` for compatibility reasons.
|
||||
let current_bin = env::args_os().next();
|
||||
|
||||
// Check if the current running binary is set to be our pager.
|
||||
let is_current_bin_pager = current_bin
|
||||
.map(|s| Path::new(&s).file_stem() == pager_bin)
|
||||
.unwrap_or(false);
|
||||
|
||||
match pager_bin.map(|s| s.to_string_lossy()).as_deref() {
|
||||
Some("less") => PagerKind::Less,
|
||||
Some("more") => PagerKind::More,
|
||||
Some("most") => PagerKind::Most,
|
||||
_ if is_current_bin_pager => PagerKind::Bat,
|
||||
_ => PagerKind::Unknown,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user