How do I run wp-cli without clicking Open Site Shell?

All the environment setup script functionally does is export the path to the lightning services in Local so those tools are available. The alternative I came up with is to just install the tools globally on my Mac. I use Homebrew, so these were…

brew install php
brew install mysql
brew install wp-cli

You can then teach the wp-cli what WP site to go at in certain folder structures by including these files at the root of your Local site:

wp-cli.local.yml

path: app/public
require:
  - wp-cli.local.php

wp-cli.local.php

<?php
define('DB_HOST', 'localhost:/Users/myusername/Library/Application Support/Local/run/gC3BGRlZX/mysql/mysqld.sock');

You get the socket path, which also does include the site ID, from the Database tab in the Local GUI.

The biggest downside of this is that without careful version management the versions of, say, PHP, will likely be out of sync. But that hasn’t really bitten me. It is much nicer to be able to just use any old Terminal (yes, lots of the time for my work that is also VS Code’s Integrated Terminal) to perform anything on my Local sites.

I also have built my own wrapper for the local-cli, which can show you how to retrieve the site ID based on folder you are in.