Menu

#42 Use Stdin for action input

Future_Release
open
Parcellite (1)
2
2013-03-17
2010-02-21
No

When I copy a string with a curly brace (e.g. ${test.id}) and pass this on to an action such as "echo "%s" >> /tmp/test.txt" the shell closes with a bad substitution error.

To solve this problem all shell interpreted variables should be escaped with a back slash. I was looking for a method in the standard libraries with such a functionality. Unfortunately I could not find one. Otherwise I would have attached a patch ;). Writing a method which does this escaping is not really a good solution but might be the only way.

Discussion

  • Sarah Strong

    Sarah Strong - 2010-08-24

    Reproduced on v0.9.2 Friday, January 01 2010 on Ubuntu 10.04.

    Steps:
    1. Start parcellite with command `parcellite`, unforked.
    2. Create action echo "%s" >> ~/test through Parcellite icon's preferences.
    3. Copy "${test.id}"
    4. Observe that "${test.id}" is not appended to ~/test as expected, and that Parcellite process reports "/bin/sh: Bad substitution". Parcellite does, however, remain open and working.

     
  • rickyrockrat

    rickyrockrat - 2010-12-13
    • assigned_to: xyhthyx --> rickyrockrat
     
  • rickyrockrat

    rickyrockrat - 2010-12-13

    Add option to escape shell vars in action menu

     
  • rickyrockrat

    rickyrockrat - 2013-01-09
    • priority: 5 --> 2
     
  • Oliver

    Oliver - 2013-02-26

    I tested 1.0.2rc5 on Mint 13. The described use-case can be solved by using single quotes instead of double quotes. Simply create the action:
    echo '%s' >> ~/test

    But I also came across usecases where the %s substitution is not very convenient. Parcellite could feed the clipboard content through /dev/stdin to the action command! Would be very handy for commands that eat files, escaping is not necessary this way, and AFAIK this solution would not interfere with the current %s. (If wanted we can open a new bug for this)

     

    Last edit: Oliver 2013-02-26
  • rickyrockrat

    rickyrockrat - 2013-03-11

    Please try this and let me know if /dev/stdin is a solution. If so, I'll add an option for putting it though stdin.

    Also, does this bug still exists in 1.1.4? It now uses g_shell_quote, which should take care of the shell quoting.

     
  • Oliver

    Oliver - 2013-03-17

    I tested the quite old 0.9.3 in Ubuntu 11.04 and as I wrote in my previous comment this is not a bug (anymore?), but insufficient documentation:
    Use double quotes "%s" to expand env variables like $HOME to /home/your_name
    Use single quotes '%s' to feed your action with env variables as-is

     
  • Oliver

    Oliver - 2013-03-17

    I implemented the new feature to feed clipboard text to an action through /dev/stdin. I tested my patch with latest svn rev379 under Linux (Mint 14). You do not have to add an option for this new feature. Since it is perfectly legal to ignore standard input, nothing will change for existing actions.

    With my patch it is possible to omit %s and use "-" (short for /dev/stdin):

    Action Command
    Testaction cat - >>/tmp/test.txt

    One advantage is that the command will get clipboard text exactly as it is. Env vars won't be expanded, no line feeds will be added, ect. And stdin allows to use commands that won't work with %s (like dd).

    Before you apply my patch, please have a look at my code. I tried to prevent problems like memory leaks, but I am not so experienced with GTK+ in C. And it would help if someone could test it on Windows or with locales other than utf8 or latin1. ATM I write to stdin using the default text encoding (utf8 in Linux).

    +++ Oliver

     
  • rickyrockrat

    rickyrockrat - 2013-03-17

    Ticket moved from /p/parcellite/bugs/33/

     
  • rickyrockrat

    rickyrockrat - 2013-03-17
    • summary: some action calls lead to an bad substitution error --> Use Stdin for action input
    • milestone: Development_Version --> Future_Release
     

Log in to post a comment.