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
pipe in shell extension fails silently #233
Comments
Hey @NeoTeo, I tried your exact match on my Linux machine and it works as expected: The only thing I did was fixing the indentation a bit: - trigger: ":tst"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "curl -s 'https://api.chucknorris.io/jokes/random' | jq '.value'" Could you check Cheers :) |
Thanks for the quick reply.
|
All right, I'll test it on my macOS machine soon and let you know once I discover something. Cheers :) |
For what it's worth I've now tried it on two different Macs: one running Mojave 10.14.6 and another running Catalina 10.15.5. Both system Terminal app, tried both bash and fish shell (I'm assuming Espanso uses bash when it shells out) |
Hey, Cheers :) |
@NeoTeo I think I've got it! It's most probably due to Environmental variables. Luckily, the fix is very easy, just include the complete path for the commands (easy to find, just type - trigger: ":tst"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "/usr/bin/curl -s 'https://api.chucknorris.io/jokes/random' | /usr/local/bin/jq '.value'" Make sure to verify the above paths with yours. Let me know if that helps :) |
That was it! Will the next version of espanso inherit the $PATH or do we just get used to adding the full path ourselves (in which case it should probably be mentioned in the docs)? Thanks again for the fast turn-around, for the fix and for the excellent tool! :) teo |
Glad to hear that! I'll definitely try to make it include the PATH in the next version, as it's what most users would expect. If for any reason this turn out difficult/impossible, I'll mention it in the docs :)
You're welcome :) Thanks for reporting this problem. I'll keep the issue open so that I can keep a track of it |
It's normal behavior, the process is executed in a limited environment. If you run the command on the terminal, your profile file Or other options, set absolute paths in the command as you do, or I think you can define this in the program before executing the command like nodeJS, but as there are more simple solutions... It's true that without an error message, it could be hard to see where is the problem. But it's not really a bug. Example with Espanso LaunchAgent on macOS <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>CONFIG</key>
<string>/Users/<username>/Library/Preferences/espanso</string>
<key>PATH</key>
<string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
</dict>
<key>Label</key>
<string>com.federicoterzi.espanso</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/espanso</string>
<string>daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/espanso.err</string>
<key>StandardOutPath</key>
<string>/tmp/espanso.out</string>
</dict>
</plist> And when the shell script is run you get: SHELL=/bin/zsh
USER=<username>
SSH_AUTH_SOCK=/private/tmp/...
CONFIG=/Users/<username>/Library/Preferences/espanso
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
GLOBAL_VAR=A_GLOBAL_VAR
PWD=/
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/<username>
LOGNAME=<username>
_=/usr/bin/env I think you can just add |
That's exactly what I thought, thanks for pointing that out.
In the last version, I added an error for this kind of situations in the log, so it should be much easier to diagnose 👍
This is a good approach indeed. I'm wondering whether it could be a good idea to load those variables from the What do you think about this approach @atika ? |
I am often taken to write daemon unit for ubuntu or my raspberry and this is the regular approach to set environment variables. You set variables for a specific environment. Obviously macOS does not include the path to The shell profiles files like The simple approach for this to work for everyone is just to add this specific directory |
Thanks for the in-depth explanation @atika . I agree with you, better to keep My only concern about adding For sure, all these strange behaviors must be accurately documented in the docs. |
Yes, I was trying to express my point of view... As an example, default paths on my ubuntu server: # /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
LC_ALL=en_GB.UTF-8
LANG=en_GB.UTF-8 By default, And also in a new installation of macOS: #cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
# echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin For me, I already have the If you want the user to be able to execute their own commands directly (custom script in other directories), you have to modify the program: adding an option, modifying the environment each time a script is executed, etc. Is the work worth it? There is a lot of program like this in macOS, it's rare to have an option to define custom PATH to custom commands. |
These are indeed fair points. At this point, I think it's pretty safe to include the Then I'll make sure to update the docs to make the situation more clear. Do you think this is a reasonable solution? Thanks for your help :) |
The term
It's true that by modifying the LaunchAgent and if the user set global environment variables like this:
The changes will be overwritten. Yes, If you really want to do this in Rust (I can't help you with this, this gave me a headache trying to understand the code 😁), you have 2 options:
The initial issue, and I encountered the same problem, was that there is no error message to help to find the error. The problem is resolved. Just another thing, a proposal. Why not take the opportunity to add a CONFIG and DATA environment variable, like this we can use it in our scripts and shell command, in the spirit to sync config between machine. |
All you said is correct. Luckily, it's pretty simple to do in Rust when spawning a command (you can see this example). What I would probably do is setting I'm wondering whether also on Linux we have the same problem. From what I can remember, a Systemd-spawned espanso was able to find the commands so the PATH should be all right there, but I may be wrong. What do you think?
Indeed now it should be easier to track down.
Could you explain this point a bit more? It might be a good idea to open a separate issue Cheers :) |
As per
On Arch Linux the PATH for user services is |
I don't know how well this would be handled on macOS, but instead of a configuration option I would propose a default path for an environment file. With systemd you could define something like
which could then in turn contain configuration like $PATH. Or you could just load the file from espanso when running scripts :D |
Yes, it's exactly the page I found but I did not manage to make it work. You can't set the path only like this Do you use docker and docker-compose? You have your example: docker-compose environment variables # Example default.yml
environment:
- CONFIG=/Users/<username>/Library/Preferences/espanso
- ANOTHER_VARIABLE=1
- PATH:
- /another/custom/location
- /my/custom/script/directory Where It's exactly the same thing in Linux for environment variables. But I think like macOS the path Like I explained in the other issue when I tried to use the Example - trigger: ":test"
replace: "{{output}}"
vars:
- name: output
type: shell
params:
cmd: "$CONFIG/scripts/command.sh"
trim: true |
@Scrumplex I referred to the docker-compose file as an example, and effectively we can add environment variables directly in the YAML file or pointing to an external environment file. @federico-terzi Indeed if you add a system like this, we could avoid using absolute paths even with our custom commands and also add global variables for all shell and scripts expanders. 👍 |
Thank you @Scrumplex for your insight, that's exactly the answer I was looking for. @atika all right, thank you. I now understand what you meant when talking about the $CONFIG variable. That could be a great solution indeed. I've opened an issue for that #277 |
Hey, This change will be shipped in the 0.6.2 release. Do you see any problem with it? |
Hi,
Why macOS? This is not only a macOS issue. |
The reason why I chose this approach is that it provides the same experience a user would get in the terminal without any configuration. On the other hand, if you don't like this approach is pretty easy to customize, it's just a matter of editing the launch agent file as you previously did. So that seems like a reasonable default: good experience out of the box and easy customizability if you don't like it.
It mostly is, because on Windows there is not this problem and on Linux Systemd automatically adds the |
The output of this command
curl -s 'https://api.chucknorris.io/jokes/random' | jq '.value'
in a bash shell returns the
value
value of the json, as expected.Putting the same in the cmd field of an espanso rule triggers the rule but replaces the trigger word with nothing.
eg.:
The text was updated successfully, but these errors were encountered: