From e1cf7e852c4a4c0cfce8c0de5625d026229dd71b Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 15 Nov 2020 20:26:54 +0100 Subject: [PATCH] ui: Disable paging if $PAGER is set to the empty string. * guix/ui.scm (call-with-paginated-output-port): Don't open a pipe if $PAGER is "". --- guix/ui.scm | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 66614eef7c..bb03e06759 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -1663,24 +1663,27 @@ zero means that PACKAGE does not match any of REGEXPS." (define* (call-with-paginated-output-port proc #:key (less-options "FrX")) - (if (isatty?* (current-output-port)) - ;; Set 'LESS' so that 'less' exits if everything fits on the screen (F), - ;; lets ANSI escapes through (r), does not send the termcap - ;; initialization string (X). Set it unconditionally because some - ;; distros set it to something that doesn't work here. - ;; - ;; For things that produce long lines, such as 'guix processes', use 'R' - ;; instead of 'r': this strips hyperlinks but allows 'less' to make a - ;; good estimate of the line length. - (let ((pager (with-environment-variables `(("LESS" ,less-options)) - (open-pipe (or (getenv "GUIX_PAGER") (getenv "PAGER") - "less") - OPEN_WRITE)))) - (dynamic-wind - (const #t) - (lambda () (proc pager)) - (lambda () (close-pipe pager)))) - (proc (current-output-port)))) + (let ((command (or (getenv "GUIX_PAGER") (getenv "PAGER") + "less"))) + ;; If a user types ‘PAGER= guix foo’ their intention is probably to disable + ;; paging entirely, not to use Guix's default pager. + (if (and (not (string=? "" command)) + (isatty?* (current-output-port))) + ;; Set 'LESS' so that 'less' exits if everything fits on the screen (F), + ;; lets ANSI escapes through (r), does not send the termcap + ;; initialization string (X). Set it unconditionally because some + ;; distros set it to something that doesn't work here. + ;; + ;; For things that produce long lines, such as 'guix processes', use 'R' + ;; instead of 'r': this strips hyperlinks but allows 'less' to make a + ;; good estimate of the line length. + (let ((pager (with-environment-variables `(("LESS" ,less-options)) + (open-pipe command OPEN_WRITE)))) + (dynamic-wind + (const #t) + (lambda () (proc pager)) + (lambda () (close-pipe pager)))) + (proc (current-output-port))))) (define-syntax with-paginated-output-port (syntax-rules () -- 2.29.2