pvolok / mprocs

Run multiple commands in parallel
MIT License
1.55k stars 53 forks source link

unable to use environment variables in `cwd` #51

Open ayushnix opened 2 years ago

ayushnix commented 2 years ago

I'm trying to run a program called entangled inside my neovim directory. When I specify $XDG_CONFIG_HOME, the entangled daemon doesn't work and isn't able to find its config file.

procs:
  neovim_literate:
    cwd: "$XDG_CONFIG_HOME/nvim"
    env:
      XDG_CONFIG_HOME: "/home/username/.config"
    shell: "entangled daemon"

However, if I specify an absolute path to the neovim config directory, the entangled daemon starts without issues.

procs:
  neovim_literate:
    cwd: "/home/username/.config/nvim"
    shell: "entangled daemon"

I'm not sure if what I'm trying to do is intended or not but I think mprocs should inherit the environment variables defined inside the terminal where it runs and YAML config keys like cwd, shell etc should be able to use these environment variables.

pvolok commented 2 years ago

cwd doesn't support env variables. It is just a plain path string. You can try to do something like this: shell: "cd $XDG_CONFIG_HOME/nvim && entangled daemon".

ayushnix commented 2 years ago

Would it be desirable to support environment variables in cwd? In my opinion, that sounds like a cleaner solution than the proposed shell solution.

pvolok commented 2 years ago

I think it's not justified to add that logic to cwd. But even if adding that feature, I would expect it to only use env variables that are passed to mprocs initially (not env vars set in mprocs.yaml).

ayushnix commented 2 years ago

But even if adding that feature, I would expect it to only use env variables that are passed to mprocs initially (not env vars set in mprocs.yaml).

mprocs can inherit the environment variables from the session where it's started. $XDG_CONFIG_HOME is one such variable that should already be defined and available to inherit on most Linux systems.

pvolok commented 2 years ago

I'm contemplating adding some operator to config which would allow using env variables. Something like this:

procs:
  neovim_literate:
    shell: entangled daemon
    cwd: { $expand: "$XDG_CONFIG_HOME/nvim" }

Where { $expand: "$XDG_CONFIG_HOME/nvim" } would be replaced with a string "$XDG_CONFIG_HOME/nvim" with $XDG_CONFIG_HOME replaced with an actual value.

But it feels too complex and not very flexible. If we support this, why not just support complete language for configs, like lua.

ayushnix commented 2 years ago

But it feels too complex and not very flexible. If we support this, why not just support complete language for configs, like lua.

If adding functionality like expanding environment variables in a YAML config format makes things complex, I think mprocs would definitely benefit by supporting Lua as a configuration language.