Running multiple commands at once in a terminal using this Laravel Package
Modern web development involves modern problems that require modern solutions. One such problem is that we often need to run multiple commands to get our development environment up and running.
For instance, if you are working with Laravel, you might need to run a command to instantiate the frontend assets, a command to tail the log, and a command to start the Reverb server all at once. Now, this can be done by opening up a separate terminal window and running each command one by one, but this is a little tedious and time-consuming.
And that’s where this new package by Aaron Francis comes to our rescue.
The package, conveniently named Solo, allows you to run multiple commands at once. It does this by rendering all the required commands in a tabbed layout in a single terminal window, with each command rendered in its own tab.
As you can tell, the package has started four commands at once bootstrapped in their own tabs. You can navigate between the tabs using the arrow keys and there are bunch of keyboard shortcuts for common actions like clearing, stopping, starting, and restarting the commands.
Using the package
To use this package, you can install it in your project as a dev dependency using Composer.
composer require aaronfrancis/solo --dev
Once installed, run this command to install its service provider.
php artisan solo:install
And finally, you can run the following command to run the commands.
php artisan solo
Adding commands
Through Solo’s service provider, you can add (or remove) commands to the list of commands that will be run at once as per your requirements.
namespace App\Providers;
use AaronFrancis\Solo\Commands\EnhancedTailCommand;
use AaronFrancis\Solo\Facades\Solo;
use AaronFrancis\Solo\Providers\SoloApplicationServiceProvider;
class SoloServiceProvider extends SoloApplicationServiceProvider
{
public function register()
{
Solo::useTheme('dark')
// Commands that auto start.
->addCommands([
EnhancedTailCommand::make('Logs', 'tail -f -n 100 ' . storage_path('logs/laravel.log')),
'Vite' => 'npm run dev',
// 'HTTP' => 'php artisan serve',
'About' => 'php artisan solo:about'
])
// Not auto-started
->addLazyCommands([
'Queue' => 'php artisan queue:listen --tries=1',
// 'Reverb' => 'php artisan reverb:start',
// 'Pint' => 'pint --ansi',
])
// FQCNs of trusted classes that can add commands.
->allowCommandsAddedFrom([
//
]);
}
}
As you can tell, you can add as many commands—as an associative array—in the addCommands
method. Commands added in this method will be started automatically.
But if you want to add a command that doesn’t start automatically, you can use the addLazyCommands
method.
In closing
I think this is a fantastic package that can help put together the most important commands for your project in a single place which itself can boost your productivity.
Although still in beta, the package works quite well in macOS. You can test it out in your OS of choice and if you face any issues, please let the author know on GitHub.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.