From 1e97247c63e321e28aaf947f07f8c8eb95584f7e Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Fri, 5 Aug 2016 18:04:14 +0200 Subject: [PATCH] Revert spawn's splitting, blacklist from doc Blacklist spawn from getting the no_replace_variables doc note. --- doc/help/commands.asciidoc | 5 ++++- qutebrowser/browser/commands.py | 14 +++++++++++--- scripts/dev/src2asciidoc.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 92d4cf02b..c0bb43f6c 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -696,7 +696,7 @@ You can use the `{url}` and `{url:pretty}` variables here which will get replace [[spawn]] === spawn -Syntax: +:spawn [*--userscript*] [*--verbose*] [*--detach*] 'cmdline' ['cmdline' ...]+ +Syntax: +:spawn [*--userscript*] [*--verbose*] [*--detach*] 'cmdline'+ Spawn a command in a shell. @@ -715,6 +715,9 @@ Note the `{url}` and `{url:pretty}` variables might be useful here. `{url}` gets * +*-v*+, +*--verbose*+: Show notifications when the command started/exited. * +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser. +==== note +* This command does not split arguments after the last argument and handles quotes literally. + [[stop]] === stop Stop loading in the current/[count]th tab. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 82062357f..9c031f116 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -991,8 +991,9 @@ class CommandDispatcher: finally: self._tabbed_browser.setUpdatesEnabled(True) - @cmdutils.register(instance='command-dispatcher', scope='window') - def spawn(self, *cmdline, userscript=False, verbose=False, detach=False): + @cmdutils.register(instance='command-dispatcher', scope='window', + maxsplit=0, no_replace_variables=True) + def spawn(self, cmdline, userscript=False, verbose=False, detach=False): """Spawn a command in a shell. Note the `{url}` and `{url:pretty}` variables might be useful here. @@ -1011,7 +1012,14 @@ class CommandDispatcher: detach: Whether the command should be detached from qutebrowser. cmdline: The commandline to execute. """ - cmd, *args = cmdline + try: + cmd, *args = shlex.split(cmdline) + except ValueError as e: + raise cmdexc.CommandError("Error while splitting command: " + "{}".format(e)) + + args = runners.replace_variables(self._win_id, args) + log.procs.debug("Executing {} with args {}, userscript={}".format( cmd, args, userscript)) if userscript: diff --git a/scripts/dev/src2asciidoc.py b/scripts/dev/src2asciidoc.py index 2589d0fc5..84b774a03 100755 --- a/scripts/dev/src2asciidoc.py +++ b/scripts/dev/src2asciidoc.py @@ -240,7 +240,7 @@ def _get_command_doc_notes(cmd): Strings which should be added to the docs. """ if (cmd.maxsplit is not None or cmd.no_cmd_split or - cmd.no_replace_variables): + cmd.no_replace_variables and cmd.name != "spawn"): yield "" yield "==== note" if cmd.maxsplit is not None: @@ -249,7 +249,7 @@ def _get_command_doc_notes(cmd): if cmd.no_cmd_split: yield ("* With this command, +;;+ is interpreted literally " "instead of splitting off a second command.") - if cmd.no_replace_variables: + if cmd.no_replace_variables and cmd.name != "spawn": yield r"* This command does not replace variables like +\{url\}+."