A zsh plugin for the Symfony PHP framework.
- Useful commands and shortcuts.
- Symfony's commands and options autocompletion.
- Autocompletion for Symfony CLI.
- Docker and DDEV support.
- Works with Laravel or any other similar PHP framework.
If you need an autocompletion, please, install symfony-complete.plugin.zsh first.
antigen bundle voronkovich/symfony.plugin.zsh
zplug "voronkovich/symfony.plugin.zsh"git clone https://github.com/voronkovich/symfony.plugin.zsh ~/.oh-my-zsh/custom/plugins/symfonyEdit .zshrc to enable the plugin:
plugins=(... symfony)Clone this repo and add this into your .zshrc:
source path/to/cloned/repo/symfony.plugin.zshThis plugin provides some useful commands and shortcuts:
sfis used for running Symfony's console commands e.g.,sf debug:router,sf c:c, etc. But it also has some special subcommands:serveruns a development web server. Depending on the configuration, it will usedocker compose up,symfony serve,ddev start, orphp -S.statusshows status (web server, containers, etc.).stopstops a development web server.runruns a program with an environment depending on the current context (current machine,symfony run,ddev,docker, etc.).phpruns a PHP (version depends on project's configuration).composerruns a Composer.phpunitruns a PHPUnit.phiveruns a PHIVE.psqlruns a psql PostgreSQL client.openopens a local project in a browser.mailsopens a local project mail catcher web interface in a browser.
sfnewcreates a new Symfony project. It's just a shortcut forsymfony new.sfserviceshows a service definition. It has autocompletion for service IDs.sfrouteshows a route definition. It has autocompletion for route names.sfconfigshows a container extensions configuration. It has autocompletion for extension names.
If you run your app inside a Docker container, you'll probably need to configure a "runner": a command that executes other commands. You can do it by setting a special SF_RUNNER environment variable. Just place it in your .zshrc or in a local .env or .env.local files inside of your project's root:
# "symfony" is a service name in a `docker-compose.yml`
SF_RUNNER="docker-compose exec symfony --"However, if you use DDEV or dunglas/symfony-docker you don't need to configure anything. It works out of the box.
The sf command can be configured via the following environment variables:
-
SF_CONSOLE: Sets the console binaryAllowed values: Any valid path to a binary file
Default: "bin/console"
# Yes, you can use this plugin with the Laravel too export SF_CONSOLE="artisan"
-
SF_RUNNER: Sets the command runnerAllowed values: Any valid command
Default: configured automatically
export SF_RUNNER="docker-compose exec -- laravel.test"
-
SF_DDEV: Enables/disables DDEV auto-detection.Allowed values: "on", "off"
Default: "on"
When enabled,
sfwill check the project's folder for the existence of a.ddevdirectory and configure the runner to useddev exec# Disable DDEV detection export SF_DDEV=off
-
SF_DOCKER: Enables/disables Docker auto-detection.Allowed values: "on", "off"
Default: "on"
When enabled,
sfwill try to detect a proper runner fromdocker-compose.ymlordocker-compose.yamlfiles. If the file exists,sfwill try to find common service names (phpandapp) and automatically configure the runner (e.g.,docker compose exec php --).# Disable Docker detection export SF_DOCKER=off
-
SF_SYMFONY_CLI: Enables/disables Symfony CLI usage.Allowed values: "on", "off"
Default: "on"
When enabled,
sfwill try to detect if Symfony CLI is installed and use it as the runner instead of localphp.# Disable Symfony CLI export SF_SYMFONY_CLI=off
-
SF_LOCAL: Enables/disables local runner.Allowed values: "on", "off"
Default: "on"
When enabled,
sfwill use a default system PHP installation as a fallback.# Disable local export SF_LOCAL=off
You can put the configuration in your global .zshrc file or in a local .env or .env.local files inside of your project's root.
By the way, you can use this plugin with Laravel. To do this, just create a wrapper function in your .zshrc with a configuration like this (in this example, I use Sail):
artisan() {
SF_CONSOLE='artisan' SF_RUNNER='docker-compose exec -- laravel.test' sf "$@"
}
compdef _sf artisanCopyright (c) Voronkovich Oleg. Distributed under the MIT.
