Adds option to open document with another programm.
This commit is contained in:
parent
fed60b7069
commit
1b5e21ab5c
@ -8,20 +8,26 @@ from .. import configs
|
|||||||
def parser(subparsers, config):
|
def parser(subparsers, config):
|
||||||
parser = subparsers.add_parser('open',
|
parser = subparsers.add_parser('open',
|
||||||
help='open the paper in a pdf viewer')
|
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',
|
parser.add_argument('citekey',
|
||||||
help='the paper associated citekey')
|
help='the paper associated citekey')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def command(config, ui, citekey):
|
def command(config, ui, with_command, citekey):
|
||||||
rp = repo.Repository.from_directory(config)
|
rp = repo.Repository.from_directory(config)
|
||||||
paper = rp.paper_from_ref(citekey, fatal=True)
|
paper = rp.paper_from_ref(citekey, fatal=True)
|
||||||
|
if with_command is None:
|
||||||
|
with_command = config.get(configs.MAIN_SECTION, 'open-cmd')
|
||||||
try:
|
try:
|
||||||
filepath = paper.get_document_path()
|
filepath = paper.get_document_path()
|
||||||
subprocess.Popen([config.get(configs.MAIN_SECTION, 'open-cmd'),
|
subprocess.Popen([with_command, filepath])
|
||||||
filepath])
|
ui.print_("%s opened." % ui.colored(filepath, 'filepath'))
|
||||||
print("%s opened." % ui.colored(filepath, 'filepath'))
|
|
||||||
except NoDocumentFile:
|
except NoDocumentFile:
|
||||||
ui.error("No document associated with the entry %s."
|
ui.error("No document associated with the entry %s."
|
||||||
% ui.colored(citekey, 'citekey'))
|
% ui.colored(citekey, 'citekey'))
|
||||||
ui.exit()
|
ui.exit()
|
||||||
|
except OSError:
|
||||||
|
ui.error("Command does not exist: %s." % with_command)
|
||||||
|
ui.exit(127)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user