In my day to day life i tend to switch between Magento, Laravel and Symfony on a regular basis. Each system has it’s pros and cons, but Magento has one pro over the other two: If you are using Magerun you can run console commands from any directory inside your project. It always bugged me that there isn’t such a thing for Laravel, Symfony or other frameworks. That’s why i created Shorty

Meet Shorty

With this library you can create a shortcut for any command. It’s in an early stage, but i’m using it on a daily base already.

Shorty has only 1 dependency: You need to add ~/.composer/vendor/bin to your $PATH. Most people already have this, so installing is only one command:

composer global require michielgerritsen/shorty

And that’s it. Now you can add commands that should be globally available:

shorty add symfony bin/console

Now you can call this command from wherever in you system, it will always call this specific executable. But when you go to the next Symfony project, this will still call the executable from the previous project. Do we have anything for that? Yes:

Global commands

With global commands you can create commands that checks your current folder and tries to find the specified executable. This way you can add a symfony command which is available in every project in every folder.

Some examples

So say you’ve added a Symfony command. When browser you project you may end up in `app/logs`. You check the error and realize you need to flush the cache. In a normal situation you have 2 options:

  • php ../../bin/console cache:clear
  • cd ../../; php bin/console cache:clear

Now with Shorty you just do this:

shorty global symfony app/console

Let’s go over the options:

  • global – Make this command available in every project.
  • symfony – The alias, you could name this sf for example.
  • app/console – The actual command that should be executed.

Support for Laravel

When installing Laravel on the recommended way, the artisan file is not executable. This prevents Shorty from running it in the default way. That’s why you need to provide it with the interpreter is needs. You can add the artisan command to Shorty like this:

shorty global artisan artisan --interpreter=$(which php)

What’s next

There are a few things i wish to add:

  • I’ve coded this project to check if this idea was feasible, so i didn’t add tests yet.
  • Make sure the command actually exists so you don’t add non-working commands.
  • Give a better error message.
  • Allow to enter parameters. This way you can easily create shortcuts for specific command, ie flushing the cache.
  • Add support for a few frameworks out of the box. Got a good idea you want to share? Open an issue or create a pull request.

View the code

As always, you can find the code on Github:
https://github.com/michielgerritsen/shorty