summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--scoop.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/scoop.c b/scoop.c
index f735fe2..0b652d9 100644
--- a/scoop.c
+++ b/scoop.c
@@ -118,12 +118,8 @@ int main(int argc, char *argv[]) {
 	}
 	if (optind < argc) search = argv[optind];
 
-	dbFind(path, SQLITE_OPEN_READONLY);
-	if (dbVersion() != DatabaseVersion) {
-		errx(EX_CONFIG, "database out of date; migrate with litterbox -m");
-	}
-
 	if (shell) {
+		dbFind(path, SQLITE_OPEN_READONLY);
 		path = strdup(sqlite3_db_filename(db, "main"));
 		if (!path) err(EX_OSERR, "strdup");
 		dbClose();
@@ -131,7 +127,36 @@ int main(int argc, char *argv[]) {
 		err(EX_UNAVAILABLE, "sqlite3");
 	}
 
-	// TODO: Set up pipe to $PAGER.
+	bool tty = isatty(STDOUT_FILENO);
+	if (tty) {
+		const char *pager = getenv("PAGER");
+		if (!pager) pager = "less";
+		setenv("LESS", "FRX", 0);
+
+		int rw[2];
+		int error = pipe(rw);
+		if (error) err(EX_OSERR, "pipe");
+
+		pid_t pid = fork();
+		if (pid < 0) err(EX_OSERR, "fork");
+
+		if (!pid) {
+			dup2(rw[0], STDIN_FILENO);
+			close(rw[0]);
+			close(rw[1]);
+			execlp(pager, pager, NULL);
+			err(EX_CONFIG, "%s", pager);
+		}
+
+		dup2(rw[1], STDOUT_FILENO);
+		close(rw[0]);
+		close(rw[1]);
+	}
+
+	dbFind(path, SQLITE_OPEN_READONLY);
+	if (dbVersion() != DatabaseVersion) {
+		errx(EX_CONFIG, "database out of date; migrate with litterbox -m");
+	}
 
 	char sql[4096];
 	if (search) {
@@ -205,4 +230,10 @@ int main(int argc, char *argv[]) {
 
 	sqlite3_finalize(stmt);
 	dbClose();
+
+	if (tty) {
+		fclose(stdout);
+		int status;
+		wait(&status);
+	}
 }
n in print_rel_date()John Keeping 2015-08-13ui-shared: extract date formatting to a functionJohn Keeping 2015-08-13filter: don't use dlsym unnecessarilyJohn Keeping 2015-08-13ui-tree: use "sane" isgraph()John Keeping 2015-08-13cgit.h: move stdbool.h from ui-shared.hJohn Keeping 2015-08-13cache.c: fix header orderJohn Keeping 2015-08-13configfile.c: don't include system headers directlyJohn Keeping 2015-08-13Remove redundant includesJohn Keeping 2015-08-13Makefile: include Git's config.mak.unameJohn Keeping 2015-08-13tests: allow shell to be overriddenJohn Keeping 2015-08-13redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping 2015-08-12log: allow users to follow a fileJohn Keeping 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld 2015-08-12filters: apply HTML escapingLazaros Koromilas 2015-08-12git: update to v2.5.0Christian Hesse 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt