Local, the development environment for WordPress by LocalWP is great, but I am a terminal type of person. So I adapted an earlier script to work with the new Local version.
This script lets you do (nearly) all you need to do with Local from the CLI. Surely, a click of a button is not hard? true. But why use the mouse when you can use the keyboard. For instance
lbl ssh
lbl db
And there is much more ;)
Before we begin; dependencies
- Apple CommandLine Tools
xcode-select --install
- homebrew. Install using instructions from brew.sh.
- php, node, nvm: Install using brew.
brew install php node nvm
- LBL does NOT work with spaces in the path. This is a limitation on the Terminal application (at least in Big Sur).
- Set-up local to use a different folder – this will help with new sites
- Move the old folder to the new and symlink is – this will help with existing sites.
- The script allows for offloading to a secondary location (for instance an external drive, helpful when your internal drive is getting filled up). You CAN use a path with spaces as it will be symlinked to a no-spaces-containing path.
The lbf command can do the following, from within a directory controlled by Local (for instance ~/Local Sites/mywebsite/app/public)
lbl list | List all sites |
lbl raw | View all info Local has on this site |
lbl start|stop|restart | Start/stop/restart a local site (this uses the local-cli node package, node v12 or newer required) |
lbl mailhog | Open the mailhog software for this site in your default browser |
lbl db | Open Sequel Pro with the database of this site |
lbl ssh | Open a shell of this site, in the root of the site |
lbl ssh commands | Open a shell of this site and execute the commands inside the shell, in the current folder |
lbl wp commands | Perform WP-CLI operation on site |
lbl php commands | Perform PHP operation on site, in the current folder |
lbl wpdr | Perform wp search-replace <current domain> <local domain> |
lbl log | Shows the error log for the site. |
You can use --site, --project or -p to specify a site, either by Name, ID or Path to operate on
You can use --browser or -b to specify a WebBrowser either by AppName or AppPath to use for ‘open’ and ‘mailhog’
You can use --ssl to use https with operation ‘open’ and ‘wpdr’
You can use browser shortcuts;
-ff --firefox |
Firefox |
-fd --firefox-dev --firefox-developer-edition |
Firefox Developer Edition |
-c --chrome |
Chrome |
-cd --chrome-dev --chromium |
Chromium |
-o --opera |
Opera |
-s --safari |
Safari |
Of course, the browser of choice must be installed… Duh…
So, now you can do this: (while inside the app folder)
lbl wp db query < site-backup.sql
lbl db
lbl wpdr
lbl wp plugin install --activate wordpress-seo classic-editor duplicate-post what-the-file wp-smushit
Enjoy, but as always; at your own risk :)