From 3be910392f1186cacf0796e952fb5dae38b10f57 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 28 Sep 2011 11:41:44 -0700 Subject: dispatch-conf: support PAGER var for bug #384663 --- bin/dispatch-conf | 32 ++++++++++++++++++++++++++++++++ cnf/dispatch-conf.conf | 10 +++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bin/dispatch-conf b/bin/dispatch-conf index 497927df4..55d7f13d7 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -64,6 +64,20 @@ atexit.register(cleanup) MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ] +def cmd_var_is_valid(cmd): + """ + Return true if the first whitespace-separated token contained + in cmd is an executable file, false otherwise. + """ + cmd = portage.util.shlex_split(cmd) + if not cmd: + return False + + if os.path.isabs(cmd[0]): + return os.access(cmd[0], os.EX_OK) + + return find_binary(cmd[0]) is not None + class dispatch: options = {} @@ -84,6 +98,22 @@ class dispatch: else: self.options["log-file"] = "/dev/null" + pager = self.options.get("pager") + if pager is None or not cmd_var_is_valid(pager): + pager = os.environ.get("PAGER") + if pager is None or not cmd_var_is_valid(pager): + pager = "cat" + + if os.path.basename(pager) == "less": + less_opts = self.options.get("less-opts") + if less_opts is not None and less_opts.strip(): + pager += " " + less_opts + + if os.path.basename(portage.util.shlex_split(pager)[0]) == "cat": + pager = "" + else: + pager = " | " + pager + # # Build list of extant configs # @@ -226,10 +256,12 @@ class dispatch: clear_screen() if show_new_diff: cmd = self.options['diff'] % (conf['new'], mrgconf) + cmd += pager spawn_shell(cmd) show_new_diff = 0 else: cmd = self.options['diff'] % (conf['current'], newconf) + cmd += pager spawn_shell(cmd) print() diff --git a/cnf/dispatch-conf.conf b/cnf/dispatch-conf.conf index b51b61ae1..c4ab33f99 100644 --- a/cnf/dispatch-conf.conf +++ b/cnf/dispatch-conf.conf @@ -22,7 +22,15 @@ use-rcs=no # %s new file # If using colordiff instead of diff, the less -R option may be required # for correct display. -diff="diff -Nu '%s' '%s' | less --no-init --QUIT-AT-EOF" +diff="diff -Nu '%s' '%s'" + +# Set the pager for use with diff commands (this will +# cause the PAGER environment variable to be ignored). +# Setting pager="cat" will disable pager usage. +pager="" + +# Default options used if less is the pager +less-opts="--no-init --QUIT-AT-EOF" # Diff for interactive merges. # %s output file -- cgit v1.2.3