allow double click on current HEAD id after git-pull
[git.git] / pager.c
blob1364e15d23527c0c4a11bcbe18c80c32af6d94b4
1 #include "cache.h"
3 /*
4 * This is split up from the rest of git so that we might do
5 * something different on Windows, for example.
6 */
8 static void run_pager(void)
10 const char *prog = getenv("PAGER");
11 if (!prog)
12 prog = "less";
13 setenv("LESS", "-S", 0);
14 execlp(prog, prog, NULL);
17 void setup_pager(void)
19 pid_t pid;
20 int fd[2];
22 if (!isatty(1))
23 return;
24 if (pipe(fd) < 0)
25 return;
26 pid = fork();
27 if (pid < 0) {
28 close(fd[0]);
29 close(fd[1]);
30 return;
33 /* return in the child */
34 if (!pid) {
35 dup2(fd[1], 1);
36 close(fd[0]);
37 close(fd[1]);
38 return;
41 /* The original process turns into the PAGER */
42 dup2(fd[0], 0);
43 close(fd[0]);
44 close(fd[1]);
46 run_pager();
47 exit(255);