From 1b5e21ab5cc064e013caf60d325e4e71cd0efa44 Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Thu, 13 Jun 2013 14:42:53 +0200 Subject: [PATCH] Adds option to open document with another programm. --- papers/commands/open_cmd.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/papers/commands/open_cmd.py b/papers/commands/open_cmd.py index 559fd88..3ecb341 100644 --- a/papers/commands/open_cmd.py +++ b/papers/commands/open_cmd.py @@ -8,20 +8,26 @@ from .. import configs def parser(subparsers, config): parser = subparsers.add_parser('open', help='open the paper in a pdf viewer') + parser.add_argument('-w', '--with', dest='with_command', default=None, + help='command to use to open the document file') parser.add_argument('citekey', help='the paper associated citekey') return parser -def command(config, ui, citekey): +def command(config, ui, with_command, citekey): rp = repo.Repository.from_directory(config) paper = rp.paper_from_ref(citekey, fatal=True) + if with_command is None: + with_command = config.get(configs.MAIN_SECTION, 'open-cmd') try: filepath = paper.get_document_path() - subprocess.Popen([config.get(configs.MAIN_SECTION, 'open-cmd'), - filepath]) - print("%s opened." % ui.colored(filepath, 'filepath')) + subprocess.Popen([with_command, filepath]) + ui.print_("%s opened." % ui.colored(filepath, 'filepath')) except NoDocumentFile: ui.error("No document associated with the entry %s." % ui.colored(citekey, 'citekey')) ui.exit() + except OSError: + ui.error("Command does not exist: %s." % with_command) + ui.exit(127)