dozius / keypirinha-snippets

A Keypirinha plugin to quickly copy user defined snippets to the clipboard
MIT License
19 stars 1 forks source link

Interpreting Snippet String #1

Closed ccarpo closed 5 years ago

ccarpo commented 5 years ago

Hello there,

Setup

I try to create a snippet with the following String:

[snippet/OhMyZshInstall]
string = sh -c "$(curl -fsSL `https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Problem

Keypirinha try to parse this and produces the following error:

11:49:16.877 WARNING: Error while extracting settings from package Snippets. Error: <class 'configparser.InterpolationSyntaxError'>: '$' must be followed by '$' or '{', found: '$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"' Traceback (most recent call last): File "lib\configparser.py", line 800, in get File "lib\configparser.py", line 455, in before_get File "lib\configparser.py", line 518, in _interpolate_some

What I tried

I tried to set single quotes or double quotes (replacing the existing double quotes with single quotes) around the whole string and to escape the $ with \ Non of that worked.

Expected Behaviour

Description how to deal with such issues or a fix to ignore this issue.

dozius commented 5 years ago

This is outside the scope of the plugin. The plugin is using the Keypirinha API to parse the settings.

I would suggest reading Keypirinha's documentation for the INI format used in configuration files. This will tell you how to properly escape things.

polyvertex commented 5 years ago

@ccarpo the $ character must be escaped by doubling it. The aforementioned error message gives you the workaround to be applied: '$' must be followed by '$' or '{'.

This should do (untested):

[snippet/OhMyZshInstall]
string = sh -c "$$(curl -fsSL 'https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh')"

Notice the $$ sequence. I also quoted the URL.

generic-user commented 3 years ago

configparser.ExtendedInterpolation

Hello, I would like to summarize some extra info about this for fellow users.

Looks like Keypirinha uses configparser.ExtendedInterpolation. That means u need to escape the $, as mentioned by the others, and as explained in the documentation linked below.

$ is the only character that needs to be escaped

Documentation link

For extra info: https://docs.python.org/3/library/configparser.html#configparser.ExtendedInterpolation

Excerpt documentation

[Escape]
cost: $$80  # use a $$ to escape the $ sign ($ is the only character that needs to be escaped)