From 6dbdea0ee3fa52d08cc135dba65924792b38395c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 17 Jun 2015 07:57:38 +0200 Subject: [PATCH] Set maxsplit=0 for :spawn and split manually. Fixes #759. --- CHANGELOG.asciidoc | 1 + doc/help/commands.asciidoc | 8 ++++++-- qutebrowser/browser/commands.py | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 70da716b4..234ebee8c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -56,6 +56,7 @@ Changed - The `ui -> user-stylesheet` setting now also takes file paths relative to the config directory. - The `content -> cookies-accept` setting now has new `no-3rdparty` (default) and `no-unknown-3rdparty` values to block third-party cookies. The `default` value got renamed to `all`. - Improved startup time by reading the webpage history while qutebrowser is open. +- The way `:spawn` splits its commandline has been changed slightly to allow commands with flags. Deprecated ~~~~~~~~~~ diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index fe71e8eb0..7fccc2117 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -529,20 +529,24 @@ Preset the statusbar to some text. [[spawn]] === spawn -Syntax: +:spawn [*--userscript*] [*--verbose*] [*--detach*] 'args' ['args' ...]+ +Syntax: +:spawn [*--userscript*] [*--verbose*] [*--detach*] 'cmdline'+ Spawn a command in a shell. Note the {url} variable which gets replaced by the current URL might be useful here. ==== positional arguments -* +'args'+: The commandline to execute. +* +'cmdline'+: The commandline to execute. ==== optional arguments * +*-u*+, +*--userscript*+: Run the command as an userscript. * +*-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. +* With this command, +;;+ is interpreted literally instead of splitting off a second command. + [[stop]] === stop Stop loading in the current/[count]th tab. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index af8815a78..4abb50710 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -21,6 +21,7 @@ import re import os +import shlex import posixpath import functools import xml.etree.ElementTree @@ -919,8 +920,9 @@ class CommandDispatcher: finally: self._tabbed_browser.setUpdatesEnabled(True) - @cmdutils.register(instance='command-dispatcher', scope='window') - def spawn(self, userscript=False, verbose=False, detach=False, *args): + @cmdutils.register(instance='command-dispatcher', scope='window', + maxsplit=0) + def spawn(self, cmdline, userscript=False, verbose=False, detach=False): """Spawn a command in a shell. Note the {url} variable which gets replaced by the current URL might be @@ -930,11 +932,15 @@ class CommandDispatcher: userscript: Run the command as an userscript. verbose: Show notifications when the command started/exited. detach: Whether the command should be detached from qutebrowser. - *args: The commandline to execute. + cmdline: The commandline to execute. """ - log.procs.debug("Executing: {}, userscript={}".format( - args, userscript)) - cmd, *args = args + try: + cmd, *args = shlex.split(cmdline) + except ValueError as e: + raise cmdexc.CommandError("Error while splitting command: " + "{}".format(e)) + log.procs.debug("Executing {} with args {}, userscript={}".format( + cmd, args, userscript)) if userscript: self.run_userscript(cmd, *args, verbose=verbose) else: