Make :jseval use a fixed path with relative paths
This commit is contained in:
parent
3b3acba34e
commit
12f4940ef3
@ -85,6 +85,8 @@ Changed
|
|||||||
again to navigate through completion items when a text was entered.
|
again to navigate through completion items when a text was entered.
|
||||||
- `:debug-pyeval` now has a `--file` arguemnt so it takes a filename instead of
|
- `:debug-pyeval` now has a `--file` arguemnt so it takes a filename instead of
|
||||||
a line of code.
|
a line of code.
|
||||||
|
- `:jseval --file` now searches relative paths in a js/ subdir in qutebrowser's
|
||||||
|
data dir, e.g. `~/.local/share/qutebrowser/js`.
|
||||||
|
|
||||||
Fixed
|
Fixed
|
||||||
~~~~~
|
~~~~~
|
||||||
|
@ -639,7 +639,10 @@ Evaluate a JavaScript string.
|
|||||||
* +'js-code'+: The string/file to evaluate.
|
* +'js-code'+: The string/file to evaluate.
|
||||||
|
|
||||||
==== optional arguments
|
==== optional arguments
|
||||||
* +*-f*+, +*--file*+: Interpret js-code as a path to a file.
|
* +*-f*+, +*--file*+: Interpret js-code as a path to a file. If the path is relative, the file is searched in a js/ subdir
|
||||||
|
in qutebrowser's data dir, e.g.
|
||||||
|
`~/.local/share/qutebrowser/js`.
|
||||||
|
|
||||||
* +*-q*+, +*--quiet*+: Don't show resulting JS object.
|
* +*-q*+, +*--quiet*+: Don't show resulting JS object.
|
||||||
* +*-w*+, +*--world*+: Ignored on QtWebKit. On QtWebEngine, a world ID or name to run the snippet in.
|
* +*-w*+, +*--world*+: Ignored on QtWebKit. On QtWebEngine, a world ID or name to run the snippet in.
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate,
|
|||||||
webelem, downloads)
|
webelem, downloads)
|
||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman
|
||||||
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
||||||
objreg, utils, debug)
|
objreg, utils, debug, standarddir)
|
||||||
from qutebrowser.utils.usertypes import KeyMode
|
from qutebrowser.utils.usertypes import KeyMode
|
||||||
from qutebrowser.misc import editor, guiprocess
|
from qutebrowser.misc import editor, guiprocess
|
||||||
from qutebrowser.completion.models import urlmodel, miscmodels
|
from qutebrowser.completion.models import urlmodel, miscmodels
|
||||||
@ -2029,6 +2029,9 @@ class CommandDispatcher:
|
|||||||
Args:
|
Args:
|
||||||
js_code: The string/file to evaluate.
|
js_code: The string/file to evaluate.
|
||||||
file: Interpret js-code as a path to a file.
|
file: Interpret js-code as a path to a file.
|
||||||
|
If the path is relative, the file is searched in a js/ subdir
|
||||||
|
in qutebrowser's data dir, e.g.
|
||||||
|
`~/.local/share/qutebrowser/js`.
|
||||||
quiet: Don't show resulting JS object.
|
quiet: Don't show resulting JS object.
|
||||||
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
|
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
|
||||||
run the snippet in.
|
run the snippet in.
|
||||||
@ -2058,6 +2061,9 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
if file:
|
if file:
|
||||||
path = os.path.expanduser(js_code)
|
path = os.path.expanduser(js_code)
|
||||||
|
if not os.path.isabs(path):
|
||||||
|
path = os.path.join(standarddir.data(), 'js')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, 'r', encoding='utf-8') as f:
|
with open(path, 'r', encoding='utf-8') as f:
|
||||||
js_code = f.read()
|
js_code = f.read()
|
||||||
|
@ -118,8 +118,8 @@ Feature: Various utility commands.
|
|||||||
And "No output or error" should be logged
|
And "No output or error" should be logged
|
||||||
|
|
||||||
Scenario: :jseval --file using a file that doesn't exist as js-code
|
Scenario: :jseval --file using a file that doesn't exist as js-code
|
||||||
When I run :jseval --file nonexistentfile
|
When I run :jseval --file /nonexistentfile
|
||||||
Then the error "[Errno 2] No such file or directory: 'nonexistentfile'" should be shown
|
Then the error "[Errno 2] No such file or directory: '/nonexistentfile'" should be shown
|
||||||
And "No output or error" should not be logged
|
And "No output or error" should not be logged
|
||||||
|
|
||||||
# :debug-webaction
|
# :debug-webaction
|
||||||
|
Loading…
Reference in New Issue
Block a user