A zsh plugin for the Symfony PHP framework.
- Usefull 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/symfony
Edit .zshrc
to enable the plugin:
plugins=(... symfony)
Clone this repo and add this into your .zshrc
:
source path/to/cloned/repo/symfony.plugin.zsh
This plugin provides some usefull commands and shortcuts:
sf
is used for running Symfony's console commands e.g.sf debug:router
,sf c:c
and etc. But it also has some special subcommands:serve
runs a development web server. Depending on configuration it will usedocker compose up
,symfony serve
,ddev start
orphp -S
status
shows status (web server, containers and etc.);stop
stops a development web server;run
runs a program with environment depending on the current context (current machine,symfony run
,ddev
,docker
and etc.);php
runs a PHP (version depends on project's configuration);composer
runs a Composer;phpunit
runs a PHPUnit;phive
runs a PHIVE;psql
runs a psql PostgreSQL client;open
opens a local project in a browser;mails
opens a local project mail catcher web interface in a browser;
sfnew
creates new Symfony project. It's just a shortcut forsymfony new
;sfservice
shows a service definition. It has an autocompletion for services ids;sfroute
shows a route definition. It has autocompletion for routes names;sfconfig
shows a container extensions configuration. It has autocompletion for extensions names;
If you run your app inside a Docker container, you'll probably need to configure a "runner": a command that executes another 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 --"
But, if you use a DDEV or a dunglas/symfony-docker you don't need to configure anything. All works out of the box.
The sf
command can be configured via following environment variables:
-
SF_CONSOLE
: sets the console binaryAllowed values: any valid path to binary file
Default: "bin/console"
# Yes, you can use this plugin with the Laravel too export SF_CONSOLE="artisan"
-
SF_RUNNER
: sets command runnerAllowed values: any valid command
Default: configured automatically
export SF_RUNNER="docker-compose exec -- laravel.test"
-
SF_DDEV
: enables/disables DDEV autodetection.Allowed values: "on", "off"
Default: "on"
When enabled
sf
will check project's folder for existence of.ddev
directory and configure runner to useddev exec
# Disable DDEV detection export SF_DDEV=off
-
SF_DOCKER
enbales/disables Docker autodetectionAllowed values: "on", "off"
Default: "on"
When enabled
sf
will try to detect a proper runner from adocker-compose.yml
ordocker-compose.yaml
files. If the file exists,sf
will try to find common service names:php
andapp
and automatically configure runner e.g.docker compose exec php --
# Disable Docker detection export SF_DOCKER=off
-
SF_SYMFONY_CLI
enbales/disables Symfony CLI usageAllowed values: "on", "off"
Default: "on"
When enabled
sf
will try to detect if Symfony CLI installed and use it as the runner instead of localphp
# Disable Symfony CLI export SF_SYMFONY_CLI=off
-
SF_LOCAL
enbales/disables local runnerAllowed values: "on", "off"
Default: "on"
When enabled
sf
will 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.
BTW, you can use this plugin with the Laravel :). To do this, just create a wrapper function in your .zshrc
with configuration like this (in this example I use Sail):
artisan() {
SF_CONSOLE='artisan' SF_RUNNER='docker-compose exec -- laravel.test' sf "$@"
}
compdef _sf artisan
Copyright (c) Voronkovich Oleg. Distributed under the MIT.