Shell script snippet question

Hi All!

I’m attempting to create a snippet that calls a command line app I have created. The syntax on the command line looks like this:

groq-cli spellcheck -p "Check this"

This runs perfectly fine in the terminal.

I want to be able to replace the “Check this” with url encoded selected text but what I have come up with so far fails to run:

#!/bin/zsh
# #popclip
# name: Spell Check
# after: paste-result
groq-cli spellcheck -p ${POPCLIP_URLENCODED_TEXT}

I’m fairly new to creating snippets so it may be my lack of knowledge about the platform that is tripping me up.

Any help or pointers would be greatly appreciated!

Thanks!
Gary

1 Like

I’m sure we can get to the bottom of it together. To start with, I suggest enabling extension debug output so you can view any error output from the script in the Console, as per Debug output.

As an example, the screenshot below shows what I get when I run your snippet. However, I do not have a groq-cli command in my path so this error iis to be expected in my case (I web searched it, but there seem to be many things called that, so I didn’t go further.)

Once you have an error message, it may give us something to go on.

Hi Nick!

Here is the error message from the console app:

Stderr:
Traceback (most recent call last):
File “/Users/garythompson/.local/bin/groq-cli”, line 10, in
sys.exit(main())
~~~~^^
File “/Users/garythompson/Documents/python_local/uv_projects/groq_cli/src/groq_cli/init.py”, line 113, in main
cli()
~~~^^
File “/Users/garythompson/.local/share/uv/tools/groq-cli/lib/python3.13/site-packages/click/core.py”, line 1161, in call
return self.main(*args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^
File “/Users/garythompson/.local/share/uv/tools/groq-cli/lib/python3.13/site-packages/click/core.py”, line 1082, in main
rv = self.invoke(ctx)
File “/Users/garythompson/.local/share/uv/tools/groq-cli/lib/python3.13/site-packages/click/core.py”, line 1697, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File “/Users/garythompson/.local/share/uv/tools/groq-cli/lib/python3.13/site-packages/click/core.py”, line 1443, in invoke
<…>

It appears that my snippet isn’t passing the text along to my cli app which is written in Python.

Normally in the terminal if the command doesn’t get any input it returns a help message and exists gracefully so I’m not sure what is going on.

Thanks!
Gary

The error messages mentioning groq-cli Python tool suggest the tool is being called. Why do you suspect text is not being passed to the script?

Were there more entries in the call stack or did PopClip cut it off there? The final entries may be the most useful of all!

You can check the exact value of POPCLIP_URLENCODED_TEXT in the Console under the “Launching Task” entry:

You can also try saving the snippet to a file and invoking it like this from a Terminal:

POPCLIP_URLENCODED_TEXT="sample%20urlencoded%20text" ./mysnippet.zsh

This way we are testing the exact same script.

As aside, I’m curious why the text needs to be URL-encoded when in your example "Check this" is not url-encoded and URL-encoding is not a common requirement for CLI tools. Could this be anything to do with the problem?

Hi Nick,

I suspect the text isn’t being sent because when I was developing the cli I would get the same errors until I added additional try/except calls. What’s weird though is the call from the snippet is triggering the same error I used to get when I was initially developing the tool.

What I sent you is what the console app showed for the error. I see the same truncating in the “Launching Task” entry which leaves off the POPCLIP_URLENCODED_TEXT entry.

Do you know of any way to force the console to show the entire error/message?

As for the url encoding a lot of times there are single and double quotes in the text I’m ingesting which breaks the command. It runs fine if url encoding is applied. In fact I just tried the exact url encoded text on the command line I was sending via the snippet and it worked fine.

I also have a test snippet that echos back the url-encoded text perfectly:

#!/bin/zsh
# #popclip
# name: Helloworld in zsh
# after: show-result
echo -n "${POPCLIP_URLENCODED_TEXT}!"  # `-n` for no newline at end

Thanks!
Gary

Here are some additional findings.

I have 3 commands available within my cli:

chat - which takes 2 options
spellcheck - which takes 1 option
models - which has no options

I changed my snippet to use the models command:

#!/bin/zsh
# #popclip
# name: Groq Models
# after: show-result
groq-cli models

and it still errors out without passing any url encoded text. Could this have anything to do with the arguments I am passing to the cli causing some kind of issue?

Thanks!
Gary

I suspect it might be something PopClip is doing wrong rather than something you are doing wrong. Is the groq-cli tool you are using publicly available? If so, where can I get it? I would like to grab it so I can test these snippets out myself.