Closed eshapard closed 3 years ago
OK, I figured out how to make it work. I just had to escape the variables (with the backslash) and let the shell be responsible for them.
:sh bash -c "echo '\${VIMB_SELECTION}' > $HOME/test.txt
I guess this can be closed now, unless this wasn't your intended behavior. If this is the intended behavior, maybe I'll try to add a little something to the documentation somewhere and make a pull request so you don't get this question again. Let me know...
Thanks!
@eshapard Thank you for reporting this issue. I have to admit that this behavior is not intended. But it is so by design. It's expensive to get the selection from the webetension into the UI process to fill the env var. So this is only done in case a shell command is executed and not every time a user changes a selection. So the unescaped $VIMB_SELECTION
in the sehll command is evaluated by vimb itself to get the command to run by the shell. So the var is expanded right before it is set. But this is only a corner cast because $VIMB_SELECTION
is the only variable that is only set before a shell command is executed - other vars are set right at the moment their value is changes.
OK, it seems like a very minor issue to just escape the variable. I suppose just having this issue in the closed issues history is probably enough, but I'll see if I can figure out a good place to add something about this in the documentation. Do you think the manpage is the right place? I'm thinking maybe a little note at the bottom of the :sh[ellcmd]
section and maybe an example just to be sure.
Something like:
:sh[ellcmd]
...existing content...
Note:
VIMB_SELECTION is set just before running a shell command, so
$VIMB_SELECTION should be escaped as \$VIMB_SELECTION to
ensure that Vimb does not expand the variable before it is set.
Example:
:sh sh -c 'echo "\$VIMB_SELECTION" >> myhighlights.txt'
Steps to reproduce
Using vimb 3.6.0-32-g55fb9cc
Step 1: select text and run something like:
When I do this, the first time, the resulting file has no text.
Step 2: Select new text and run the above command again. The previously selected text is written to the test.txt file.
Step 3: Select a different set of text and run command. The text selected in Step 2 is written to the file.
Expected behaviour
Replace ${VIMB_SELECTION} with currently selected text.
Actual behaviour
${VIMB_SELECTION} seems to be replaced with previously selected text.
Comments
I think this is a great new feature, and I'm hoping it's just user-error on my part.
Am I doing something wrong? Is there a step that I should be doing to 'save' the currently selected text somehow?
Thanks so much for your hard work on vimb! It's my default browser. :-)