mprocs icon indicating copy to clipboard operation
mprocs copied to clipboard

unable to use environment variables in `cwd`

Open ayushnix opened this issue 3 years ago • 6 comments

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.

ayushnix avatar Aug 10 '22 15:08 ayushnix

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".

pvolok avatar Aug 12 '22 12:08 pvolok

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

ayushnix avatar Aug 12 '22 13:08 ayushnix

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).

pvolok avatar Aug 14 '22 16:08 pvolok

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.

ayushnix avatar Aug 14 '22 20:08 ayushnix

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.

pvolok avatar Aug 19 '22 23:08 pvolok

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.

ayushnix avatar Aug 20 '22 13:08 ayushnix