Merge remote-tracking branch 'origin/pr/4129'
This commit is contained in:
commit
748d80c08f
@ -1200,6 +1200,9 @@ Spawn a command in a shell.
|
|||||||
* +*-o*+, +*--output*+: Whether the output should be shown in a new tab.
|
* +*-o*+, +*--output*+: Whether the output should be shown in a new tab.
|
||||||
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
|
* +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser.
|
||||||
|
|
||||||
|
==== count
|
||||||
|
Given to userscripts as $QUTE_COUNT.
|
||||||
|
|
||||||
==== note
|
==== note
|
||||||
* This command does not split arguments after the last argument and handles quotes literally.
|
* This command does not split arguments after the last argument and handles quotes literally.
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ In `command` mode:
|
|||||||
- `QUTE_URL`: The current URL.
|
- `QUTE_URL`: The current URL.
|
||||||
- `QUTE_TITLE`: The title of the current page.
|
- `QUTE_TITLE`: The title of the current page.
|
||||||
- `QUTE_SELECTED_TEXT`: The text currently selected on the page.
|
- `QUTE_SELECTED_TEXT`: The text currently selected on the page.
|
||||||
|
- `QUTE_COUNT`: The `count` from the spawn command running the userscript.
|
||||||
|
|
||||||
In `hints` mode:
|
In `hints` mode:
|
||||||
|
|
||||||
|
@ -1173,8 +1173,9 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
maxsplit=0, no_replace_variables=True)
|
maxsplit=0, no_replace_variables=True)
|
||||||
|
@cmdutils.argument('count', count=True)
|
||||||
def spawn(self, cmdline, userscript=False, verbose=False,
|
def spawn(self, cmdline, userscript=False, verbose=False,
|
||||||
output=False, detach=False):
|
output=False, detach=False, count=None):
|
||||||
"""Spawn a command in a shell.
|
"""Spawn a command in a shell.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -1188,6 +1189,7 @@ class CommandDispatcher:
|
|||||||
output: Whether the output should be shown in a new tab.
|
output: Whether the output should be shown in a new tab.
|
||||||
detach: Whether the command should be detached from qutebrowser.
|
detach: Whether the command should be detached from qutebrowser.
|
||||||
cmdline: The commandline to execute.
|
cmdline: The commandline to execute.
|
||||||
|
count: Given to userscripts as $QUTE_COUNT.
|
||||||
"""
|
"""
|
||||||
cmdutils.check_exclusive((userscript, detach), 'ud')
|
cmdutils.check_exclusive((userscript, detach), 'ud')
|
||||||
try:
|
try:
|
||||||
@ -1211,7 +1213,7 @@ class CommandDispatcher:
|
|||||||
if userscript:
|
if userscript:
|
||||||
def _selection_callback(s):
|
def _selection_callback(s):
|
||||||
try:
|
try:
|
||||||
runner = self._run_userscript(s, cmd, args, verbose)
|
runner = self._run_userscript(s, cmd, args, verbose, count)
|
||||||
runner.finished.connect(_on_proc_finished)
|
runner.finished.connect(_on_proc_finished)
|
||||||
except cmdexc.CommandError as e:
|
except cmdexc.CommandError as e:
|
||||||
message.error(str(e))
|
message.error(str(e))
|
||||||
@ -1238,19 +1240,23 @@ class CommandDispatcher:
|
|||||||
"""Open main startpage in current tab."""
|
"""Open main startpage in current tab."""
|
||||||
self.openurl(config.val.url.start_pages[0])
|
self.openurl(config.val.url.start_pages[0])
|
||||||
|
|
||||||
def _run_userscript(self, selection, cmd, args, verbose):
|
def _run_userscript(self, selection, cmd, args, verbose, count):
|
||||||
"""Run a userscript given as argument.
|
"""Run a userscript given as argument.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmd: The userscript to run.
|
cmd: The userscript to run.
|
||||||
args: Arguments to pass to the userscript.
|
args: Arguments to pass to the userscript.
|
||||||
verbose: Show notifications when the command started/exited.
|
verbose: Show notifications when the command started/exited.
|
||||||
|
count: Exposed to the userscript.
|
||||||
"""
|
"""
|
||||||
env = {
|
env = {
|
||||||
'QUTE_MODE': 'command',
|
'QUTE_MODE': 'command',
|
||||||
'QUTE_SELECTED_TEXT': selection,
|
'QUTE_SELECTED_TEXT': selection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if count is not None:
|
||||||
|
env['QUTE_COUNT'] = str(count)
|
||||||
|
|
||||||
idx = self._current_index()
|
idx = self._current_index()
|
||||||
if idx != -1:
|
if idx != -1:
|
||||||
env['QUTE_TITLE'] = self._tabbed_browser.widget.page_title(idx)
|
env['QUTE_TITLE'] = self._tabbed_browser.widget.page_title(idx)
|
||||||
|
11
tests/end2end/data/userscripts/hello_if_count
Executable file
11
tests/end2end/data/userscripts/hello_if_count
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$QUTE_COUNT" -eq 5 ]; then
|
||||||
|
|
||||||
|
echo "message-info 'Count is five!'" >> "$QUTE_FIFO"
|
||||||
|
|
||||||
|
elif [ -z "$QUTE_COUNT" ]; then
|
||||||
|
|
||||||
|
echo "message-info 'No count!'" >> "$QUTE_FIFO"
|
||||||
|
|
||||||
|
fi
|
@ -47,6 +47,17 @@ Feature: :spawn
|
|||||||
- data/hello.txt
|
- data/hello.txt
|
||||||
- data/hello.txt (active)
|
- data/hello.txt (active)
|
||||||
|
|
||||||
|
@posix
|
||||||
|
Scenario: Running :spawn with userscript and count
|
||||||
|
When I run :spawn -u (testdata)/userscripts/hello_if_count with count 5
|
||||||
|
Then the message "Count is five!" should be shown
|
||||||
|
|
||||||
|
@posix
|
||||||
|
Scenario: Running :spawn with userscript and no count
|
||||||
|
When I run :spawn -u (testdata)/userscripts/hello_if_count
|
||||||
|
Then the message "No count!" should be shown
|
||||||
|
|
||||||
|
|
||||||
@windows
|
@windows
|
||||||
Scenario: Running :spawn with userscript on Windows
|
Scenario: Running :spawn with userscript on Windows
|
||||||
When I open data/hello.txt
|
When I open data/hello.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user