2006-02-28 20:26:21 +01:00
|
|
|
#include "cache.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is split up from the rest of git so that we might do
|
|
|
|
* something different on Windows, for example.
|
|
|
|
*/
|
|
|
|
|
2006-04-16 04:44:25 +02:00
|
|
|
static void run_pager(const char *pager)
|
2006-02-28 20:26:21 +01:00
|
|
|
{
|
2006-04-16 04:44:25 +02:00
|
|
|
execlp(pager, pager, NULL);
|
2006-02-28 20:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup_pager(void)
|
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
int fd[2];
|
2006-04-16 04:44:25 +02:00
|
|
|
const char *pager = getenv("PAGER");
|
2006-02-28 20:26:21 +01:00
|
|
|
|
|
|
|
if (!isatty(1))
|
|
|
|
return;
|
2006-04-16 04:44:25 +02:00
|
|
|
if (!pager)
|
|
|
|
pager = "less";
|
|
|
|
else if (!*pager)
|
|
|
|
return;
|
|
|
|
|
2006-02-28 20:26:21 +01:00
|
|
|
if (pipe(fd) < 0)
|
|
|
|
return;
|
|
|
|
pid = fork();
|
|
|
|
if (pid < 0) {
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return in the child */
|
|
|
|
if (!pid) {
|
|
|
|
dup2(fd[1], 1);
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The original process turns into the PAGER */
|
|
|
|
dup2(fd[0], 0);
|
|
|
|
close(fd[0]);
|
|
|
|
close(fd[1]);
|
|
|
|
|
2006-04-16 04:44:25 +02:00
|
|
|
setenv("LESS", "-S", 0);
|
|
|
|
run_pager(pager);
|
2006-02-28 20:26:21 +01:00
|
|
|
exit(255);
|
|
|
|
}
|