From 52f3900c0c7dec8581fa907495a09c900a3d39d7 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 31 Mar 2006 18:42:35 +0100 Subject: [PATCH] Use a pager for diff and show commands This patch also adds a pager configuration option that overrides the default PAGER environment variable. Signed-off-by: Catalin Marinas --- examples/stgitrc | 3 +++ stgit/commands/diff.py | 3 ++- stgit/commands/show.py | 3 ++- stgit/config.py | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/stgitrc b/examples/stgitrc index fdb11b1..568bc16 100644 --- a/examples/stgitrc +++ b/examples/stgitrc @@ -24,6 +24,9 @@ smtpserver: localhost:25 # variable, then default to using 'vi' #editor: /usr/bin/vi +# this value overrides the default PAGER environment variable +#pager: less -S + # Different three-way merge tools below. Uncomment the preferred one. # Note that the 'output' file contains the same data as 'branch1'. This # is useful for tools that do not take an output parameter diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py index 5645eca..7dc6c5d 100644 --- a/stgit/commands/diff.py +++ b/stgit/commands/diff.py @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os from optparse import OptionParser, make_option +from pydoc import pager from stgit.commands.common import * from stgit.utils import * @@ -73,4 +74,4 @@ def func(parser, options, args): if options.stat: print git.diffstat(args, git_id(rev1), git_id(rev2)) else: - git.diff(args, git_id(rev1), git_id(rev2), sys.stdout) + pager(git.diff(args, git_id(rev1), git_id(rev2))) diff --git a/stgit/commands/show.py b/stgit/commands/show.py index 50eb376..9537192 100644 --- a/stgit/commands/show.py +++ b/stgit/commands/show.py @@ -17,6 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys, os from optparse import OptionParser, make_option +from pydoc import pager from stgit.commands.common import * from stgit import git @@ -42,4 +43,4 @@ def func(parser, options, args): parser.error('incorrect number of arguments') commit_id = git_id(patch) - sys.stdout.write(git.pretty_commit(commit_id)) + pager(git.pretty_commit(commit_id)) diff --git a/stgit/config.py b/stgit/config.py index e28633d..66e9f41 100644 --- a/stgit/config.py +++ b/stgit/config.py @@ -40,6 +40,10 @@ config.read('/etc/stgitrc') config.read(os.path.expanduser('~/.stgitrc')) config.read(os.path.join(basedir.get(), 'stgitrc')) +# Set the PAGER environment to the config value (if any) +if config.has_option('stgit', 'pager'): + os.environ['PAGER'] = config.get('stgit', 'pager') + # [gitmergeonefile] section is deprecated. In case it exists copy the # options/values to the [stgit] one if config.has_section('gitmergeonefile'): -- 2.11.0