Hi there. The execution of a shell command using espanso seems to be broken under Windows 10. Using the default.yml file, with the default setting:
# Shell commands
- trigger: ":shell"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "echo Hello from your shell"
when you type ":shell" this error will appear:
"Hello" is not recognized as an internal or external command, operable program or batch file.
Hey,
Thanks for the report. I tried to reproduce the problem but I'm unable to do so, as the example you proposed works correctly for me on Windows.
Are you trying to use it in a terminal?
Thanks to you for the support. Yes, i'm using the standard "cmd" terminal. I just tried with "powershell" too and this is the result:
PS C:\Users\User> Hello from your shell
Hello : The term 'Hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
In line:1 car:1
As you can see from the log, the echo command appears in the powershell terminal followed by this error. I've tried to delete the "default.yml" config file and let the program recreates it, but still nothing, same results.
All right, probably a little bit of clarification will make things more clear:
The shell extension is not used to type things in the terminal, but rather to execute the command you specify and then insert the output of this command as an extension.
You don't need to use a shell extension to type things in the terminal, just use a normal match:
- trigger: ":hello"
replace: "Hello from your shell"
Your example return an error, because what happens is that espanso executes "echo Hello from your shell", which produces "Hello from your shell" as an output (with a newline at the end, which simulates an enter command).
As a result, the current terminal you are in will try to interpret "Hello from your shell" as a command, which of course is not valid.
I'm not sure if it is clear at this point, could you please explain what are you trying to accomplish?
Yes, i understand the differences. I was trying to execute a very long command like:
scoop update && scoop update * && scoop cleanup * && scoop cache rm *
but doesn't work, that's why i tried the default config and realize that it doesn't work either. As you point out, the standard replacement works good.
Glad you sorted that out :) Let me know if you have other doubts, I'm going to close the issue for now
@federico-terzi
Only the standard replacement works. This config doesn't:
- trigger: ":shell"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "scoop update && scoop update * && scoop cleanup * && scoop cache rm *"
With this config, when i type ":shell", it should replace the text with the specified command, then execute it and show the result of that command in the same window but it seems it doesn't work like this. Maybe (it's just a suggestion) is more simple adding somesort of an option which sends the "enter key" input after a line is replaced, something like:
- trigger: ":hello"
replace: "echo blablabla"
send: "enterkey"
Hey,
I'm not sure I understood correctly. Do you want espanso to execute scoop update && scoop update * && scoop cleanup * && scoop cache rm * or to just paste it in the terminal?
Cheers
@federico-terzi yes, espanso should paste in the terminal that command, then execute it. Something like:
C:>:shell (espanso will transform into)
C:>scoop update && scoop update * && scoop cleanup * && scoop cache rm *
C:> espanso will send "enterkey" input without any other user interaction and the command will run.
All right, now I understand what you are trying to do. Could you please try using this match:
- trigger: ":shell"
replace: "scoop update && scoop update * && scoop cleanup * && scoop cache rm *\n"
@federico-terzi yep, exactly like this. Works perfectly! Thank you very much for the great support!
You're welcome :)
Most helpful comment
All right, now I understand what you are trying to do. Could you please try using this match: