Make :jseval use a fixed path with relative paths

This commit is contained in:
Florian Bruhin 2017-11-22 09:35:16 +01:00
parent 3b3acba34e
commit 12f4940ef3
4 changed files with 15 additions and 4 deletions

View File

@ -85,6 +85,8 @@ Changed
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
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
~~~~~

View File

@ -639,7 +639,10 @@ Evaluate a JavaScript string.
* +'js-code'+: The string/file to evaluate.
==== 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.
* +*-w*+, +*--world*+: Ignored on QtWebKit. On QtWebEngine, a world ID or name to run the snippet in.

View File

@ -39,7 +39,7 @@ from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate,
webelem, downloads)
from qutebrowser.keyinput import modeman
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
objreg, utils, debug)
objreg, utils, debug, standarddir)
from qutebrowser.utils.usertypes import KeyMode
from qutebrowser.misc import editor, guiprocess
from qutebrowser.completion.models import urlmodel, miscmodels
@ -2029,6 +2029,9 @@ class CommandDispatcher:
Args:
js_code: The string/file to evaluate.
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.
world: Ignored on QtWebKit. On QtWebEngine, a world ID or name to
run the snippet in.
@ -2058,6 +2061,9 @@ class CommandDispatcher:
if file:
path = os.path.expanduser(js_code)
if not os.path.isabs(path):
path = os.path.join(standarddir.data(), 'js')
try:
with open(path, 'r', encoding='utf-8') as f:
js_code = f.read()

View File

@ -118,8 +118,8 @@ Feature: Various utility commands.
And "No output or error" should be logged
Scenario: :jseval --file using a file that doesn't exist as js-code
When I run :jseval --file nonexistentfile
Then the error "[Errno 2] No such file or directory: 'nonexistentfile'" should be shown
When I run :jseval --file /nonexistentfile
Then the error "[Errno 2] No such file or directory: '/nonexistentfile'" should be shown
And "No output or error" should not be logged
# :debug-webaction