estruyf / vscode-front-matter

Front Matter is a CMS running straight in Visual Studio Code. Can be used with static site generators like Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...
https://frontmatter.codes
MIT License
1.98k stars 80 forks source link

Enhancement: dynamic evaluation of commands #882

Open davidsneighbour opened 5 days ago

davidsneighbour commented 5 days ago
"frontMatter.custom.scripts": [
{
"command": "~/.nvm/versions/node/v20.18.0/bin/node",
"script": "./bin/frontmatter/screenshot-header-image.cjs",
"title": "Retrieve Screenshot"
},
]

I have a custom script like the above that relies on the command attribute. The problem is that this path/command might change over time, and I am forced to update this configuration every now and then. Technically speaking, the return value of which node would return this path and all its changes. Is it possible somehow to evaluate the content of command so that the resulting path doesn't need to be changed every time?

I remember adding this line because VSCode somehow doesn't respect/find my node/npm versions. They are in "the path," so when I run node in the VSCode terminal, it runs the proper version—just not in those custom scripts. Maybe I am doing something else wrong in the VSCode configuration.

Edit: something like this:

$(which node)

would, under Bash, return the path.

estruyf commented 4 days ago

Thanks, @davidsneighbour. for suggesting this. The issue is on VS Code and how it starts the shell. It works with a "nologin" instance. That way, no $PATH variables are available. I've tried the which node command, but even then its not possible to find it.

What I've tried is to retrieve the terminal settings' path in the following order:

The first one containing a path/configuration, is used for the execution of the which node command.

Configuration of the custom script can then be changed to:

"frontMatter.custom.scripts": [{
  "command": "node",
  "script": "./bin/frontmatter/screenshot-header-image.cjs",
  "title": "Retrieve Screenshot"
}]

On my device, this approach works as I have zsh configured and that path is used for the which node command.

If there is no configuration, it would still be the same experience as before.