4 * This is split up from the rest of git so that we can do
5 * something different on Windows.
8 static int spawned_pager
;
11 static void run_pager(const char *pager
)
14 * Work around bug in "less" by not starting it until we
21 select(1, &in
, NULL
, &in
, NULL
);
23 execlp(pager
, pager
, NULL
);
24 execl("/bin/sh", "sh", "-c", pager
, NULL
);
27 #include "run-command.h"
29 static const char *pager_argv
[] = { "sh", "-c", NULL
, NULL
};
30 static struct child_process pager_process
= {
34 static void wait_for_pager(void)
38 /* signal EOF to pager */
41 finish_command(&pager_process
);
45 void setup_pager(void)
51 const char *pager
= getenv("GIT_PAGER");
57 git_config(git_default_config
);
58 pager
= pager_program
;
61 pager
= getenv("PAGER");
64 else if (!*pager
|| !strcmp(pager
, "cat"))
67 spawned_pager
= 1; /* means we are emitting to terminal */
79 /* return in the child */
88 /* The original process turns into the PAGER */
93 setenv("LESS", "FRSX", 0);
95 die("unable to execute pager '%s'", pager
);
99 pager_argv
[2] = pager
;
100 if (start_command(&pager_process
))
103 /* original process continues, but writes to the pipe */
104 dup2(pager_process
.in
, 1);
105 dup2(pager_process
.in
, 2);
106 close(pager_process
.in
);
108 /* this makes sure that the parent terminates after the pager */
109 atexit(wait_for_pager
);
113 int pager_in_use(void)
120 env
= getenv("GIT_PAGER_IN_USE");
121 return env
? git_config_bool("GIT_PAGER_IN_USE", env
) : 0;