Skip to content

voronkovich/symfony.plugin.zsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

symfony.plugin.zsh

Tests

A zsh plugin for the Symfony PHP framework.

Features

  • 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.

Installation

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)

Manual

Clone this repo and add this into your .zshrc:

source path/to/cloned/repo/symfony.plugin.zsh

Usage

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 use docker compose up, symfony serve, ddev start or php -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 for symfony 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;

Containers support (Docker/DDEV and etc.)

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.

Configuration

The sf command can be configured via following environment variables:

  • SF_CONSOLE: sets the console binary

    Allowed 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 runner

    Allowed 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 use ddev exec

    # Disable DDEV detection
    export SF_DDEV=off
  • SF_DOCKER enbales/disables Docker autodetection

    Allowed values: "on", "off"

    Default: "on"

    When enabled sf will try to detect a proper runner from a docker-compose.yml or docker-compose.yaml files. If the file exists, sf will try to find common service names: php and app and automatically configure runner e.g. docker compose exec php --

    # Disable Docker detection
    export SF_DOCKER=off
  • SF_SYMFONY_CLI enbales/disables Symfony CLI usage

    Allowed values: "on", "off"

    Default: "on"

    When enabled sf will try to detect if Symfony CLI installed and use it as the runner instead of local php

    # Disable Symfony CLI
    export SF_SYMFONY_CLI=off
  • SF_LOCAL enbales/disables local runner

    Allowed 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.

Laravel

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

ASCII movie

asciicast

License

Copyright (c) Voronkovich Oleg. Distributed under the MIT.

Releases

No releases published

Packages

No packages published

Languages