Skip to content

Commit d26206f

Browse files
committed
fix(pager): ensure we always pass -R to less
1 parent b76f7fd commit d26206f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

test/manpage_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ TEST(pager_test, find_pager_program) {
273273
auto pager = find_pager_program(os);
274274
ASSERT_TRUE(pager);
275275
EXPECT_EQ("/whatever/bin/less", pager->name);
276-
EXPECT_TRUE(pager->args.empty());
276+
EXPECT_THAT(pager->args, ::testing::ElementsAre("-R"));
277277
}
278278

279279
os.setenv("PAGER", "cat");

tools/src/tool/pager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#endif
4343

4444
#include <dwarfs/os_access.h>
45+
#include <dwarfs/string.h>
4546
#include <dwarfs/tool/pager.h>
4647

4748
namespace dwarfs::tool {
@@ -77,14 +78,20 @@ std::optional<pager_program> find_pager_program(os_access const& os) {
7778
sv.remove_suffix(1);
7879
}
7980

80-
std::filesystem::path p{std::string(sv)};
81+
// split into program and arguments
82+
auto args = split_to<std::vector<std::string>>(sv, ' ');
83+
std::filesystem::path p{args.front()};
84+
args.erase(args.begin());
8185

8286
if (os.access(p, X_OK) == 0) {
83-
return pager_program{p, {}};
87+
return pager_program{p, args};
8488
}
8589

8690
if (auto exe = os.find_executable(p); !exe.empty()) {
87-
return pager_program{exe, {}};
91+
if (exe.filename() == "less" && args.empty()) {
92+
args.push_back("-R");
93+
}
94+
return pager_program{exe, args};
8895
}
8996
}
9097

0 commit comments

Comments
 (0)