aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-09-28 18:41:44 (GMT)
committerZac Medico <zmedico@gentoo.org>2011-09-28 18:41:44 (GMT)
commit3be910392f1186cacf0796e952fb5dae38b10f57 (patch)
treef8127a0995d1bf3f60b4bf2fb58e1a10ddf85fbe
parentetc-update: support PAGER env var for bug #384663 (diff)
downloadportage-3be910392f1186cacf0796e952fb5dae38b10f57.zip
portage-3be910392f1186cacf0796e952fb5dae38b10f57.tar.gz
portage-3be910392f1186cacf0796e952fb5dae38b10f57.tar.bz2
dispatch-conf: support PAGER var for bug #384663
-rwxr-xr-xbin/dispatch-conf32
-rw-r--r--cnf/dispatch-conf.conf10
2 files changed, 41 insertions, 1 deletions
diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index 497927d..55d7f13 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 b51b61a..c4ab33f 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