]>
Commit | Line | Data |
---|---|---|
f67b45f8 LT |
1 | #include "cache.h" |
2 | ||
3 | /* | |
4 | * This is split up from the rest of git so that we might do | |
5 | * something different on Windows, for example. | |
6 | */ | |
7 | ||
402461aa | 8 | static void run_pager(const char *pager) |
f67b45f8 | 9 | { |
402461aa | 10 | execlp(pager, pager, NULL); |
f67b45f8 LT |
11 | } |
12 | ||
13 | void setup_pager(void) | |
14 | { | |
15 | pid_t pid; | |
16 | int fd[2]; | |
402461aa | 17 | const char *pager = getenv("PAGER"); |
f67b45f8 LT |
18 | |
19 | if (!isatty(1)) | |
20 | return; | |
402461aa JS |
21 | if (!pager) |
22 | pager = "less"; | |
23 | else if (!*pager) | |
24 | return; | |
25 | ||
f67b45f8 LT |
26 | if (pipe(fd) < 0) |
27 | return; | |
28 | pid = fork(); | |
29 | if (pid < 0) { | |
30 | close(fd[0]); | |
31 | close(fd[1]); | |
32 | return; | |
33 | } | |
34 | ||
35 | /* return in the child */ | |
36 | if (!pid) { | |
37 | dup2(fd[1], 1); | |
38 | close(fd[0]); | |
39 | close(fd[1]); | |
40 | return; | |
41 | } | |
42 | ||
43 | /* The original process turns into the PAGER */ | |
44 | dup2(fd[0], 0); | |
45 | close(fd[0]); | |
46 | close(fd[1]); | |
47 | ||
402461aa JS |
48 | setenv("LESS", "-S", 0); |
49 | run_pager(pager); | |
f67b45f8 LT |
50 | exit(255); |
51 | } |