From 6be5c65c3632ce53b29dceb7c162cc482fc0efff Mon Sep 17 00:00:00 2001 From: Peter Michely Date: Wed, 7 Oct 2015 23:53:21 +0200 Subject: [PATCH 1/3] Fixed issue #943 and changed the docs accordingly --- doc/help/commands.asciidoc | 4 ++-- doc/userscripts.asciidoc | 4 ++++ qutebrowser/commands/userscripts.py | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 012522909..3c3a8bd8f 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -261,7 +261,7 @@ Start hinting. - With `spawn`: The executable and arguments to spawn. `{hint-url}` will get replaced by the selected URL. - - With `userscript`: The userscript to execute. + - With `userscript`: The userscript to execute. Either store the userscript in your data directory or use an absolute path. - With `fill`: The command to fill the statusbar with. `{hint-url}` will get replaced by the selected URL. @@ -580,7 +580,7 @@ Note the {url} variable which gets replaced by the current URL might be useful h * +'cmdline'+: The commandline to execute. ==== optional arguments -* +*-u*+, +*--userscript*+: Run the command as a userscript. +* +*-u*+, +*--userscript*+: Run the command as a userscript. Either store it in your data directory or use an absolute path. * +*-v*+, +*--verbose*+: Show notifications when the command started/exited. * +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser. diff --git a/doc/userscripts.asciidoc b/doc/userscripts.asciidoc index 97c820898..928315d33 100644 --- a/doc/userscripts.asciidoc +++ b/doc/userscripts.asciidoc @@ -15,6 +15,10 @@ mpv, a simple key binding to something like `:spawn mpv {url}` should suffice. Also note userscripts need to have the executable bit set (`chmod +x`) for qutebrowser to run them. +To call a userscript, it needs to be stored in your data directory under +`userscripts` (for example: `~/.local/share/qutebrowser/userscripts/myscript`), +or just use an absolute path. + Getting information ------------------- diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 9f2b0fe10..21d754182 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -344,6 +344,14 @@ def run(cmd, *args, win_id, env, verbose=False): if user_agent is not None: env['QUTE_USER_AGENT'] = user_agent cmd = os.path.expanduser(cmd) + + # check if userscript is in absolute path or in $XDG_DATA_DIRS + if not os.path.isabs(cmd) : + log.misc.debug("{} is no absoulte path".format(cmd)) + c = os.path.join(standarddir.data(),"userscripts", cmd) + if os.path.isfile(c): + cmd = c + runner.run(cmd, *args, env=env, verbose=verbose) runner.finished.connect(commandrunner.deleteLater) runner.finished.connect(runner.deleteLater) From 10f4798559493e8cd2708d8be4a083b6a156dd87 Mon Sep 17 00:00:00 2001 From: Peter Michely Date: Thu, 8 Oct 2015 01:10:44 +0200 Subject: [PATCH 2/3] Fixed whitespace errors --- qutebrowser/commands/userscripts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 21d754182..564e2f366 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -346,9 +346,9 @@ def run(cmd, *args, win_id, env, verbose=False): cmd = os.path.expanduser(cmd) # check if userscript is in absolute path or in $XDG_DATA_DIRS - if not os.path.isabs(cmd) : + if not os.path.isabs(cmd): log.misc.debug("{} is no absoulte path".format(cmd)) - c = os.path.join(standarddir.data(),"userscripts", cmd) + c = os.path.join(standarddir.data(), "userscripts", cmd) if os.path.isfile(c): cmd = c From bfccb91e421d7c30730659fb0ec06e41f226eedc Mon Sep 17 00:00:00 2001 From: Peter Michely Date: Thu, 8 Oct 2015 10:13:47 +0200 Subject: [PATCH 3/3] Changed code and docs according to comments --- doc/help/commands.asciidoc | 4 ++-- qutebrowser/browser/commands.py | 4 +++- qutebrowser/browser/hints.py | 5 ++++- qutebrowser/commands/userscripts.py | 9 ++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 3c3a8bd8f..012522909 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -261,7 +261,7 @@ Start hinting. - With `spawn`: The executable and arguments to spawn. `{hint-url}` will get replaced by the selected URL. - - With `userscript`: The userscript to execute. Either store the userscript in your data directory or use an absolute path. + - With `userscript`: The userscript to execute. - With `fill`: The command to fill the statusbar with. `{hint-url}` will get replaced by the selected URL. @@ -580,7 +580,7 @@ Note the {url} variable which gets replaced by the current URL might be useful h * +'cmdline'+: The commandline to execute. ==== optional arguments -* +*-u*+, +*--userscript*+: Run the command as a userscript. Either store it in your data directory or use an absolute path. +* +*-u*+, +*--userscript*+: Run the command as a userscript. * +*-v*+, +*--verbose*+: Show notifications when the command started/exited. * +*-d*+, +*--detach*+: Whether the command should be detached from qutebrowser. diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 5307d0c8e..dac9edd9a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -948,7 +948,9 @@ class CommandDispatcher: useful here. Args: - userscript: Run the command as a userscript. + userscript: Run the command as a userscript. Either store the + userscript in ~/.local/share/qutebrowser/userscripts + (or $XDG_DATA_DIR), or use an absolute path. verbose: Show notifications when the command started/exited. detach: Whether the command should be detached from qutebrowser. cmdline: The commandline to execute. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index fdc2014a4..46eca6b7e 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -749,7 +749,10 @@ class HintManager(QObject): - With `spawn`: The executable and arguments to spawn. `{hint-url}` will get replaced by the selected URL. - - With `userscript`: The userscript to execute. + - With `userscript`: The userscript to execute. Either store + the userscript in + ~/.local/share/qutebrowser/userscripts (or + $XDG_DATA_DIR), or use an absolute path. - With `fill`: The command to fill the statusbar with. `{hint-url}` will get replaced by the selected URL. diff --git a/qutebrowser/commands/userscripts.py b/qutebrowser/commands/userscripts.py index 564e2f366..88ad04d93 100644 --- a/qutebrowser/commands/userscripts.py +++ b/qutebrowser/commands/userscripts.py @@ -345,12 +345,11 @@ def run(cmd, *args, win_id, env, verbose=False): env['QUTE_USER_AGENT'] = user_agent cmd = os.path.expanduser(cmd) - # check if userscript is in absolute path or in $XDG_DATA_DIRS + # if cmd is not given as an absolute path, look it up + # ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR) if not os.path.isabs(cmd): - log.misc.debug("{} is no absoulte path".format(cmd)) - c = os.path.join(standarddir.data(), "userscripts", cmd) - if os.path.isfile(c): - cmd = c + log.misc.debug("{} is no absolute path".format(cmd)) + cmd = os.path.join(standarddir.data(), "userscripts", cmd) runner.run(cmd, *args, env=env, verbose=verbose) runner.finished.connect(commandrunner.deleteLater)