From 4485e4ee1bad6aa2b983aa7616a6f67576c74c27 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 15 Jan 2015 22:28:04 +0100 Subject: [PATCH] Merge :run-userscripts into :spawn. :run-userscripts is now marked as deprecated, and :spawn has a new -u/--userscript option instead. Closes #448. --- doc/help/commands.asciidoc | 16 ++++------------ qutebrowser/browser/commands.py | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index fba2a101a..73cf2205a 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -32,7 +32,6 @@ |<>|Repeat a given command. |<>|Report a bug in qutebrowser. |<>|Restart qutebrowser while keeping existing tabs open. -|<>|Run an userscript given as argument. |<>|Save the config file. |<>|Search for a text on the current page. |<>|Set an option. @@ -351,16 +350,6 @@ Report a bug in qutebrowser. === restart Restart qutebrowser while keeping existing tabs open. -[[run-userscript]] -=== run-userscript -Syntax: +:run-userscript 'cmd' ['args' ['args' ...]]+ - -Run an userscript given as argument. - -==== positional arguments -* +'cmd'+: The userscript to run. -* +'args'+: Arguments to pass to the userscript. - [[save]] === save Save the config file. @@ -404,7 +393,7 @@ Preset the statusbar to some text. [[spawn]] === spawn -Syntax: +:spawn 'args' ['args' ...]+ +Syntax: +:spawn [*--userscript*] 'args' ['args' ...]+ Spawn a command in a shell. @@ -413,6 +402,9 @@ Note the {url} variable which gets replaced by the current URL might be useful h ==== positional arguments * +'args'+: The commandline to execute. +==== optional arguments +* +*-u*+, +*--userscript*+: Run the command as an userscript. + [[stop]] === stop Stop loading in the current/[count]th tab. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 3b8c75df4..9fb88f599 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -795,7 +795,7 @@ class CommandDispatcher: tabbed_browser.setUpdatesEnabled(True) @cmdutils.register(instance='command-dispatcher', scope='window') - def spawn(self, *args): + def spawn(self, userscript=False, *args): """Spawn a command in a shell. Note the {url} variable which gets replaced by the current URL might be @@ -807,21 +807,30 @@ class CommandDispatcher: don't care about the process anymore as soon as it's spawned. Args: + userscript: Run the command as an userscript. *args: The commandline to execute. """ - log.procs.debug("Executing: {}".format(args)) - try: - subprocess.Popen(args) - except OSError as e: - raise cmdexc.CommandError("Error while spawning command: " - "{}".format(e)) + log.procs.debug("Executing: {}, userscript={}".format( + args, userscript)) + if userscript: + if len(args) > 1: + self.run_userscript(args[0], args[1:]) + else: + self.run_userscript(args[0]) + else: + try: + subprocess.Popen(args) + except OSError as e: + raise cmdexc.CommandError("Error while spawning command: " + "{}".format(e)) @cmdutils.register(instance='command-dispatcher', scope='window') def home(self): """Open main startpage in current tab.""" self.openurl(config.get('general', 'startpage')[0]) - @cmdutils.register(instance='command-dispatcher', scope='window') + @cmdutils.register(instance='command-dispatcher', scope='window', + deprecated='Use :spawn --userscript instead!') def run_userscript(self, cmd, *args: {'nargs': '*'}): """Run an userscript given as argument.