Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use forms and shell at the same time? #1802

Closed
moshpirit opened this issue Jan 1, 2024 · 5 comments
Closed

How to use forms and shell at the same time? #1802

moshpirit opened this issue Jan 1, 2024 · 5 comments
Labels
question Further information is requested

Comments

@moshpirit
Copy link

It would be cool if we could write down something like ";command", and then if showed up a form where we entered something and then get a replacement with the output of the bash command.

@smeech
Copy link
Collaborator

smeech commented Jan 3, 2024

It's not too difficult. Here's a script I wrote in response to a user's query on Discord recently, which builds on the examples in the docs:

  - trigger: :atest
    replace: "{{output}}"
    vars:
      - name: form1
        type: form
        params:
          layout: "[[choices]]"
          fields:
            choices:
              type: choice
              values: |
                one
                two
                three
      - name: output
        type: shell
        params:
          cmd: echo $"{{form1.choices}}" | sed 's/one/four/;s/two/five/;s/three/six/'

By making the form a named variable, it takes its output and makes it available for a script to change the output for the replace:. If you want to try it, the last line may need altering to suit your OS and shell, but it illustrates the principle.

@smeech smeech added the question Further information is requested label Jan 3, 2024
@smeech
Copy link
Collaborator

smeech commented Jan 4, 2024

If this answers your question, I'll close the Issue. If I've misunderstood, please let me know!

@moshpirit
Copy link
Author

moshpirit commented Jan 5, 2024

Sorry, I couldn't check it until now.

I copied/pasted it in a new file called scripts.yml in the same folder, but got this error: [Espanso]: An error occurred during rendering, please examine the logs for more information. I tried it with the three options and still got the same result. I also added the force_mode: clipboard that we talked about in another issue.

EDIT: found the log!

12:06:34 [worker(56269)] [ERROR] shell command exited with code: exit status: 2 and error: bash: -c: línea 1: EOF inesperado mientras se buscaba un `'' coincidente

12:06:34 [worker(56269)] [WARN] extension 'shell' on var: 'output' reported an error: command reported error: '`bash: -c: línea 1: EOF inesperado mientras se buscaba un `'' coincidente
`'
12:06:34 [worker(56269)] [ERROR] error during rendering: rendering error

Caused by:
    command reported error: '`bash: -c: línea 1: EOF inesperado mientras se buscaba un `'' coincidente
    `'

English translation:

12:06:34 [worker(56269)] [ERROR] shell command exited with code: exit status: 2 and error: bash: -c: line 1: Unexpected EOF while searching for a matching ``''

12:06:34 [worker(56269)] [WARN] extension 'shell' on var: 'output' reported an error: command reported error: '`bash: -c: line 1: Unexpected EOF while searching for a `' ' coincident
''
12:06:34 [worker(56269)] [ERROR] error during rendering: rendering error

Caused by:
     command reported error: '`bash: -c: line 1: Unexpected EOF while searching for a matching `''
     ''

@smeech
Copy link
Collaborator

smeech commented Jan 5, 2024

Apologies - I failed to copy the final "'" (single inverted comma) at the end of the last line. I've added it above and checked it works here.

@moshpirit
Copy link
Author

Thanks! I think this should be added to the documentation, it's an amazing tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants