Vscode and wp-cli

Please help! I have been trying to use WP-CLI in my Visual Studio Code while Local by Flywheel is open with the bash terminal, but it seems that I can only work from the local terminal. I want to use Visual Studio Code instead.

I use macOS but the principle should be the same. You have to find the shell script that sets the environment variables and starts the shell for the website in question. In macOS you will find the shell scripts for the Local websites in the users Application Support folder. You can start the shell by enter the path to the shell script but I have created an alias in the bash profile for each website to quickly start a terminal session in VS Code.

/Users/USERNAME/Library/Application\ Support/Local/ssh-entry/QtMpqLkVF.sh
alias website.sh="/Users/USERNAME/Library/Application\ Support/Local/ssh-entry/QtMpqLkVF.sh"

3 Likes

@emmtre 's solution is cool! Another option that we’ve thought about implementing in Local core is to use direnv.

You can still use direnv with Local (and any terminal, including VS Code) today with an addon!

Clay, the original author of Local (Pressmatic) created this addon which adds the .envrc needed for direnv to the <site>/app/ folder.

You can download that addon and install it from “Addons > Installed > Install from disk” in Local:

5 Likes

This is absolutely awesome! It worked perfectly. Thank you so much!

1 Like

Many thanks for the info. Sounds like a good idea I think. I had no idea this plugin even existed. I’ll have to test when I have the chance.

“This is also great. Thank you so much.”

It should be mentioned that Local requires the file format to be in a .tar.gz format, so make sure to download https://github.com/gravitywiz/local-addon-direnv/archive/refs/tags/1.0.0.tar.gz and import that one.

Unfortunately for me, installing this in the latest Local (Version 9.2.3+6776) doesn’t work since I pretty soon get the message:

**Uh-oh! Local ran into an error.**
TypeError: Cannot read properties of undefined (reading 'toString')

Stack Trace:
in Unknown
in o
in div
[etc]

and then if I restart local, this add-on is no longer listed in my “installed” list of applications.

Is it possible that this add-on was only made for Local Classic (used docker) since it was last update in 2021?

Per Ben’s comment, I’d love to see this just integrated directly, since I imagine many of us are using terminals integrated into our preferred IDEs.

I experienced that same issue with the archive you linked to.

I think the issue is that the tar.gz file is just the source code. For an actual compiled build, you’ll want to install the tgz archive:

2 Likes